From: Jing Wenjun Date: Thu, 23 Feb 2017 20:45:04 +0000 (+0800) Subject: rgw: add the remove-x-delete feature to cancel swift object expiration X-Git-Tag: v12.0.2~224^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F13621%2Fhead;p=ceph.git rgw: add the remove-x-delete feature to cancel swift object expiration 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 --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index e2b963154ff5..49f64a4beba5 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -1145,8 +1145,8 @@ 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, - if_match, if_nomatch); + op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs, + (delete_at ? *delete_at : real_time()), if_match, if_nomatch); if (! op_ret) { /* update stats */ rgw_fh->set_mtime(real_clock::to_timespec(mtime)); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 6cf908933208..99476fac6ad7 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1320,7 +1320,7 @@ static bool object_is_expired(map& attrs) { return false; } - if (delete_at <= ceph_clock_now()) { + if (delete_at <= ceph_clock_now() && !delete_at.is_zero()) { return true; } } @@ -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 ? *delete_at : real_time()), if_match, if_nomatch); /* produce torrent */ if (s->cct->_conf->rgw_torrent_flag && (ofs == torrent.get_data_len())) @@ -3343,7 +3343,8 @@ 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 ? *delete_at : real_time())); } @@ -4007,7 +4008,7 @@ void RGWCopyObj::execute() copy_if_newer, attrs, RGW_OBJ_CATEGORY_MAIN, olh_epoch, - delete_at, + (delete_at ? *delete_at : real_time()), (version_id.empty() ? NULL : &version_id), &s->req_id, /* use req_id as tag */ &etag, diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index d1098c341e75..43a3c4f4ee9c 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -720,7 +720,7 @@ protected: string version_id; bufferlist bl_aux; - ceph::real_time delete_at; + boost::optional delete_at; public: RGWPutObj() : ofs(0), @@ -798,7 +798,7 @@ protected: string content_type; RGWAccessControlPolicy policy; map attrs; - ceph::real_time delete_at; + boost::optional delete_at; public: RGWPostObj() : min_len(0), @@ -908,7 +908,7 @@ class RGWPutMetadataObject : public RGWOp { protected: RGWAccessControlPolicy policy; string placement_rule; - ceph::real_time delete_at; + boost::optional delete_at; const char *dlo_manifest; public: @@ -998,7 +998,7 @@ protected: string version_id; uint64_t olh_epoch; - ceph::real_time delete_at; + boost::optional delete_at; bool copy_if_newer; int init_common(); @@ -1703,15 +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 delete_at, map& attrs) { - if (real_clock::is_zero(delete_at)) { + if (delete_at == boost::none) { return; - } + } bufferlist delatbl; - ::encode(delete_at, delatbl); + ::encode(*delete_at, delatbl); attrs[RGW_ATTR_DELETE_AT] = delatbl; } /* encode_delete_at_attr */ diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index bd3e2349f0f8..c9aa44d3fae2 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -8328,6 +8328,8 @@ int RGWRados::Object::Delete::delete_obj() if (params.expiration_time != delete_at) { return -ERR_PRECONDITION_FAILED; } + } else { + return -ERR_PRECONDITION_FAILED; } } diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 27c636562a87..7f8437b20d0a 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -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 &delete_at) { /* Handle Swift object expiration. */ real_time delat_proposal; @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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" @@ -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;