From 403d139c673180ce00eab420a2fdebdacf366dac Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 12 Sep 2017 12:48:56 -0400 Subject: [PATCH] rgw: add rgw_bucket_sync_status() to bypass manager RGWBucketSyncStatusManager::init() is doing a lot of extra work that's not needed to serve the rest api (spawning an http manager thread, fetching the bucket instance info, etc) uses RGWShardCollectCR to limit the number of concurrent reads to 16 Signed-off-by: Casey Bodley --- src/rgw/rgw_data_sync.cc | 55 ++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_data_sync.h | 5 ++++ 2 files changed, 60 insertions(+) diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index af6cfd2ff10a5..2a29a18fb0d87 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -3106,6 +3106,61 @@ string RGWBucketSyncStatusManager::status_oid(const string& source_zone, return bucket_status_oid_prefix + "." + source_zone + ":" + bs.get_key(); } +class RGWCollectBucketSyncStatusCR : public RGWShardCollectCR { + static constexpr int max_concurrent_shards = 16; + RGWRados *const store; + RGWDataSyncEnv *const env; + const int num_shards; + rgw_bucket_shard bs; + + using Vector = std::vector; + Vector::iterator i, end; + + public: + RGWCollectBucketSyncStatusCR(RGWRados *store, RGWDataSyncEnv *env, + int num_shards, const rgw_bucket& bucket, + Vector *status) + : RGWShardCollectCR(store->ctx(), max_concurrent_shards), + store(store), env(env), num_shards(num_shards), + bs(bucket, num_shards > 0 ? 0 : -1), // start at shard 0 or -1 + i(status->begin()), end(status->end()) + {} + + bool spawn_next() override { + if (i == end) { + return false; + } + spawn(new RGWReadBucketSyncStatusCoroutine(env, bs, &*i), false); + ++i; + ++bs.shard_id; + return true; + } +}; + +int rgw_bucket_sync_status(RGWRados *store, const std::string& source_zone, + const rgw_bucket& bucket, + std::vector *status) +{ + // read the bucket instance info for num_shards + RGWObjectCtx ctx(store); + RGWBucketInfo info; + int ret = store->get_bucket_instance_info(ctx, bucket, info, nullptr, nullptr); + if (ret < 0) { + return ret; + } + status->clear(); + status->resize(std::max(1, info.num_shards)); + + RGWDataSyncEnv env; + RGWSyncModuleInstanceRef module; // null sync module + env.init(store->ctx(), store, nullptr, store->get_async_rados(), + nullptr, nullptr, nullptr, source_zone, module); + + RGWCoroutinesManager crs(store->ctx(), store->get_cr_registry()); + return crs.run(new RGWCollectBucketSyncStatusCR(store, &env, info.num_shards, + bucket, status)); +} + // TODO: move into rgw_data_sync_trim.cc #undef dout_prefix diff --git a/src/rgw/rgw_data_sync.h b/src/rgw/rgw_data_sync.h index 2a59fdac328b9..f4d3c7e7138ae 100644 --- a/src/rgw/rgw_data_sync.h +++ b/src/rgw/rgw_data_sync.h @@ -530,6 +530,11 @@ public: int run(); }; +/// read the sync status of all bucket shards from the given source zone +int rgw_bucket_sync_status(RGWRados *store, const std::string& source_zone, + const rgw_bucket& bucket, + std::vector *status); + class RGWDefaultSyncModule : public RGWSyncModule { public: RGWDefaultSyncModule() {} -- 2.39.5