ldout(cct, 0) << "ERROR: rados->unwatch2() returned r=" << r << dendl;
return r;
}
- r = rados->watch_flush();
+ r = rados[0]->watch_flush();
if (r < 0) {
ldout(cct, 0) << "ERROR: rados->watch_flush() returned r=" << r << dendl;
return r;
*/
int RGWRados::init_rados()
{
- int ret;
+ int ret = 0;
- rados = new Rados();
- if (!rados)
- return -ENOMEM;
+ num_rados_handles = cct->_conf->rgw_num_rados_handles;
- ret = rados->init_with_context(cct);
- if (ret < 0)
- return ret;
+ rados = new librados::Rados *[num_rados_handles];
+ if (!rados) {
+ ret = -ENOMEM;
+ return ret;
+ }
- ret = rados->connect();
- if (ret < 0)
- return ret;
+ for (uint32_t i=0; i < num_rados_handles; i++) {
+
+ rados[i] = new Rados();
+ if (!rados[i]) {
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ ret = rados[i]->init_with_context(cct);
+ if (ret < 0) {
+ goto fail;
+ }
+
+ ret = rados[i]->connect();
+ if (ret < 0) {
+ goto fail;
+ }
+ }
meta_mgr = new RGWMetadataManager(cct, this);
data_log = new RGWDataChangesLog(cct, this);
+ return ret;
+
+fail:
+ for (uint32_t i=0; i < num_rados_handles; i++) {
+ if (rados[i]) {
+ delete rados[i];
+ }
+ }
+ if (rados) {
+ delete[] rados;
+ }
+
return ret;
}
{
const string& pool = zone.domain_root.name;
const char *pool_str = pool.c_str();
- int r = rados->ioctx_create(pool_str, root_pool_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(pool_str, root_pool_ctx);
if (r == -ENOENT) {
- r = rados->pool_create(pool_str);
+ r = rad->pool_create(pool_str);
if (r == -EEXIST)
r = 0;
if (r < 0)
return r;
- r = rados->ioctx_create(pool_str, root_pool_ctx);
+ r = rad->ioctx_create(pool_str, root_pool_ctx);
}
return r;
int RGWRados::open_gc_pool_ctx()
{
const char *gc_pool = zone.gc_pool.name.c_str();
- int r = rados->ioctx_create(gc_pool, gc_pool_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(gc_pool, gc_pool_ctx);
if (r == -ENOENT) {
- r = rados->pool_create(gc_pool);
+ r = rad->pool_create(gc_pool);
if (r == -EEXIST)
r = 0;
if (r < 0)
return r;
- r = rados->ioctx_create(gc_pool, gc_pool_ctx);
+ r = rad->ioctx_create(gc_pool, gc_pool_ctx);
}
return r;
int RGWRados::init_watch()
{
const char *control_pool = zone.control_pool.name.c_str();
- int r = rados->ioctx_create(control_pool, control_pool_ctx);
+ librados::Rados *rad = rados[0];
+ int r = rad->ioctx_create(control_pool, control_pool_ctx);
if (r == -ENOENT) {
- r = rados->pool_create(control_pool);
+ r = rad->pool_create(control_pool);
if (r == -EEXIST)
r = 0;
if (r < 0)
return r;
- r = rados->ioctx_create(control_pool, control_pool_ctx);
+ r = rad->ioctx_create(control_pool, control_pool_ctx);
if (r < 0)
return r;
}
int RGWRados::open_bucket_pool_ctx(const string& bucket_name, const string& pool, librados::IoCtx& io_ctx)
{
- int r = rados->ioctx_create(pool.c_str(), io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(pool.c_str(), io_ctx);
if (r != -ENOENT)
return r;
if (!pools_initialized)
return r;
- r = rados->pool_create(pool.c_str());
+ r = rad->pool_create(pool.c_str());
if (r < 0 && r != -EEXIST)
return r;
- r = rados->ioctx_create(pool.c_str(), io_ctx);
+ r = rad->ioctx_create(pool.c_str(), io_ctx);
return r;
}
{
log_list_state *state = new log_list_state;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, state->io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, state->io_ctx);
if (r < 0) {
delete state;
return r;
{
librados::IoCtx io_ctx;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, io_ctx);
if (r < 0)
return r;
return io_ctx.remove(name);
{
log_show_state *state = new log_show_state;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, state->io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, state->io_ctx);
if (r < 0) {
delete state;
return r;
librados::IoCtx io_ctx;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, io_ctx);
if (r == -ENOENT) {
rgw_bucket pool(log_pool);
r = create_pool(pool);
return r;
// retry
- r = rados->ioctx_create(log_pool, io_ctx);
+ r = rad->ioctx_create(log_pool, io_ctx);
}
if (r < 0)
return r;
librados::IoCtx io_ctx;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, io_ctx);
if (r == -ENOENT) {
rgw_bucket pool(log_pool);
r = create_pool(pool);
return r;
// retry
- r = rados->ioctx_create(log_pool, io_ctx);
+ r = rad->ioctx_create(log_pool, io_ctx);
}
if (r < 0)
return r;
librados::IoCtx io_ctx;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, io_ctx);
if (r < 0)
return r;
librados::ObjectReadOperation op;
librados::IoCtx io_ctx;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, io_ctx);
if (r < 0)
return r;
librados::ObjectReadOperation op;
librados::IoCtx io_ctx;
const char *log_pool = zone.log_pool.name.c_str();
- int r = rados->ioctx_create(log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(log_pool, io_ctx);
if (r < 0)
return r;
const char *pool_name = pool.name.c_str();
- int r = rados->ioctx_create(pool_name, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(pool_name, io_ctx);
if (r < 0)
return r;
const char *pool_name = pool.name.c_str();
- int r = rados->ioctx_create(pool_name, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(pool_name, io_ctx);
if (r < 0)
return r;
string pool = bucket.index_pool;
- ret = rados->pool_create(pool.c_str(), 0);
+ librados::Rados *rad = get_rados_handle();
+ ret = rad->pool_create(pool.c_str(), 0);
if (ret == -EEXIST)
ret = 0;
if (ret < 0)
return ret;
if (bucket.data_pool != pool) {
- ret = rados->pool_create(bucket.data_pool.c_str(), 0);
+ ret = rad->pool_create(bucket.data_pool.c_str(), 0);
if (ret == -EEXIST)
ret = 0;
if (ret < 0)
const string& pool = zone.domain_root.name;
const char *pool_str = pool.c_str();
librados::IoCtx id_io_ctx;
- int r = rados->ioctx_create(pool_str, id_io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(pool_str, id_io_ctx);
if (r < 0)
return r;
int RGWRados::add_bucket_placement(std::string& new_pool)
{
- int ret = rados->pool_lookup(new_pool.c_str());
+ librados::Rados *rad = get_rados_handle();
+ int ret = rad->pool_lookup(new_pool.c_str());
if (ret < 0) // DNE, or something
return ret;
vector<librados::PoolAsyncCompletion *> completions;
vector<int> rets;
+ librados::Rados *rad = get_rados_handle();
for (iter = names.begin(); iter != names.end(); ++iter) {
librados::PoolAsyncCompletion *c = librados::Rados::pool_async_create_completion();
completions.push_back(c);
string& name = *iter;
- int ret = rados->pool_create_async(name.c_str(), c);
+ int ret = rad->pool_create_async(name.c_str(), c);
rets.push_back(ret);
}
if (r < 0) {
return r;
}
- librados::AioCompletion *completion = rados->aio_create_completion(NULL, NULL, NULL);
+ librados::Rados *rad = get_rados_handle();
+ librados::AioCompletion *completion = rad->aio_create_completion(NULL, NULL, NULL);
r = ref.ioctx.aio_append(ref.oid, completion, bl, size);
completion->release();
librados::IoCtx io_ctx;
const char *usage_log_pool = zone.usage_log_pool.name.c_str();
- int r = rados->ioctx_create(usage_log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(usage_log_pool, io_ctx);
if (r == -ENOENT) {
rgw_bucket pool(usage_log_pool);
r = create_pool(pool);
return r;
// retry
- r = rados->ioctx_create(usage_log_pool, io_ctx);
+ r = rad->ioctx_create(usage_log_pool, io_ctx);
}
if (r < 0)
return r;
*is_truncated = false;
const char *usage_log_pool = zone.usage_log_pool.name.c_str();
- int r = rados->ioctx_create(usage_log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(usage_log_pool, io_ctx);
if (r < 0)
return r;
librados::IoCtx io_ctx;
const char *usage_log_pool = zone.usage_log_pool.name.c_str();
- int r = rados->ioctx_create(usage_log_pool, io_ctx);
+ librados::Rados *rad = get_rados_handle();
+ int r = rad->ioctx_create(usage_log_pool, io_ctx);
if (r < 0)
return r;
int RGWStateLog::open_ioctx(librados::IoCtx& ioctx) {
string pool_name;
store->get_log_pool_name(pool_name);
- int r = store->rados->ioctx_create(pool_name.c_str(), ioctx);
+ int r = store->get_rados_handle()->ioctx_create(pool_name.c_str(), ioctx);
if (r < 0) {
lderr(store->ctx()) << "ERROR: could not open rados pool" << dendl;
return r;
uint64_t RGWRados::instance_id()
{
- return rados->get_instance_id();
+ return get_rados_handle()->get_instance_id();
}
uint64_t RGWRados::next_bucket_id()
delete store;
}
+librados::Rados* RGWRados::get_rados_handle()
+{
+ if (num_rados_handles == 1) {
+ return rados[0];
+ } else {
+ handle_lock.get_read();
+ pthread_t id = pthread_self();
+ std::map<pthread_t, int>:: iterator it = rados_map.find(id);
+
+ if (it != rados_map.end()) {
+ handle_lock.put_read();
+ return rados[it->second];
+ } else {
+ handle_lock.put_read();
+ handle_lock.get_write();
+ if (next_rados_handle.read() == num_rados_handles) {
+ next_rados_handle.set(0);
+ }
+ int handle = next_rados_handle.read();
+ rados_map[id] = handle;
+ next_rados_handle.inc();
+ handle_lock.put_write();
+ return rados[handle];
+ }
+ }
+}
+