From 2c882b52e5a5b2c21ac63406aa95f8e7850c0fd3 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Tue, 27 Mar 2018 18:26:01 +0300 Subject: [PATCH] rgw: reshard cancel command should clear the resharding flag Fixes: http://tracker.ceph.com/issues/21619 Signed-off-by: Orit Wasserman --- src/rgw/rgw_admin.cc | 43 +++++++++++++++++++++++++++++------------- src/rgw/rgw_reshard.cc | 13 +++++++++++++ src/rgw/rgw_reshard.h | 1 + 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index d7c43cc066230..786c7efdc00bd 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -5850,30 +5850,47 @@ next: } if (opt_cmd == OPT_RESHARD_CANCEL) { - RGWReshard reshard(store); - if (bucket_name.empty()) { cerr << "ERROR: bucket not specified" << std::endl; return EINVAL; } - cls_rgw_reshard_entry entry; - //entry.tenant = tenant; - entry.bucket_name = bucket_name; - //entry.bucket_id = bucket_id; - int ret = reshard.get(entry); + + rgw_bucket bucket; + RGWBucketInfo bucket_info; + map attrs; + ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket, &attrs); if (ret < 0) { - cerr << "Error in getting bucket " << bucket_name << ": " << cpp_strerror(-ret) << std::endl; - return ret; + cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; + return -ret; } - /* TBD stop running resharding */ - - ret =reshard.remove(entry); + RGWBucketReshard br(store, bucket_info, attrs); + int ret = br.cancel(); if (ret < 0) { - cerr << "Error removing bucket " << bucket_name << " for resharding queue: " << cpp_strerror(-ret) << + cerr << "Error canceling bucket " << bucket_name << " resharding: " << cpp_strerror(-ret) << std::endl; return ret; } + + RGWReshard reshard(store); + + cls_rgw_reshard_entry entry; + //entry.tenant = tenant; + entry.bucket_name = bucket_name; + //entry.bucket_id = bucket_id; + + ret = reshard.get(entry); + if (ret < 0 && ret != -ENOENT) { + cerr << "Error in getting bucket " << bucket_name << ": " << cpp_strerror(-ret) << std::endl; + return ret; + } else if (ret != -ENOENT) { + ret = reshard.remove(entry); + if (ret < 0) { + cerr << "Error removing bucket " << bucket_name << " from resharding queue: " << cpp_strerror(-ret) << + std::endl; + return ret; + } + } } if (opt_cmd == OPT_OBJECT_UNLINK) { diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 04e95aabfd183..5ea9b3859a6d4 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -292,6 +292,19 @@ int RGWBucketReshard::create_new_bucket_instance(int new_num_shards, return ::create_new_bucket_instance(store, new_num_shards, bucket_info, bucket_attrs, new_bucket_info); } +int RGWBucketReshard::cancel() +{ + int ret = lock_bucket(); + if (ret < 0) { + return ret; + } + + ret = clear_resharding(); + + unlock_bucket(); + return 0; +} + class BucketInfoReshardUpdate { RGWRados *store; diff --git a/src/rgw/rgw_reshard.h b/src/rgw/rgw_reshard.h index e5d658531c8a0..6fe43129906f0 100644 --- a/src/rgw/rgw_reshard.h +++ b/src/rgw/rgw_reshard.h @@ -46,6 +46,7 @@ public: RGWReshard *reshard_log = nullptr); int abort(); int get_status(std::list *status); + int cancel(); }; class RGWReshard { -- 2.39.5