From 4d72adcec9c4f17d19a755708f93044b34fdbc26 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 23 Sep 2015 11:15:10 -0400 Subject: [PATCH] rgw: add realm control object for watch/notify Signed-off-by: Casey Bodley --- src/rgw/rgw_rados.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_rados.h | 6 +++++ 2 files changed, 63 insertions(+) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 0567c6a0d5b48..12966d079e2f0 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -655,6 +655,11 @@ int RGWRealm::create(bool exclusive) ldout(cct, 0) << "ERROR creating new realm object " << name << ": " << cpp_strerror(-ret) << dendl; return ret; } + // create the control object for watch/notify + ret = create_control(); + if (ret < 0) { + return ret; + } /* create new period for the realm */ RGWPeriod period; ret = period.init(cct, store, id, name, false); @@ -681,6 +686,32 @@ int RGWRealm::create(bool exclusive) return 0; } +int RGWRealm::delete_obj() +{ + int ret = RGWSystemMetaObj::delete_obj(); + if (ret < 0) { + return ret; + } + return delete_control(); +} + +int RGWRealm::create_control() +{ + auto pool_name = get_pool_name(cct); + auto pool = rgw_bucket{pool_name.c_str()}; + auto oid = get_control_oid(); + return rgw_put_system_obj(store, pool, oid, nullptr, 0, true, + nullptr, 0, nullptr); +} + +int RGWRealm::delete_control() +{ + auto pool_name = get_pool_name(cct); + auto pool = rgw_bucket{pool_name.c_str()}; + auto obj = rgw_obj{pool, get_control_oid()}; + return store->delete_system_obj(obj); +} + const string& RGWRealm::get_pool_name(CephContext *cct) { if (cct->_conf->rgw_realm_root_pool.empty()) { @@ -728,6 +759,32 @@ int RGWRealm::set_current_period(const string& period_id, const rgw_meta_sync_st return update(); } +string RGWRealm::get_control_oid() +{ + return get_info_oid_prefix() + id + ".control"; +} + +int RGWRealm::notify_zone() +{ + // open a context on the realm's pool + auto pool = get_pool_name(cct); + librados::IoCtx ctx; + int r = store->get_rados_handle()->ioctx_create(pool.c_str(), ctx); + if (r < 0) { + lderr(cct) << "Failed to open pool " << pool << dendl; + return r; + } + // send a notify on the realm object + bufferlist bl; + r = ctx.notify2(get_control_oid(), bl, 0, nullptr); + if (r < 0) { + lderr(cct) << "Realm notify failed with " << r << dendl; + return r; + } + return 0; +} + + int RGWPeriod::init(CephContext *_cct, RGWRados *_store, const string& period_realm_id, const string& period_realm_name, bool setup_obj) { diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 8f0cdce9432c1..f2c58e0a2875a 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1262,6 +1262,8 @@ class RGWRealm : public RGWSystemMetaObj map zonegroups; string current_period; + int create_control(); + int delete_control(); public: RGWRealm() {} RGWRealm(const string& _id, const string& _name = "") : RGWSystemMetaObj(_id, _name) {} @@ -1287,6 +1289,7 @@ public: } int create(bool exclusive = true); + int delete_obj(); const string& get_pool_name(CephContext *cct); const string& get_default_oid(bool old_format = false); const string& get_names_oid_prefix(); @@ -1300,6 +1303,9 @@ public: return current_period; } int set_current_period(const string& period_id, const rgw_meta_sync_status* sync_status = NULL); + + string get_control_oid(); + int notify_zone(); }; WRITE_CLASS_ENCODER(RGWRealm) -- 2.39.5