From d07306ccc79c1a8bdc957798938d087a6d90ca66 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Tue, 1 Sep 2015 12:38:39 +0200 Subject: [PATCH] rgw: add period activate admin command and fix get current command Signed-off-by: Orit Wasserman --- src/rgw/rgw_admin.cc | 31 +++++++++++++++++-------------- src/rgw/rgw_rados.cc | 16 ++++++++++++++++ src/rgw/rgw_rados.h | 1 + 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 033c2c8c27f37..be2fb9ff04f50 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1691,12 +1691,15 @@ int main(int argc, char **argv) break; case OPT_PERIOD_GET_CURRENT: { - RGWRealm realm(g_ceph_context, store); - string current_id; - int ret = realm.get_current_period_id(current_id); - if (ret == -ENOENT) { - cout << "No current period" << std::endl; + RGWRealm realm(realm_id, realm_name); + int ret = realm.init(g_ceph_context, store); + if (ret < 0 ) { + cerr << "Error initing realm " << cpp_strerror(-ret) << std::endl; return ret; + } + string current_id = realm.get_current_period(); + if (current_id.empty()) { + cout << "No current period" << std::endl; } else if (ret < 0) { cerr << "Error reading current period:" << cpp_strerror(-ret) << std::endl; return ret; @@ -1710,16 +1713,16 @@ int main(int argc, char **argv) cerr << "Missing period id" << std::endl; return -EINVAL; } - RGWPeriod period(g_ceph_context, store, period_id); - int ret = period.init(); - if (ret < 0) { - cerr << "period init failed: " << cpp_strerror(-ret) << std::endl; - return -ret; + RGWRealm realm(realm_id, realm_name); + int ret = realm.init(g_ceph_context, store); + if (ret < 0 ) { + cerr << "Error initing realm " << cpp_strerror(-ret) << std::endl; + return ret; } - ret = period.activate(); - if (ret < 0) { - cerr << "period activate failed: " << cpp_strerror(-ret) << std::endl; - return -ret; + ret = realm.set_current_period(period_id); + if (ret < 0 ) { + cerr << "Error setting current period " << period_id << ":" << cpp_strerror(-ret) << std::endl; + return ret; } } break; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 1e7ed13ad9ea6..4acb2451ec6ec 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -552,6 +552,22 @@ const string& RGWRealm::get_info_oid_prefix(bool old_format) return realm_info_oid_prefix; } +int RGWRealm::set_current_period(const string& period_id) { + /* check to see period id is valid */ + RGWPeriod new_current(cct, store); + int ret = new_current.init(period_id); + if (ret < 0) { + return ret; + } + if (new_current.get_predecessor() != current_period) { + ldout(cct, 0) << "set_current_period new period " << period_id << + " is not a perdecessor of the current period "<< current_period << dendl; + return -EINVAL; + } + current_period = period_id; + return store_info(true); +} + int RGWPeriod::init(const string& period_id, epoch_t period_epoch, bool setup_obj) { if (!period_id.empty()) { diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index bdba0d35e8b8b..35634fdf85f31 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1202,6 +1202,7 @@ public: const string& get_current_period() { return current_period; } + int set_current_period(const string& period_id); }; WRITE_CLASS_ENCODER(RGWRealm) -- 2.39.5