Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgw:add a s3 API of make torrent for a object #10396

Merged
merged 1 commit into from Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/common/config_opts.h
Expand Up @@ -1477,6 +1477,15 @@ 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_flag, OPT_BOOL, false) // produce torrent function flag
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
3 changes: 2 additions & 1 deletion src/rgw/CMakeLists.txt
Expand Up @@ -85,7 +85,8 @@ set(rgw_a_srcs
rgw_user.cc
rgw_website.cc
rgw_xml.cc
rgw_xml_enc.cc)
rgw_xml_enc.cc
rgw_torrent.cc)

add_library(rgw_a STATIC ${rgw_a_srcs})
target_include_directories(rgw_a PUBLIC ${FCGI_INCLUDE_DIR})
Expand Down
4 changes: 3 additions & 1 deletion src/rgw/Makefile.am
Expand Up @@ -91,7 +91,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 @@ -273,6 +274,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
41 changes: 40 additions & 1 deletion src/rgw/rgw_op.cc
Expand Up @@ -1241,6 +1241,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 @@ -1340,6 +1341,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 @@ -2587,7 +2610,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 @@ -2683,6 +2706,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 @@ -2836,6 +2862,19 @@ void RGWPutObj::execute()
op_ret = processor->complete(etag, &mtime, real_time(), attrs, delete_at,
if_match, if_nomatch);

/* produce torrent */
if (s->cct->_conf->rgw_torrent_flag && (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);
perfcounter->tinc(l_rgw_put_lat,
Expand Down
5 changes: 5 additions & 0 deletions src/rgw/rgw_op.h
Expand Up @@ -34,11 +34,14 @@
#include "rgw_acl.h"
#include "rgw_cors.h"
#include "rgw_quota.h"

#include "rgw_lc.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 @@ -104,6 +107,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 @@ -643,6 +647,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
27 changes: 27 additions & 0 deletions src/rgw/rgw_rest.cc
Expand Up @@ -790,6 +790,20 @@ 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);
bool torrent_flag = s->cct->_conf->rgw_torrent_flag;
if (torrent_flag && is_torrent)
{
int ret = 0;
ret = torrent.get_params();
if (ret < 0)
{
return ret;
}
}
/* end gettorrent */

return 0;
}

Expand Down Expand Up @@ -1000,6 +1014,19 @@ int RGWPutObj_ObjStore::verify_params()

int RGWPutObj_ObjStore::get_params()
{
/* start gettorrent */
if (s->cct->_conf->rgw_torrent_flag)
{
int ret = 0;
ret = torrent.get_params();
ldout(s->cct, 5) << "NOTICE: open produce torrent file " << dendl;
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