From 92876bf269da5f461a7c80463b3e8d172219903b Mon Sep 17 00:00:00 2001 From: Shilpa Jagannath Date: Thu, 21 May 2020 18:29:15 +0530 Subject: [PATCH] rgw/dynamic-resharding: Allow clean_index to take generation number as a parameter. Signed-off-by: Shilpa Jagannath --- src/rgw/rgw_rados.cc | 3 +- src/rgw/rgw_reshard.cc | 11 ++++-- src/rgw/services/svc_bi.h | 2 +- src/rgw/services/svc_bi_rados.cc | 63 ++++++++++++++++++++++++++------ src/rgw/services/svc_bi_rados.h | 3 +- 5 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 51c942dd527ed..2d1ffd10ae279 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -2291,7 +2291,7 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket, /* only remove it if it's a different bucket instance */ if (orig_info.bucket.bucket_id != bucket.bucket_id) { - int r = svc.bi->clean_index(info); + int r = svc.bi->clean_index(info, std::nullopt); if (r < 0) { ldout(cct, 0) << "WARNING: could not remove bucket index (r=" << r << ")" << dendl; } @@ -8987,7 +8987,6 @@ int RGWRados::cls_bucket_head(const RGWBucketInfo& bucket_info, const rgw::bucke } r = CLSRGWIssueGetDirHeader(index_pool.ioctx(), oids, list_results, cct->_conf->rgw_bucket_index_max_aio)(); - ldout(cct, 20) << "CLSRGWIssueGetDirHeader issued" << dendl; if (r < 0) { ldout(cct, 20) << "cls_bucket_head: CLSRGWIssueGetDirHeader() returned " << r << dendl; diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 719c6b75bc2ae..c34ad880a90ff 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -681,14 +681,13 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries, ret = update_num_shards(num_shards, dpp); if (ret < 0) { - return ret; + // shard state is uncertain, but this will attempt to remove them anyway goto error_out; } if (reshard_log) { ret = reshard_log->update(bucket_info); if (ret < 0) { - return ret; goto error_out; } } @@ -719,7 +718,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries, // at this point since all we're using a best effor to to remove old // shard objects - ret = store->svc()->bi->clean_index(bucket_info); + ret = store->svc()->bi->clean_index(bucket_info, std::nullopt); if (ret < 0) { lderr(store->ctx()) << "Error: " << __func__ << " failed to clean up old shards; " << @@ -740,7 +739,7 @@ error_out: // since the real problem is the issue that led to this error code // path, we won't touch ret and instead use another variable to // temporarily error codes - int ret2 = store->svc()->bi->clean_index(bucket_info); + int ret2 = store->svc()->bi->clean_index(bucket_info, std::nullopt); if (ret2 < 0) { lderr(store->ctx()) << "Error: " << __func__ << " failed to clean up shards from failed incomplete resharding; " << @@ -780,6 +779,10 @@ void RGWReshard::get_bucket_logshard_oid(const string& tenant, const string& buc int RGWReshard::add(cls_rgw_reshard_entry& entry) { + if (!store->svc()->zone->can_reshard()) { + ldout(store->ctx(), 20) << __func__ << " Resharding is disabled" << dendl; + return 0; + } string logshard_oid; diff --git a/src/rgw/services/svc_bi.h b/src/rgw/services/svc_bi.h index cf6e605c87c3a..93d5a033f0303 100644 --- a/src/rgw/services/svc_bi.h +++ b/src/rgw/services/svc_bi.h @@ -30,7 +30,7 @@ public: virtual ~RGWSI_BucketIndex() {} virtual int init_index(RGWBucketInfo& bucket_info) = 0; - virtual int clean_index(RGWBucketInfo& bucket_info) = 0; + virtual int clean_index(RGWBucketInfo& bucket_info, std::optional gen) = 0; virtual int read_stats(const RGWBucketInfo& bucket_info, RGWBucketEnt *stats, diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index a13d1a8c5c539..5dc747580a4bd 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -112,6 +112,45 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const RGWBucketInfo& bucket_info, return 0; } +static void get_bucket_index_objects(const string& bucket_oid_base, + uint32_t num_shards, std::optional _gen_id, + map *_bucket_objects, + int shard_id = -1) +{ + auto& bucket_objects = *_bucket_objects; + auto gen_id = _gen_id.value_or(0); + if (!num_shards) { + bucket_objects[0] = bucket_oid_base; + } else { + char buf[bucket_oid_base.size() + 64]; + if (shard_id < 0) { + for (uint32_t i = 0; i < num_shards; ++i) { + if (gen_id) { + snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, i); + bucket_objects[i] = buf; + } else { + snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), i); + bucket_objects[i] = buf; + } + } + } else { + if ((uint32_t)shard_id > num_shards) { + return; + } else { + if (gen_id) { + snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id); + bucket_objects[shard_id] = buf; + } else { + // for backward compatibility, gen_id(0) will not be added in the object name + snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id); + bucket_objects[shard_id] = buf; + } + } + } + } +} + +/* static void get_bucket_index_objects(const string& bucket_oid_base, uint32_t num_shards, map *_bucket_objects, @@ -136,6 +175,7 @@ static void get_bucket_index_objects(const string& bucket_oid_base, } } } +*/ static void get_bucket_instance_ids(const RGWBucketInfo& bucket_info, int shard_id, @@ -179,10 +219,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const RGWBucketInfo& bucket_info, return ret; } - //auto gen = bucket_info.layout.current_index.gen; - - // TODO: need reshard changes to add gen_id here - get_bucket_index_objects(bucket_oid_base, bucket_info.layout.current_index.layout.normal.num_shards, bucket_objs, shard_id); + get_bucket_index_objects(bucket_oid_base, idx_layout.layout.normal.num_shards, + idx_layout.gen, bucket_objs, shard_id); if (bucket_instance_ids) { // TODO: generation need to be passed here get_bucket_instance_ids(bucket_info, shard_id, bucket_instance_ids); @@ -202,8 +240,9 @@ void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_b } else { char buf[bucket_oid_base.size() + 64]; if (gen_id != 0) { - snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id); + snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id); (*bucket_obj) = buf; + ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl; } else { // for backward compatibility, gen_id(0) will not be added in the object name snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id); @@ -273,7 +312,7 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket_info, int shard_id, - const rgw::bucket_index_layout_generation& idx_layout, + const rgw::bucket_index_layout_generation& target_layout, RGWSI_RADOS::Obj *bucket_obj) { RGWSI_RADOS::Pool index_pool; @@ -287,8 +326,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket string oid; - get_bucket_index_object(bucket_oid_base, idx_layout.layout.normal.num_shards, - shard_id, idx_layout.gen, &oid); + get_bucket_index_object(bucket_oid_base, target_layout.layout.normal.num_shards, + shard_id, target_layout.gen, &oid); *bucket_obj = svc.rados->obj(index_pool, oid); @@ -324,7 +363,6 @@ int RGWSI_BucketIndex_RADOS::cls_bucket_head(const RGWBucketInfo& bucket_info, return 0; } - int RGWSI_BucketIndex_RADOS::init_index(RGWBucketInfo& bucket_info) { RGWSI_RADOS::Pool index_pool; @@ -338,14 +376,15 @@ int RGWSI_BucketIndex_RADOS::init_index(RGWBucketInfo& bucket_info) dir_oid.append(bucket_info.bucket.bucket_id); map bucket_objs; - get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, &bucket_objs); + get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, std::nullopt, &bucket_objs); return CLSRGWIssueBucketIndexInit(index_pool.ioctx(), bucket_objs, cct->_conf->rgw_bucket_index_max_aio)(); } -int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info) + +int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, std::optional gen) { RGWSI_RADOS::Pool index_pool; @@ -358,7 +397,7 @@ int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info) dir_oid.append(bucket_info.bucket.bucket_id); std::map bucket_objs; - get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, &bucket_objs); + get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, gen.value_or(0), &bucket_objs); return CLSRGWIssueBucketIndexClean(index_pool.ioctx(), bucket_objs, diff --git a/src/rgw/services/svc_bi_rados.h b/src/rgw/services/svc_bi_rados.h index b7a09acf49733..918697ad035a8 100644 --- a/src/rgw/services/svc_bi_rados.h +++ b/src/rgw/services/svc_bi_rados.h @@ -94,8 +94,7 @@ public: } int init_index(RGWBucketInfo& bucket_info); - int clean_index(RGWBucketInfo& bucket_info); - + int clean_index(RGWBucketInfo& bucket_info, std::optional gen); /* RADOS specific */ -- 2.39.5