From: Casey Bodley Date: Fri, 18 Dec 2020 15:23:55 +0000 (-0500) Subject: rgw: BucketReshardManager takes layouts X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=cb7dfc4a74e42351de21341f9c4576d4fcd77f9b;p=ceph.git rgw: BucketReshardManager takes layouts Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 3b2f095442677..ee591163c1070 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -61,7 +61,7 @@ const std::initializer_list RGWBucketReshard::reshard_primes = { class BucketReshardShard { rgw::sal::RGWRadosStore *store; const RGWBucketInfo& bucket_info; - int num_shard; + int shard_id; RGWRados::BucketShard bs; vector entries; map stats; @@ -101,15 +101,13 @@ class BucketReshardShard { } public: - BucketReshardShard(const DoutPrefixProvider *dpp, - rgw::sal::RGWRadosStore *_store, const RGWBucketInfo& _bucket_info, - int _num_shard, deque& _completions) : - store(_store), bucket_info(_bucket_info), bs(store->getRados()), - aio_completions(_completions) + BucketReshardShard(rgw::sal::RGWRadosStore *_store, const RGWBucketInfo& _bucket_info, + const rgw::bucket_index_layout_generation& index, + int shard_id, deque& _completions) : + store(_store), bucket_info(_bucket_info), shard_id(shard_id), + bs(store->getRados()), aio_completions(_completions) { - num_shard = (bucket_info.layout.target_index->layout.normal.num_shards > 0 ? _num_shard : -1); - - bs.init(bucket_info, *bucket_info.layout.target_index, num_shard); + bs.init(bucket_info, index, shard_id); max_aio_completions = store->ctx()->_conf.get_val("rgw_reshard_max_aio"); @@ -117,8 +115,8 @@ public: store->ctx()->_conf.get_val("rgw_reshard_batch_size"); } - int get_num_shard() { - return num_shard; + int get_shard_id() const { + return shard_id; } int add_entry(rgw_cls_bi_entry& entry, bool account, RGWObjCategory category, @@ -182,20 +180,19 @@ public: class BucketReshardManager { rgw::sal::RGWRadosStore *store; - const RGWBucketInfo& target_bucket_info; deque completions; vector target_shards; public: - BucketReshardManager(const DoutPrefixProvider *dpp, - rgw::sal::RGWRadosStore *_store, - const RGWBucketInfo& _target_bucket_info, - int num_target_shards) - : store(_store), target_bucket_info(_target_bucket_info) + BucketReshardManager(rgw::sal::RGWRadosStore *_store, + const RGWBucketInfo& bucket_info, + const rgw::bucket_index_layout_generation& target) + : store(_store) { - target_shards.reserve(num_target_shards); - for (int i = 0; i < num_target_shards; ++i) { - target_shards.emplace_back(dpp, store, target_bucket_info, i, completions); + const int num_shards = target.layout.normal.num_shards; + target_shards.reserve(num_shards); + for (int i = 0; i < num_shards; ++i) { + target_shards.emplace_back(store, bucket_info, target, i, completions); } } @@ -228,14 +225,14 @@ public: for (auto& shard : target_shards) { int r = shard.flush(); if (r < 0) { - derr << "ERROR: target_shards[" << shard.get_num_shard() << "].flush() returned error: " << cpp_strerror(-r) << dendl; + derr << "ERROR: target_shards[" << shard.get_shard_id() << "].flush() returned error: " << cpp_strerror(-r) << dendl; ret = r; } } for (auto& shard : target_shards) { int r = shard.wait_all_aio(); if (r < 0) { - derr << "ERROR: target_shards[" << shard.get_num_shard() << "].wait_all_aio() returned error: " << cpp_strerror(-r) << dendl; + derr << "ERROR: target_shards[" << shard.get_shard_id() << "].wait_all_aio() returned error: " << cpp_strerror(-r) << dendl; ret = r; } } @@ -584,8 +581,9 @@ int RGWBucketReshardLock::renew(const Clock::time_point& now) { } -int RGWBucketReshard::do_reshard(int num_shards, - int max_entries, +int RGWBucketReshard::do_reshard(const rgw::bucket_index_layout_generation& current, + const rgw::bucket_index_layout_generation& target, + int max_entries, bool verbose, ostream *out, Formatter *formatter, @@ -605,9 +603,7 @@ int RGWBucketReshard::do_reshard(int num_shards, return -EINVAL; } - int num_target_shards = rgw::current_num_shards(bucket_info.layout); - - BucketReshardManager target_shards_mgr(dpp, store, bucket_info, num_target_shards); + BucketReshardManager target_shards_mgr(store, bucket_info, target); bool verbose_json_out = verbose && (formatter != nullptr) && (out != nullptr); @@ -621,9 +617,7 @@ int RGWBucketReshard::do_reshard(int num_shards, (*out) << "total entries:"; } - auto current_shards = bucket_info.layout.current_index.layout.normal.num_shards; - const int num_source_shards = - (current_shards > 0 ? current_shards : 1); + const int num_source_shards = current.layout.normal.num_shards; string marker; for (int i = 0; i < num_source_shards; ++i) { bool is_truncated = true; @@ -753,8 +747,9 @@ int RGWBucketReshard::execute(int num_shards, if (ret = fault.check("do_reshard"); ret == 0) { // no fault injected, do the reshard - ret = do_reshard(num_shards, max_op_entries, - verbose, out, formatter, dpp); + ret = do_reshard(bucket_info.layout.current_index, + *bucket_info.layout.target_index, + max_op_entries, verbose, out, formatter, dpp); } if (ret < 0) { diff --git a/src/rgw/rgw_reshard.h b/src/rgw/rgw_reshard.h index ebde14e76a8a9..d3e7dc8e0fa4f 100644 --- a/src/rgw/rgw_reshard.h +++ b/src/rgw/rgw_reshard.h @@ -86,10 +86,8 @@ private: // allocated in at once static const std::initializer_list reshard_primes; - int set_target_layout(int new_num_shards, const DoutPrefixProvider *dpp); - int update_bucket(rgw::BucketReshardState s, const DoutPrefixProvider* dpp); - - int do_reshard(int num_shards, + int do_reshard(const rgw::bucket_index_layout_generation& current, + const rgw::bucket_index_layout_generation& target, int max_entries, bool verbose, ostream *os,