From 09ccfebf684bb07fd0043f7ddb3b1011d911512e Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 10 May 2017 11:46:57 -0700 Subject: [PATCH] rgw: more detailed resharding status kept in bucket header So that we can differentiate between in-progress and complete status. Signed-off-by: Yehuda Sadeh --- src/cls/rgw/cls_rgw.cc | 2 +- src/cls/rgw/cls_rgw_types.cc | 4 ++-- src/cls/rgw/cls_rgw_types.h | 26 +++++++++++++++++++------- src/rgw/rgw_reshard.cc | 18 ++++-------------- src/rgw/rgw_reshard.h | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index abae4bfbf17a1..17ce100b7723e 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -3637,7 +3637,7 @@ static int rgw_set_bucket_resharding(cls_method_context_t hctx, bufferlist *in, return rc; } - header.new_instance.set(op.entry.new_bucket_instance_id); + header.new_instance.set_status(op.entry.new_bucket_instance_id, op.entry.reshard_status); return write_bucket_header(hctx, &header); } diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index c3a97c6576004..acf782f1f48bf 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -596,7 +596,7 @@ void cls_rgw_reshard_entry::generate_test_instances(list void cls_rgw_bucket_instance_entry::dump(Formatter *f) const { - encode_json("resharding", resharding, f); + encode_json("reshard_status", (int)reshard_status, f); encode_json("new_bucket_instance_id", new_bucket_instance_id, f); } @@ -605,6 +605,6 @@ void cls_rgw_bucket_instance_entry::generate_test_instances(listresharding = true; + ls.back()->reshard_status = CLS_RGW_RESHARD_IN_PROGRESS; ls.back()->new_bucket_instance_id = "new_instance_id"; } diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index dd89e73c2f77c..8244a48dff436 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -604,20 +604,28 @@ struct rgw_bucket_category_stats { }; WRITE_CLASS_ENCODER(rgw_bucket_category_stats) +enum cls_rgw_reshard_status { + CLS_RGW_RESHARD_NONE = 0, + CLS_RGW_RESHARD_IN_PROGRESS = 1, + CLS_RGW_RESHARD_DONE = 2, +}; + struct cls_rgw_bucket_instance_entry { - bool resharding{false}; + cls_rgw_reshard_status reshard_status{CLS_RGW_RESHARD_NONE}; string new_bucket_instance_id; void encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); - ::encode(resharding, bl); + ::encode((uint8_t)reshard_status, bl); ::encode(new_bucket_instance_id, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { DECODE_START(1, bl); - ::decode(resharding, bl); + uint8_t s; + ::decode(s, bl); + reshard_status = (cls_rgw_reshard_status)s; ::decode(new_bucket_instance_id, bl); DECODE_FINISH(bl); } @@ -626,14 +634,18 @@ struct cls_rgw_bucket_instance_entry { static void generate_test_instances(list& o); void clear() { - resharding = false; + reshard_status = CLS_RGW_RESHARD_NONE; new_bucket_instance_id.clear(); } - void set(const string& new_instance_id) { - resharding = true; + void set_status(const string& new_instance_id, cls_rgw_reshard_status s) { + reshard_status = s; new_bucket_instance_id = new_instance_id; } + + bool resharding() const { + return reshard_status != CLS_RGW_RESHARD_NONE; + } }; WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry) @@ -685,7 +697,7 @@ struct rgw_bucket_dir_header { static void generate_test_instances(list& o); bool resharding() const { - return new_instance.resharding; + return new_instance.resharding(); } }; WRITE_CLASS_ENCODER(rgw_bucket_dir_header) diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 6033591bff4e9..385fdd0b6d71c 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -228,7 +228,7 @@ int RGWBucketReshard::init_resharding(const string& new_instance_id) } cls_rgw_bucket_instance_entry instance_entry; - instance_entry.set(new_instance_id); + instance_entry.set_status(new_instance_id, CLS_RGW_RESHARD_IN_PROGRESS); int ret = store->bucket_set_reshard(bucket_info, instance_entry); if (ret < 0) { @@ -571,33 +571,23 @@ int RGWReshard::unlock_bucket_index(const string& oid) const int num_retries = 10; const int default_reshard_sleep_duration = 30; -int RGWReshard::block_while_resharding(const string& bucket_instance_oid, - BucketIndexLockGuard& guard) +int RGWReshard::block_while_resharding(const string& bucket_instance_oid) { int ret = 0; cls_rgw_bucket_instance_entry entry; for (int i=0; i< num_retries;i++) { - ret = guard.lock(); - if (ret < 0) { - return ret; - } - ret = cls_rgw_get_bucket_resharding(store->reshard_pool_ctx, bucket_instance_oid, &entry); if (ret < 0) { ldout(store->ctx(), 0) << "RGWReshard::" << __func__ << " ERROR: failed to get bucket resharding :" << cpp_strerror(-ret)<< dendl; return ret; } - - ret = guard.unlock(); - if (ret < 0) { - return ret; - } - if (!entry.resharding) { + if (!entry.resharding()) { return 0; } /* needed to unlock as clear resharding uses the same lock */ +#warning replace sleep with interruptible condition sleep(default_reshard_sleep_duration); } ldout(store->ctx(), 0) << "RGWReshard::" << __func__ << " ERROR: bucket is still resharding, please retry" << dendl; diff --git a/src/rgw/rgw_reshard.h b/src/rgw/rgw_reshard.h index da9ede7d1893c..d20412f59ba9c 100644 --- a/src/rgw/rgw_reshard.h +++ b/src/rgw/rgw_reshard.h @@ -85,7 +85,7 @@ class RGWReshard { if succefull, keeps the bucket index locked. It will be unlocked in the guard dtor. */ - int block_while_resharding(const string& bucket_instance_oid, BucketIndexLockGuard& guard); + int block_while_resharding(const string& bucket_instance_oid); }; #endif -- 2.39.5