We used to instantiate a single RGWRados object.
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
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;
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()) {
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;
}
}
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;
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;
}
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;
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;
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;
unregister_async_signal_handler(SIGHUP, sighup_handler);
+ RGWStoreManager::close_storage(store);
+
return 0;
}
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;
}
++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);
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;
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";
}
}
-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)
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;
+}
+
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);
/**
};
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);
+
};