From 8fd589d1eb9fb106e42b659e7cb926e5a8c3198f Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 11 May 2017 15:41:15 -0700 Subject: [PATCH] rgw: handle reshard wait logic in cancel() too Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rados.cc | 76 ++++++++++++++++++++++++++------------------ src/rgw/rgw_rados.h | 2 ++ 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 441fddd2946..af6d46a5f1c 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -9521,42 +9521,21 @@ int RGWRados::stat_system_obj(RGWObjectCtx& obj_ctx, return 0; } -int RGWRados::SystemObject::Read::stat(RGWObjVersionTracker *objv_tracker) -{ - RGWRados *store = source->get_store(); - rgw_raw_obj& obj = source->get_obj(); - - return store->stat_system_obj(source->get_ctx(), state, obj, stat_params.attrs, - stat_params.lastmod, stat_params.obj_size, objv_tracker); -} -int RGWRados::Bucket::UpdateIndex::prepare(RGWModifyOp op, const string *write_tag) +int RGWRados::Bucket::UpdateIndex::guard_reshard(BucketShard *pbs, std::function call) { - if (blind) { - return 0; - } RGWRados *store = target->get_store(); - - if (write_tag && write_tag->length()) { - optag = string(write_tag->c_str(), write_tag->length()); - } else { - if (optag.empty()) { - append_rand_alpha(store->ctx(), optag, optag, 32); - } - } - + BucketShard *bs; int r; #define NUM_RESHARD_RETRIES 10 - for (int i = 0; i < NUM_RESHARD_RETRIES; ++i) { - BucketShard *bs; int ret = get_bucket_shard(&bs); if (ret < 0) { ldout(store->ctx(), 5) << "failed to get BucketShard object: ret=" << ret << dendl; return ret; } - r = store->cls_obj_prepare_op(*bs, op, optag, obj, bilog_flags, zones_trace); + r = call(bs); if (r != -ERR_BUSY_RESHARDING) { break; } @@ -9580,6 +9559,45 @@ int RGWRados::Bucket::UpdateIndex::prepare(RGWModifyOp op, const string *write_t invalidate_bs(); } + if (r < 0) { + return r; + } + + if (pbs) { + *pbs = bs; + } + + return 0; +} + +int RGWRados::SystemObject::Read::stat(RGWObjVersionTracker *objv_tracker) +{ + RGWRados *store = source->get_store(); + rgw_raw_obj& obj = source->get_obj(); + + return store->stat_system_obj(source->get_ctx(), state, obj, stat_params.attrs, + stat_params.lastmod, stat_params.obj_size, objv_tracker); +} + +int RGWRados::Bucket::UpdateIndex::prepare(RGWModifyOp op, const string *write_tag) +{ + if (blind) { + return 0; + } + RGWRados *store = target->get_store(); + + if (write_tag && write_tag->length()) { + optag = string(write_tag->c_str(), write_tag->length()); + } else { + if (optag.empty()) { + append_rand_alpha(store->ctx(), optag, optag, 32); + } + } + + int r = guard_reshard(nullptr, [&](BucketShard *bs) -> int { + return store->cls_obj_prepare_op(*bs, op, optag, obj, bilog_flags, zones_trace); + }); + if (r < 0) { return r; } @@ -9673,13 +9691,9 @@ int RGWRados::Bucket::UpdateIndex::cancel() RGWRados *store = target->get_store(); BucketShard *bs; - int ret = get_bucket_shard(&bs); - if (ret < 0) { - ldout(store->ctx(), 5) << "failed to get BucketShard object: ret=" << ret << dendl; - return ret; - } - - ret = store->cls_obj_complete_cancel(*bs, optag, obj, bilog_flags, zones_trace); + ret = guard_reshard(&bs, [&](BucketShard *bs) -> int { + return store->cls_obj_complete_cancel(*bs, optag, obj, bilog_flags, zones_trace); + }); /* * need to update data log anyhow, so that whoever follows needs to update its internal markers diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 15b41c2c4f1..da129430bfa 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -2881,6 +2881,8 @@ public: void invalidate_bs() { bs_initialized = false; } + + int guard_reshard(BucketShard *pbs, std::function call); public: UpdateIndex(RGWRados::Bucket *_target, const rgw_obj& _obj) : target(_target), obj(_obj), -- 2.39.5