Skip to content

Commit

Permalink
Merge pull request #9295 from cbodley/wip-rgw-rados-vector
Browse files Browse the repository at this point in the history
rgw: use vector for librados handles
  • Loading branch information
mattbenjamin committed Jun 2, 2016
2 parents b55b6fb + 53a7f1a commit aff13e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 66 deletions.
72 changes: 22 additions & 50 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 handles = std::vector<librados::Rados>{cct->_conf->rgw_num_rados_handles};

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");
auto crs = std::unique_ptr<RGWCoroutinesManagerRegistry>{
new RGWCoroutinesManagerRegistry(cct)};
ret = crs->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);
cr_registry = crs.release();

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;
}

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 @@ -12118,28 +12092,26 @@ void RGWStoreManager::close_storage(RGWRados *store)

librados::Rados* RGWRados::get_rados_handle()
{
if (num_rados_handles == 1) {
return rados[0];
if (rados.size() == 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];
return &rados[it->second];
} else {
handle_lock.put_read();
handle_lock.get_write();
uint32_t handle = next_rados_handle.read();
if (handle == num_rados_handles) {
next_rados_handle.set(0);
handle = 0;
}
const uint32_t handle = next_rados_handle;
rados_map[id] = handle;
next_rados_handle.inc();
if (++next_rados_handle == rados.size()) {
next_rados_handle = 0;
}
handle_lock.put_write();
return rados[handle];
return &rados[handle];
}
}
}
Expand Down
21 changes: 5 additions & 16 deletions src/rgw/rgw_rados.h
Original file line number Diff line number Diff line change
Expand Up @@ -1800,9 +1800,8 @@ class RGWRados
protected:
CephContext *cct;

librados::Rados **rados;
atomic_t next_rados_handle;
uint32_t num_rados_handles;
std::vector<librados::Rados> rados;
uint32_t next_rados_handle;
RWLock handle_lock;
std::map<pthread_t, int> rados_map;

Expand Down Expand Up @@ -1841,8 +1840,8 @@ 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),
num_rados_handles(0), handle_lock("rados_handle_lock"),
next_rados_handle(0),
handle_lock("rados_handle_lock"),
binfo_cache(NULL),
pools_initialized(false),
quota_handler(NULL),
Expand Down Expand Up @@ -1956,17 +1955,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 aff13e5

Please sign in to comment.