rgw: change cls rgw reshard status to enum class

Get the type safety and reduced impact on global namespace of enum
class.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
This commit is contained in:
J. Eric Ivancich 2019-09-26 20:57:39 -04:00
parent d5b0eb8c5b
commit 61d4498d0b
7 changed files with 36 additions and 33 deletions

View File

@ -746,11 +746,12 @@ void cls_rgw_bucket_instance_entry::dump(Formatter *f) const
}
void cls_rgw_bucket_instance_entry::generate_test_instances(list<cls_rgw_bucket_instance_entry*>& ls)
void cls_rgw_bucket_instance_entry::generate_test_instances(
list<cls_rgw_bucket_instance_entry*>& ls)
{
ls.push_back(new cls_rgw_bucket_instance_entry);
ls.push_back(new cls_rgw_bucket_instance_entry);
ls.back()->reshard_status = CLS_RGW_RESHARD_IN_PROGRESS;
ls.back()->reshard_status = RESHARD_STATUS::IN_PROGRESS;
ls.back()->new_bucket_instance_id = "new_instance_id";
}

View File

@ -721,32 +721,32 @@ struct rgw_bucket_category_stats {
};
WRITE_CLASS_ENCODER(rgw_bucket_category_stats)
enum cls_rgw_reshard_status {
CLS_RGW_RESHARD_NOT_RESHARDING = 0,
CLS_RGW_RESHARD_IN_PROGRESS = 1,
CLS_RGW_RESHARD_DONE = 2,
enum class cls_rgw_reshard_status : uint8_t {
NOT_RESHARDING = 0,
IN_PROGRESS = 1,
DONE = 2
};
static inline std::string to_string(const enum cls_rgw_reshard_status status)
static inline std::string to_string(const cls_rgw_reshard_status status)
{
switch (status) {
case CLS_RGW_RESHARD_NOT_RESHARDING:
case cls_rgw_reshard_status::NOT_RESHARDING:
return "not-resharding";
break;
case CLS_RGW_RESHARD_IN_PROGRESS:
case cls_rgw_reshard_status::IN_PROGRESS:
return "in-progress";
break;
case CLS_RGW_RESHARD_DONE:
case cls_rgw_reshard_status::DONE:
return "done";
break;
default:
break;
};
return "Unknown reshard status";
}
struct cls_rgw_bucket_instance_entry {
cls_rgw_reshard_status reshard_status{CLS_RGW_RESHARD_NOT_RESHARDING};
using RESHARD_STATUS = cls_rgw_reshard_status;
cls_rgw_reshard_status reshard_status{RESHARD_STATUS::NOT_RESHARDING};
string new_bucket_instance_id;
int32_t num_shards{-1};
@ -772,21 +772,23 @@ struct cls_rgw_bucket_instance_entry {
static void generate_test_instances(list<cls_rgw_bucket_instance_entry*>& o);
void clear() {
reshard_status = CLS_RGW_RESHARD_NOT_RESHARDING;
reshard_status = RESHARD_STATUS::NOT_RESHARDING;
new_bucket_instance_id.clear();
}
void set_status(const string& new_instance_id, int32_t new_num_shards, cls_rgw_reshard_status s) {
void set_status(const string& new_instance_id,
int32_t new_num_shards,
cls_rgw_reshard_status s) {
reshard_status = s;
new_bucket_instance_id = new_instance_id;
num_shards = new_num_shards;
}
bool resharding() const {
return reshard_status != CLS_RGW_RESHARD_NOT_RESHARDING;
return reshard_status != RESHARD_STATUS::NOT_RESHARDING;
}
bool resharding_in_progress() const {
return reshard_status == CLS_RGW_RESHARD_IN_PROGRESS;
return reshard_status == RESHARD_STATUS::IN_PROGRESS;
}
};
WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry)

View File

@ -2723,7 +2723,7 @@ int check_reshard_bucket_params(rgw::sal::RGWRadosStore *store,
return ret;
}
if (bucket_info.reshard_status != CLS_RGW_RESHARD_NOT_RESHARDING) {
if (bucket_info.reshard_status != cls_rgw_reshard_status::NOT_RESHARDING) {
// if in_progress or done then we have an old BucketInfo
cerr << "ERROR: the bucket is currently undergoing resharding and "
"cannot be added to the reshard list at this time" << std::endl;

View File

@ -1673,7 +1673,7 @@ void get_stale_instances(rgw::sal::RGWRadosStore *store, const std::string& buck
<< cpp_strerror(-r) << dendl;
continue;
}
if (binfo.reshard_status == CLS_RGW_RESHARD_DONE)
if (binfo.reshard_status == cls_rgw_reshard_status::DONE)
stale_instances.emplace_back(std::move(binfo));
else {
other_instances.emplace_back(std::move(binfo));
@ -1700,7 +1700,7 @@ void get_stale_instances(rgw::sal::RGWRadosStore *store, const std::string& buck
}
// Don't process further in this round if bucket is resharding
if (cur_bucket_info.reshard_status == CLS_RGW_RESHARD_IN_PROGRESS)
if (cur_bucket_info.reshard_status == cls_rgw_reshard_status::IN_PROGRESS)
return;
other_instances.erase(std::remove_if(other_instances.begin(), other_instances.end(),

View File

@ -1125,8 +1125,8 @@ struct RGWBucketInfo {
RGWQuotaInfo quota;
// Represents the number of bucket index object shards:
// - value of 0 indicates there is no sharding (this is by default before this
// feature is implemented).
// - value of 0 indicates there is no sharding (this is by default
// before this feature is implemented).
// - value of UINT32_T::MAX indicates this is a blind bucket.
uint32_t num_shards{0};
@ -1148,10 +1148,8 @@ struct RGWBucketInfo {
map<string, uint32_t> mdsearch_config;
/* resharding */
uint8_t reshard_status{0};
// resharding
cls_rgw_reshard_status reshard_status{cls_rgw_reshard_status::NOT_RESHARDING};
string new_bucket_instance_id;
RGWObjectLock obj_lock;

View File

@ -518,7 +518,7 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_
return 0;
}
if (cur_bucket_info.reshard_status == CLS_RGW_RESHARD_IN_PROGRESS) {
if (cur_bucket_info.reshard_status == cls_rgw_reshard_status::IN_PROGRESS) {
ldout(store->ctx(), 0) << __func__ << ": reshard in progress. Skipping "
<< orphan_bucket.name << ": "
<< orphan_bucket.bucket_id << dendl;

View File

@ -310,7 +310,7 @@ int RGWBucketReshard::clear_index_shard_reshard_status(rgw::sal::RGWRadosStore*
int ret = set_resharding_status(store, bucket_info,
bucket_info.bucket.bucket_id,
(num_shards < 1 ? 1 : num_shards),
CLS_RGW_RESHARD_NOT_RESHARDING);
cls_rgw_reshard_status::NOT_RESHARDING);
if (ret < 0) {
ldout(store->ctx(), 0) << "RGWBucketReshard::" << __func__ <<
" ERROR: error clearing reshard status from index shard " <<
@ -336,7 +336,7 @@ static int create_new_bucket_instance(rgw::sal::RGWRadosStore *store,
new_bucket_info.objv_tracker.clear();
new_bucket_info.new_bucket_instance_id.clear();
new_bucket_info.reshard_status = 0;
new_bucket_info.reshard_status = cls_rgw_reshard_status::NOT_RESHARDING;
int ret = store->svc()->bi->init_index(new_bucket_info);
if (ret < 0) {
@ -413,12 +413,14 @@ public:
" clear_index_shard_status returned " << ret << dendl;
}
bucket_info.new_bucket_instance_id.clear();
set_status(CLS_RGW_RESHARD_NOT_RESHARDING); // clears new_bucket_instance as well
// clears new_bucket_instance as well
set_status(cls_rgw_reshard_status::NOT_RESHARDING);
}
}
int start() {
int ret = set_status(CLS_RGW_RESHARD_IN_PROGRESS);
int ret = set_status(cls_rgw_reshard_status::IN_PROGRESS);
if (ret < 0) {
return ret;
}
@ -427,7 +429,7 @@ public:
}
int complete() {
int ret = set_status(CLS_RGW_RESHARD_DONE);
int ret = set_status(cls_rgw_reshard_status::DONE);
if (ret < 0) {
return ret;
}
@ -711,7 +713,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
// set resharding status of current bucket_info & shards with
// information about planned resharding
ret = set_resharding_status(new_bucket_info.bucket.bucket_id,
num_shards, CLS_RGW_RESHARD_IN_PROGRESS);
num_shards, cls_rgw_reshard_status::IN_PROGRESS);
if (ret < 0) {
goto error_out;
}