From c09155f7509f50900af2f9e16d70db4977c75d22 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Thu, 14 Apr 2022 09:35:40 -0400 Subject: [PATCH] rgw: Disentangle read_sync_status from RemoteBucketManager Also fix the problem where we read the status from all peers into the same map at once. Signed-off-by: Adam C. Emerson --- src/rgw/rgw_data_sync.cc | 79 ++++++++++++++++++++++++++++++++++++---- src/rgw/rgw_data_sync.h | 3 ++ 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index e947879363e1e..eb503c16a3916 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -5414,6 +5414,11 @@ int RGWBucketPipeSyncStatusManager::do_init(const DoutPrefixProvider *dpp) return ret; } + if (pipes.empty()) { + ldpp_dout(this, 0) << "No peers. This is not a valid multisite configuration." << dendl; + return -EINVAL; + } + for (auto& pipe : pipes) { auto& szone = pipe.source.zone; @@ -5449,6 +5454,36 @@ int RGWBucketPipeSyncStatusManager::do_init(const DoutPrefixProvider *dpp) return 0; } +int RGWBucketPipeSyncStatusManager::remote_info(const DoutPrefixProvider *dpp, + source& s, + uint64_t* oldest_gen, + uint64_t* latest_gen, + uint64_t* num_shards) +{ + rgw_bucket_index_marker_info remote_info; + BucketIndexShardsManager remote_markers; + auto r = rgw_read_remote_bilog_info(dpp, s.sc.conn, s.info.bucket, + remote_info, remote_markers, + null_yield); + + if (r < 0) { + ldpp_dout(dpp, 0) << __PRETTY_FUNCTION__ << ":" << __LINE__ + << " rgw_read_remote_bilog_info: r=" + << r << dendl; + return r; + } + if (oldest_gen) + *oldest_gen = remote_info.oldest_gen; + + if (latest_gen) + *latest_gen = remote_info.latest_gen; + + if (num_shards) + *num_shards = remote_markers.get().size(); + + return 0; +} + tl::expected, int> RGWBucketPipeSyncStatusManager::construct( const DoutPrefixProvider* dpp, @@ -5498,16 +5533,46 @@ RGWBucketPipeSyncStatusManager::read_sync_status( std::map sync_status; list stacks; - for (auto& mgr : source_mgrs) { - RGWCoroutinesStack *stack = new RGWCoroutinesStack(store->ctx(), &cr_mgr); - for (int i = 0; i < mgr.num_pipes(); ++i) { - stack->call(mgr.read_sync_status_cr(i, &sync_status[i])); - } + auto sz = sources.begin(); - stacks.push_back(stack); + if (source_zone) { + sz = std::find_if(sources.begin(), sources.end(), + [this](const source& s) { + return s.sc.source_zone == *source_zone; + } + ); + if (sz == sources.end()) { + ldpp_dout(this, 0) << "ERROR: failed to find source zone: " + << *source_zone << dendl; + return tl::unexpected(-ENOENT); + } + } else { + ldpp_dout(this, 5) << "No source zone specified, using source zone: " + << sz->sc.source_zone << dendl; + return tl::unexpected(-ENOENT); + } + uint64_t num_shards, latest_gen; + auto ret = remote_info(dpp, *sz, nullptr, &latest_gen, &num_shards); + if (!ret) { + ldpp_dout(this, 5) << "Unable to get remote info: " + << ret << dendl; + return tl::unexpected(ret); + } + auto stack = new RGWCoroutinesStack(store->ctx(), &cr_mgr); + std::vector pairs(num_shards); + for (auto shard = 0u; shard < num_shards; ++shard) { + auto& pair = pairs[shard]; + pair.source_bs.bucket = sz->info.bucket; + pair.dest_bucket = sz->dest; + pair.source_bs.shard_id = shard; + stack->call(new RGWReadBucketPipeSyncStatusCoroutine( + &sz->sc, pair, &sync_status[shard], + nullptr, latest_gen)); } - int ret = cr_mgr.run(dpp, stacks); + stacks.push_back(stack); + + ret = cr_mgr.run(dpp, stacks); if (ret < 0) { ldpp_dout(this, 0) << "ERROR: failed to read sync status for " << bucket_str{dest_bucket} << dendl; diff --git a/src/rgw/rgw_data_sync.h b/src/rgw/rgw_data_sync.h index 8d1d9925c73bc..b4556de3d4420 100644 --- a/src/rgw/rgw_data_sync.h +++ b/src/rgw/rgw_data_sync.h @@ -756,6 +756,9 @@ class RGWBucketPipeSyncStatusManager : public DoutPrefixProvider { : store(store), source_zone(source_zone), source_bucket(source_bucket), dest_bucket(dest_bucket) {} + int remote_info(const DoutPrefixProvider *dpp, source& s, + uint64_t* oldest_gen, uint64_t* latest_gen, + uint64_t* num_shards); public: static tl::expected, int> construct(const DoutPrefixProvider* dpp, rgw::sal::RadosStore* store, -- 2.39.5