From ef92157c328d6c31e9a5e51f88a72b8bac24409b Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 10 Aug 2012 16:27:21 -0700 Subject: [PATCH] rgw: remove static store object We used to instantiate a single RGWRados object. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 24 ++++++++++++------ src/rgw/rgw_gc.cc | 2 +- src/rgw/rgw_main.cc | 5 ++-- src/rgw/rgw_op.cc | 6 ++--- src/rgw/rgw_op.h | 4 +-- src/rgw/rgw_rados.cc | 58 ++++++++++++++++++++++---------------------- src/rgw/rgw_rados.h | 19 +++++---------- 7 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index f528d7133a16a..4c61d9a0a112d 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -648,6 +648,15 @@ static int remove_bucket(rgw_bucket& bucket, bool delete_children) return ret; } +class StoreRef { + RGWRados *s; +public: + StoreRef(RGWRados *_s) : s(_s) {} + ~StoreRef() { + RGWStoreManager::close_storage(s); + } +}; + int main(int argc, char **argv) { vector args; @@ -841,13 +850,14 @@ int main(int argc, char **argv) opt_cmd == OPT_SUBUSER_CREATE || opt_cmd == OPT_SUBUSER_RM || opt_cmd == OPT_KEY_CREATE || opt_cmd == OPT_KEY_RM || opt_cmd == OPT_USER_RM); - RGWStoreManager store_manager; - store = store_manager.init(g_ceph_context, false); + store = RGWStoreManager::get_storage(g_ceph_context, false); if (!store) { cerr << "couldn't init storage provider" << std::endl; return 5; //EIO } + StoreRef s(store); + if (opt_cmd != OPT_USER_CREATE && opt_cmd != OPT_LOG_SHOW && opt_cmd != OPT_LOG_LIST && opt_cmd != OPT_LOG_RM && user_id.empty()) { @@ -1192,11 +1202,11 @@ int main(int argc, char **argv) aclbl.clear(); policy.encode(aclbl); - r = rgwstore->set_attr(NULL, obj, RGW_ATTR_ACL, aclbl); + r = store->set_attr(NULL, obj, RGW_ATTR_ACL, aclbl); if (r < 0) return r; - r = rgw_add_bucket(info.user_id, bucket); + r = rgw_add_bucket(store, info.user_id, bucket); if (r < 0) return r; } @@ -1636,7 +1646,7 @@ next: } if (opt_cmd == OPT_OBJECT_RM) { - int ret = remove_object(bucket, object); + int ret = remove_object(store, bucket, object); if (ret < 0) { cerr << "ERROR: object remove returned: " << cpp_strerror(-ret) << std::endl; @@ -1662,7 +1672,7 @@ next: do { list result; - ret = rgwstore->list_gc_objs(&index, marker, 1000, result, &truncated); + ret = store->list_gc_objs(&index, marker, 1000, result, &truncated); if (ret < 0) { cerr << "ERROR: failed to list objs: " << cpp_strerror(-ret) << std::endl; return 1; @@ -1694,7 +1704,7 @@ next: } if (opt_cmd == OPT_GC_PROCESS) { - int ret = rgwstore->process_gc(); + int ret = store->process_gc(); if (ret < 0) { cerr << "ERROR: gc processing returned error: " << cpp_strerror(-ret) << std::endl; return 1; diff --git a/src/rgw/rgw_gc.cc b/src/rgw/rgw_gc.cc index b4f131f633623..2ae7a3f66d879 100644 --- a/src/rgw/rgw_gc.cc +++ b/src/rgw/rgw_gc.cc @@ -183,7 +183,7 @@ int RGWGC::process(int index, int max_secs) delete ctx; ctx = new IoCtx; } - ret = rgwstore->rados->ioctx_create(obj.pool.c_str(), *ctx); + ret = store->rados->ioctx_create(obj.pool.c_str(), *ctx); if (ret < 0) { dout(0) << "ERROR: failed to create ioctx pool=" << obj.pool << dendl; continue; diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 6af025f49b263..2bfa9215e1a94 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -418,10 +418,9 @@ int main(int argc, const char **argv) sighandler_term = signal(SIGTERM, godown_alarm); - RGWStoreManager store_manager; int r = 0; - RGWRados *store = store_manager.init(g_ceph_context, true); + RGWRados *store = RGWStoreManager::get_storage(g_ceph_context, true); if (!store) { derr << "Couldn't init storage provider (RADOS)" << dendl; r = EIO; @@ -448,6 +447,8 @@ int main(int argc, const char **argv) unregister_async_signal_handler(SIGHUP, sighup_handler); + RGWStoreManager::close_storage(store); + return 0; } diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 84e1f4739753e..22c2069096b17 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -363,7 +363,7 @@ void RGWGetObj::execute() if (ofs <= end) { if (start_time > gc_invalidate_time) { - int r = rgwstore->defer_gc(s->obj_ctx, obj); + int r = store->defer_gc(s->obj_ctx, obj); if (r < 0) { dout(0) << "WARNING: could not defer gc entry for obj" << dendl; } @@ -1812,8 +1812,8 @@ void RGWDeleteMultiObj::execute() ++iter, num_processed++) { rgw_obj obj(bucket,(*iter)); - rgwstore->set_atomic(s->obj_ctx, obj); - ret = rgwstore->delete_obj(s->obj_ctx, obj); + store->set_atomic(s->obj_ctx, obj); + ret = store->delete_obj(s->obj_ctx, obj); result = make_pair(*iter, ret); send_partial_response(result); diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 0661b1b7f7cd8..f32d1ff8299de 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -684,8 +684,8 @@ protected: public: RGWDeleteMultiObj() {} - virtual void init(struct req_state *s, RGWHandler *h) { - RGWOp::init(s, h); + virtual void init(RGWRados *store, struct req_state *s, RGWHandler *h) { + RGWOp::init(store, s, h); ret = 0; max_to_delete = 1000; len = 0; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index d02774c1827fa..42150ae9559ba 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -36,9 +36,6 @@ using namespace std; static RGWCache cached_rados_provider; static RGWRados rados_provider; -RGWRados* RGWRados::store; - - static string notify_oid_prefix = "notify"; static string *notify_oids = NULL; static string shadow_ns = "shadow"; @@ -107,32 +104,6 @@ void RGWRadosCtx::set_prefetch_data(rgw_obj& obj) { } } -RGWRados *RGWRados::init_storage_provider(CephContext *cct, bool use_gc_thread) -{ - int use_cache = cct->_conf->rgw_cache_enabled; - store = NULL; - if (!use_cache) { - store = &rados_provider; - } else { - store = &cached_rados_provider; - } - - if (store->initialize(cct, use_gc_thread) < 0) - store = NULL; - - return store; -} - -void RGWRados::close_storage() -{ - if (!store) - return; - - store->finalize(); - store = NULL; -} - - void RGWRados::finalize() { if (use_gc_thread) @@ -3225,3 +3196,32 @@ uint64_t RGWRados::next_bucket_id() Mutex::Locker l(bucket_id_lock); return ++max_bucket_id; } + +RGWRados *RGWStoreManager::init_storage_provider(CephContext *cct, bool use_gc_thread) +{ + int use_cache = cct->_conf->rgw_cache_enabled; + RGWRados *store = NULL; + if (!use_cache) { + store = new RGWRados; + } else { + store = new RGWCache; + } + + if (store->initialize(cct, use_gc_thread) < 0) { + delete store; + return NULL; + } + + return store; +} + +void RGWStoreManager::close_storage(RGWRados *store) +{ + if (!store) + return; + + store->finalize(); + + delete store; +} + diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 0030da4919dc0..4a86182becd52 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -314,10 +314,6 @@ public: virtual int initialize(); virtual void finalize(); - static RGWRados *init_storage_provider(CephContext *cct, bool use_gc_thread); - static void close_storage(); - static RGWRados *store; - /** set up a bucket listing. handle is filled in. */ virtual int list_buckets_init(RGWAccessHandle *handle); /** @@ -661,18 +657,15 @@ public: }; class RGWStoreManager { - RGWRados *store; public: - RGWStoreManager(): store(NULL) {} - ~RGWStoreManager() { - if (store) { - RGWRados::close_storage(); - } - } - RGWRados *init(CephContext *cct, bool use_gc_thread) { - store = RGWRados::init_storage_provider(cct, use_gc_thread); + RGWStoreManager() {} + static RGWRados *get_storage(CephContext *cct, bool use_gc_thread) { + RGWRados *store = init_storage_provider(cct, use_gc_thread); return store; } + static RGWRados *init_storage_provider(CephContext *cct, bool use_gc_thread); + static void close_storage(RGWRados *store); + }; -- 2.39.5