Skip to content

Commit

Permalink
rgw: add the remove-x-delete feature to cancel swift object expiration
Browse files Browse the repository at this point in the history
In openstack swift, it also support the feature to cancel the object expiration,
which could be found at last point in
https://docs.openstack.org/user-guide/cli-swift-set-object-expiration.html. we
can remove the object expiration by set 'X-Remove-Delete-At:'.

This patch also could fix the bug that when we set the object expiration and
then upload the same object to the container again. The previous object expiration
also works, which is not compatible with the openstack swift.

Fixes: http://tracker.ceph.com/issues/19074
Signed-off-by: Jing Wenjun <jingwenjun@cmss.chinamobile.com>
  • Loading branch information
Jing-Scott committed Mar 6, 2017
1 parent a785b00 commit 2a9da73
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/rgw/rgw_file.cc
Expand Up @@ -1145,7 +1145,7 @@ namespace rgw {
emplace_attr(RGW_ATTR_SLO_UINDICATOR, std::move(slo_userindicator_bl));
}

op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs, delete_at,
op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs, *delete_at,
if_match, if_nomatch);
if (! op_ret) {
/* update stats */
Expand Down
8 changes: 4 additions & 4 deletions src/rgw/rgw_op.cc
Expand Up @@ -1320,7 +1320,7 @@ static bool object_is_expired(map<string, bufferlist>& attrs) {
return false;
}

if (delete_at <= ceph_clock_now()) {
if (delete_at <= ceph_clock_now() && !delete_at.is_zero()) {
return true;
}
}
Expand Down Expand Up @@ -3172,7 +3172,7 @@ void RGWPutObj::execute()
}

op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs,
delete_at, if_match, if_nomatch);
*delete_at, if_match, if_nomatch);

/* produce torrent */
if (s->cct->_conf->rgw_torrent_flag && (ofs == torrent.get_data_len()))
Expand Down Expand Up @@ -3343,7 +3343,7 @@ void RGWPostObj::execute()
emplace_attr(RGW_ATTR_COMPRESSION, std::move(tmp));
}

op_ret = processor.complete(s->obj_size, etag, NULL, real_time(), attrs, delete_at);
op_ret = processor.complete(s->obj_size, etag, NULL, real_time(), attrs, *delete_at);
}


Expand Down Expand Up @@ -4007,7 +4007,7 @@ void RGWCopyObj::execute()
copy_if_newer,
attrs, RGW_OBJ_CATEGORY_MAIN,
olh_epoch,
delete_at,
*delete_at,
(version_id.empty() ? NULL : &version_id),
&s->req_id, /* use req_id as tag */
&etag,
Expand Down
18 changes: 11 additions & 7 deletions src/rgw/rgw_op.h
Expand Up @@ -720,7 +720,7 @@ class RGWPutObj : public RGWOp {
string version_id;
bufferlist bl_aux;

ceph::real_time delete_at;
boost::optional<ceph::real_time> delete_at;

public:
RGWPutObj() : ofs(0),
Expand Down Expand Up @@ -798,7 +798,7 @@ class RGWPostObj : public RGWOp {
string content_type;
RGWAccessControlPolicy policy;
map<string, bufferlist> attrs;
ceph::real_time delete_at;
boost::optional<ceph::real_time> delete_at;

public:
RGWPostObj() : min_len(0),
Expand Down Expand Up @@ -908,7 +908,7 @@ class RGWPutMetadataObject : public RGWOp {
protected:
RGWAccessControlPolicy policy;
string placement_rule;
ceph::real_time delete_at;
boost::optional<ceph::real_time> delete_at;
const char *dlo_manifest;

public:
Expand Down Expand Up @@ -998,7 +998,7 @@ class RGWCopyObj : public RGWOp {
string version_id;
uint64_t olh_epoch;

ceph::real_time delete_at;
boost::optional<ceph::real_time> delete_at;
bool copy_if_newer;

int init_common();
Expand Down Expand Up @@ -1703,11 +1703,15 @@ static inline void rgw_get_request_metadata(CephContext *cct,
}
} /* rgw_get_request_metadata */

static inline void encode_delete_at_attr(ceph::real_time delete_at,
static inline void encode_delete_at_attr(boost::optional<ceph::real_time>& delete_at,
map<string, bufferlist>& attrs)
{
if (real_clock::is_zero(delete_at)) {
return;
map<string, bufferlist>::iterator iter = attrs.find(RGW_ATTR_DELETE_AT);
if (delete_at == boost::none) {
if (iter != attrs.end()) {
return;
}
delete_at = boost::in_place(real_time());
}

bufferlist delatbl;
Expand Down
18 changes: 12 additions & 6 deletions src/rgw/rgw_rest_swift.cc
Expand Up @@ -663,7 +663,7 @@ void RGWDeleteBucket_ObjStore_SWIFT::send_response()
rgw_flush_formatter_and_reset(s, s->formatter);
}

static int get_delete_at_param(req_state *s, real_time *delete_at)
static int get_delete_at_param(req_state *s, boost::optional<real_time> &delete_at)
{
/* Handle Swift object expiration. */
real_time delat_proposal;
Expand All @@ -678,6 +678,10 @@ static int get_delete_at_param(req_state *s, real_time *delete_at)
}

if (x_delete.empty()) {
delete_at = boost::none;
if (s->info.env->exists("HTTP_X_REMOVE_DELETE_AT")) {
delete_at = boost::in_place(real_time());
}
return 0;
}
string err;
Expand All @@ -692,7 +696,7 @@ static int get_delete_at_param(req_state *s, real_time *delete_at)
return -EINVAL;
}

*delete_at = delat_proposal;
delete_at = delat_proposal;

return 0;
}
Expand Down Expand Up @@ -746,7 +750,7 @@ int RGWPutObj_ObjStore_SWIFT::get_params()

policy.create_default(s->user->user_id, s->user->display_name);

int r = get_delete_at_param(s, &delete_at);
int r = get_delete_at_param(s, delete_at);
if (r < 0) {
ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl;
return r;
Expand Down Expand Up @@ -919,7 +923,7 @@ int RGWPutMetadataObject_ObjStore_SWIFT::get_params()
}

/* Handle Swift object expiration. */
int r = get_delete_at_param(s, &delete_at);
int r = get_delete_at_param(s, delete_at);
if (r < 0) {
ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl;
return r;
Expand Down Expand Up @@ -1118,7 +1122,9 @@ static void dump_object_metadata(struct req_state * const s,
utime_t delete_at;
try {
::decode(delete_at, iter->second);
dump_header(s, "X-Delete-At", delete_at.sec());
if (!delete_at.is_zero()) {
dump_header(s, "X-Delete-At", delete_at.sec());
}
} catch (buffer::error& err) {
ldout(s->cct, 0) << "ERROR: cannot decode object's " RGW_ATTR_DELETE_AT
" attr, ignoring"
Expand Down Expand Up @@ -1155,7 +1161,7 @@ int RGWCopyObj_ObjStore_SWIFT::get_params()
attrs_mod = RGWRados::ATTRSMOD_MERGE;
}

int r = get_delete_at_param(s, &delete_at);
int r = get_delete_at_param(s, delete_at);
if (r < 0) {
ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl;
return r;
Expand Down

0 comments on commit 2a9da73

Please sign in to comment.