]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: remove static store object
authorYehuda Sadeh <yehuda@inktank.com>
Fri, 10 Aug 2012 23:27:21 +0000 (16:27 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 29 Aug 2012 21:27:47 +0000 (14:27 -0700)
We used to instantiate a single RGWRados object.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_gc.cc
src/rgw/rgw_main.cc
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index f528d7133a16af3c3ffc3c257d37977718a76df5..4c61d9a0a112d27c94697ad918b6a13cdc21388e 100644 (file)
@@ -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<const char*> 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<cls_rgw_gc_obj_info> 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;
index b4f131f633623f1519ff5411e371fa36ac5f07db..2ae7a3f66d8796421a6fa889bcb425ec9a677bc3 100644 (file)
@@ -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;
index 6af025f49b263fb86999923d36494596c93323c2..2bfa9215e1a94b140125cd37f6fa05ba6c0beb68 100644 (file)
@@ -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;
 }
 
index 84e1f4739753e04a8f893fee8138b08b83c315f0..22c2069096b17491c405fb802014f86951cb37d0 100644 (file)
@@ -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);
index 0661b1b7f7cd893b0e5b62fd26ef70be5e431398..f32d1ff8299de4573aa49034f7459e3bb83f8708 100644 (file)
@@ -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;
index d02774c1827fa0c8646478be605bd00c5fabf7a8..42150ae9559ba32485663ce74bfc236df3d1954a 100644 (file)
@@ -36,9 +36,6 @@ using namespace std;
 static RGWCache<RGWRados> 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<RGWRados>; 
+  }
+
+  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;
+}
+
index 0030da4919dc06260761b7962934d83b8bb19152..4a86182becd522c47301bb73cae1ec76e72c3a4d 100644 (file)
@@ -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);
+
 };