Skip to content

Commit

Permalink
rgw:add a s3 API of make torrent for a object
Browse files Browse the repository at this point in the history
When you execute the command gettorrent of a object, a torrent file will be produced and returned.
The torrent also will be save into a pool named default.rgw.torrent.
If the torrent of a object exists in default.rgw.torrent, it will be returned.

Signed-off-by: zhouruisong <236131368@qq.com>
  • Loading branch information
zhouruisong committed Jul 22, 2016
1 parent b342bf8 commit 0940266
Show file tree
Hide file tree
Showing 10 changed files with 557 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/common/config_opts.h
Expand Up @@ -1457,6 +1457,14 @@ OPTION(rgw_list_bucket_min_readahead, OPT_INT, 1000) // minimum number of entrie
OPTION(mutex_perf_counter, OPT_BOOL, false) // enable/disable mutex perf counter
OPTION(throttler_perf_counter, OPT_BOOL, true) // enable/disable throttler perf counter

/* The following are tunables for torrent data */
OPTION(rgw_torrent_tracker, OPT_STR, "") // torrent field annouce and annouce list
OPTION(rgw_torrent_createby, OPT_STR, "") // torrent field created by
OPTION(rgw_torrent_comment, OPT_STR, "") // torrent field comment
OPTION(rgw_torrent_encoding, OPT_STR, "") // torrent field encoding
OPTION(rgw_torrent_origin, OPT_STR, "") // torrent origin
OPTION(rgw_torrent_sha_unit, OPT_INT, 512*1024) //torrent field piece length 521K

// This will be set to true when it is safe to start threads.
// Once it is true, it will never change.
OPTION(internal_safe_to_start_threads, OPT_BOOL, false)
Expand Down
4 changes: 3 additions & 1 deletion src/rgw/Makefile.am
Expand Up @@ -89,7 +89,8 @@ librgw_la_SOURCES = \
rgw/librgw.cc \
rgw/rgw_xml.cc \
rgw/rgw_xml_enc.cc \
rgw/rgw_website.cc
rgw/rgw_website.cc \
rgw/rgw_torrent.cc

if WITH_OPENLDAP
librgw_la_SOURCES += rgw/rgw_ldap.cc
Expand Down Expand Up @@ -269,6 +270,7 @@ noinst_HEADERS += \
rgw/rgw_civetweb_log.h \
rgw/rgw_website.h \
rgw/rgw_rest_s3website.h \
rgw/rgw_torrent.h \
civetweb/civetweb.h \
civetweb/include/civetweb.h \
civetweb/include/civetweb_conf.h \
Expand Down
40 changes: 39 additions & 1 deletion src/rgw/rgw_op.cc
Expand Up @@ -1234,6 +1234,7 @@ int RGWGetObj::get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len)
gc_invalidate_time = start_time;
gc_invalidate_time += (s->cct->_conf->rgw_gc_obj_min_wait / 2);
}

return send_response_data(bl, bl_ofs, bl_len);
}

Expand Down Expand Up @@ -1333,6 +1334,28 @@ void RGWGetObj::execute()
if (op_ret < 0)
goto done_err;

/* start gettorrent */
if (torrent.get_flag())
{
torrent.init(s, store);
torrent.get_torrent_file(op_ret, read_op, total_len, bl, obj);
if (op_ret < 0)
{
ldout(s->cct, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
<< dendl;
goto done_err;
}
op_ret = send_response_data(bl, 0, total_len);
if (op_ret < 0)
{
ldout(s->cct, 0) << "ERROR: failed to send_response_data ret= " << op_ret
<< dendl;
goto done_err;
}
return;
}
/* end gettorrent */

attr_iter = attrs.find(RGW_ATTR_USER_MANIFEST);
if (attr_iter != attrs.end() && !skip_manifest) {
op_ret = handle_user_manifest(attr_iter->second.c_str());
Expand Down Expand Up @@ -2580,7 +2603,7 @@ void RGWPutObj::execute()
int len;
map<string, string>::iterator iter;
bool multipart;

bool need_calc_md5 = (dlo_manifest == NULL) && (slo_info == NULL);

perfcounter->inc(l_rgw_put);
Expand Down Expand Up @@ -2676,6 +2699,9 @@ void RGWPutObj::execute()
len = data.length();
}

/* save data for producing torrent data */
torrent.save_data(data_in);

/* do we need this operation to be synchronous? if we're dealing with an object with immutable
* head, e.g., multipart object we need to make sure we're the first one writing to this object
*/
Expand Down Expand Up @@ -2828,6 +2854,18 @@ void RGWPutObj::execute()

op_ret = processor->complete(etag, &mtime, real_time(), attrs, delete_at,
if_match, if_nomatch);
/* produce torrent */
if (ofs == torrent.get_data_len())
{
torrent.init(s, store);
torrent.set_create_date(mtime);
op_ret = torrent.handle_data();
if (0 != op_ret)
{
ldout(s->cct, 0) << "ERROR: torrent.handle_data() returned " << op_ret << dendl;
goto done;
}
}

done:
dispose_processor(processor);
Expand Down
4 changes: 4 additions & 0 deletions src/rgw/rgw_op.h
Expand Up @@ -34,10 +34,12 @@
#include "rgw_acl.h"
#include "rgw_cors.h"
#include "rgw_quota.h"
#include "rgw_torrent.h"

#include "include/assert.h"

using namespace std;
using ceph::crypto::SHA1;

struct req_state;
class RGWHandler;
Expand Down Expand Up @@ -103,6 +105,7 @@ RGWOp() : s(nullptr), dialect_handler(nullptr), store(nullptr),

class RGWGetObj : public RGWOp {
protected:
seed torrent; // get torrent
const char *range_str;
const char *if_mod;
const char *if_unmod;
Expand Down Expand Up @@ -642,6 +645,7 @@ class RGWPutObj : public RGWOp {
friend class RGWPutObjProcessor;

protected:
seed torrent;
off_t ofs;
const char *supplied_md5_b64;
const char *supplied_etag;
Expand Down
22 changes: 22 additions & 0 deletions src/rgw/rgw_rest.cc
Expand Up @@ -790,6 +790,19 @@ int RGWGetObj_ObjStore::get_params()
mod_pg_ver = s->info.env->get_int("HTTP_DEST_PG_VER", 0);
}

/* start gettorrent */
bool is_torrent = s->info.args.exists(GET_TORRENT);
if (is_torrent)
{
int ret = 0;
ret = torrent.get_params();
if (ret < 0)
{
return ret;
}
}
/* end gettorrent */

return 0;
}

Expand Down Expand Up @@ -1000,6 +1013,15 @@ int RGWPutObj_ObjStore::verify_params()

int RGWPutObj_ObjStore::get_params()
{
/* start gettorrent */
int ret = 0;
ret = torrent.get_params();
if (ret < 0)
{
return ret;
}
torrent.set_info_name((s->object).name);
/* end gettorrent */
supplied_md5_b64 = s->info.env->get("HTTP_CONTENT_MD5");

return 0;
Expand Down

0 comments on commit 0940266

Please sign in to comment.