Skip to content

Commit

Permalink
rgw: use vector for librados handles
Browse files Browse the repository at this point in the history
using a vector instead of an array of pointers cleans up our
initialization/shutdown logic

Signed-off-by: Casey Bodley <cbodley@redhat.com>
  • Loading branch information
cbodley committed May 24, 2016
1 parent a41860a commit 0cab969
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 54 deletions.
56 changes: 15 additions & 41 deletions src/rgw/rgw_rados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ int RGWRados::unwatch(uint64_t watch_handle)
ldout(cct, 0) << "ERROR: rados->unwatch2() returned r=" << r << dendl;
return r;
}
r = rados[0]->watch_flush();
r = rados[0].watch_flush();
if (r < 0) {
ldout(cct, 0) << "ERROR: rados->watch_flush() returned r=" << r << dendl;
return r;
Expand Down Expand Up @@ -3199,58 +3199,32 @@ void RGWRados::finalize()
int RGWRados::init_rados()
{
int ret = 0;
auto count = cct->_conf->rgw_num_rados_handles;
auto handles = std::vector<librados::Rados>{count};

num_rados_handles = cct->_conf->rgw_num_rados_handles;

rados = new librados::Rados *[num_rados_handles];
if (!rados) {
ret = -ENOMEM;
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);
for (auto& r : handles) {
ret = r.init_with_context(cct);
if (ret < 0) {
goto fail;
return ret;
}

ret = rados[i]->connect();
ret = r.connect();
if (ret < 0) {
goto fail;
return ret;
}
}

cr_registry = new RGWCoroutinesManagerRegistry(cct);
ret = cr_registry->hook_to_admin_command("cr dump");
if (ret < 0) {
goto fail;
return ret;
}

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];
rados[i] = NULL;
}
}
num_rados_handles = 0;
if (rados) {
delete[] rados;
rados = NULL;
}

num_rados_handles = count;
std::swap(handles, rados);
return ret;
}

Expand Down Expand Up @@ -3993,7 +3967,7 @@ int RGWRados::init_watch()
{
const char *control_pool = get_zone_params().control_pool.name.c_str();

librados::Rados *rad = rados[0];
librados::Rados *rad = &rados[0];
int r = rad->ioctx_create(control_pool, control_pool_ctx);

if (r == -ENOENT) {
Expand Down Expand Up @@ -12110,15 +12084,15 @@ void RGWStoreManager::close_storage(RGWRados *store)
librados::Rados* RGWRados::get_rados_handle()
{
if (num_rados_handles == 1) {
return rados[0];
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];
return &rados[it->second];
} else {
handle_lock.put_read();
handle_lock.get_write();
Expand All @@ -12130,7 +12104,7 @@ librados::Rados* RGWRados::get_rados_handle()
rados_map[id] = handle;
next_rados_handle.inc();
handle_lock.put_write();
return rados[handle];
return &rados[handle];
}
}
}
Expand Down
16 changes: 3 additions & 13 deletions src/rgw/rgw_rados.h
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ class RGWRados
protected:
CephContext *cct;

librados::Rados **rados;
std::vector<librados::Rados> rados;
atomic_t next_rados_handle;
uint32_t num_rados_handles;
RWLock handle_lock;
Expand Down Expand Up @@ -1841,7 +1841,7 @@ class RGWRados
bucket_id_lock("rados_bucket_id"),
bucket_index_max_shards(0),
max_bucket_id(0), cct(NULL),
rados(NULL), next_rados_handle(0),
next_rados_handle(0),
num_rados_handles(0), handle_lock("rados_handle_lock"),
binfo_cache(NULL),
pools_initialized(false),
Expand Down Expand Up @@ -1956,17 +1956,7 @@ class RGWRados

RGWDataChangesLog *data_log;

virtual ~RGWRados() {
for (uint32_t i=0; i < num_rados_handles; i++) {
if (rados[i]) {
rados[i]->shutdown();
delete rados[i];
}
}
if (rados) {
delete[] rados;
}
}
virtual ~RGWRados() = default;

int get_required_alignment(rgw_bucket& bucket, uint64_t *alignment);
int get_max_chunk_size(rgw_bucket& bucket, uint64_t *max_chunk_size);
Expand Down

0 comments on commit 0cab969

Please sign in to comment.