From eb8c6b7585bae09ad24b25bea0cef5b10bd8c3d0 Mon Sep 17 00:00:00 2001 From: Shilpa Jagannath Date: Tue, 21 Jul 2020 18:40:09 +0530 Subject: [PATCH] rgw: helper function to set reshard status from rgw::BucketReshardState. Signed-off-by: Shilpa Jagannath --- src/rgw/rgw_reshard.cc | 39 +++++++++++++++++++++++---------------- src/rgw/rgw_reshard.h | 2 ++ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 4a98832efc1fe..951846d1e99ff 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -327,24 +327,17 @@ static int set_target_layout(rgw::sal::RadosStore *store, RGWBucketInfo& bucket_info, const DoutPrefixProvider *dpp) { - assert(!bucket_info.layout.target_index); + bucket_info.layout.target_index = std::nullopt; // to ensure empty target_index in case of an abruptly interrupted reshard process + ceph_assert(!bucket_info.layout.target_index); bucket_info.layout.target_index.emplace(); bucket_info.layout.target_index->layout.normal.num_shards = new_num_shards; - + //increment generation number bucket_info.layout.target_index->gen = bucket_info.layout.current_index.gen; bucket_info.layout.target_index->gen++; - bucket_info.layout.resharding = rgw::BucketReshardState::InProgress; - - int ret = static_cast(store)->getRados()->put_bucket_instance_info(bucket_info, true, real_time(), nullptr, dpp); - if (ret < 0) { - cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = store->svc()->bi->init_index(dpp, bucket_info, *(bucket_info.layout.target_index)); + int ret = static_cast(store)->svc()->bi->init_index(dpp, bucket_info, *(bucket_info.layout.target_index)); if (ret < 0) { return ret; } @@ -354,6 +347,11 @@ static int set_target_layout(rgw::sal::RadosStore *store, int RGWBucketReshard::set_target_layout(int new_num_shards, const DoutPrefixProvider *dpp) { + int ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::InProgress, dpp); + if (ret < 0) { + cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl; + return ret; + } return ::set_target_layout(store, new_num_shards, bucket_info, dpp); } @@ -661,8 +659,7 @@ int RGWBucketReshard::do_reshard(int num_shards, //overwrite current_index for the next reshard process bucket_info.layout.current_index = *bucket_info.layout.target_index; bucket_info.layout.target_index = std::nullopt; // target_layout doesn't need to exist after reshard - bucket_info.layout.resharding = rgw::BucketReshardState::None; - ret = store->getRados()->put_bucket_instance_info(bucket_info, false, real_time(), nullptr, dpp); + ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::None, dpp); if (ret < 0) { ldpp_dout(dpp, -1) << "ERROR: failed writing bucket instance info: " << dendl; return ret; @@ -677,6 +674,15 @@ int RGWBucketReshard::get_status(const DoutPrefixProvider *dpp, listsvc()->bi_rados->get_reshard_status(dpp, bucket_info, status); } +int RGWBucketReshard::set_reshard_status(rgw::BucketReshardState s, const DoutPrefixProvider* dpp) { + bucket_info.layout.resharding = s; + int ret = store->getRados()->put_bucket_instance_info(bucket_info, false, real_time(), nullptr, dpp); + if (ret < 0) { + ldout(store->ctx(), 0) << "ERROR: failed to write bucket info, ret=" << ret << dendl; + return ret; + } + return 0; +} int RGWBucketReshard::execute(int num_shards, int max_op_entries, const DoutPrefixProvider *dpp, @@ -757,11 +763,12 @@ error_out: return ret; } - ret = store->svc()->bi->init_index(dpp, bucket_info, bucket_info.layout.current_index); + ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::None, dpp); if (ret < 0) { - return ret; + cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl; + return ret; } - + return ret; } // execute diff --git a/src/rgw/rgw_reshard.h b/src/rgw/rgw_reshard.h index ed1325d5adf5f..29b6b30e6b79e 100644 --- a/src/rgw/rgw_reshard.h +++ b/src/rgw/rgw_reshard.h @@ -86,6 +86,8 @@ private: static const std::initializer_list reshard_primes; int set_target_layout(int new_num_shards, const DoutPrefixProvider *dpp); + int set_reshard_status(rgw::BucketReshardState s, const DoutPrefixProvider* dpp); + int do_reshard(int num_shards, int max_entries, bool verbose, -- 2.39.5