mirror of
https://github.com/ceph/ceph
synced 2024-12-17 17:05:42 +00:00
librados: use rwlock for lookup pool, cache results
Use rwlock to read cahed results, only use regular lock if results are not cached. Invalidate cache on new osdmap. Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
This commit is contained in:
parent
a84cf15f64
commit
6b7f27c015
@ -74,7 +74,10 @@ librados::RadosClient::RadosClient(CephContext *cct_)
|
||||
messenger(NULL),
|
||||
instance_id(0),
|
||||
objecter(NULL),
|
||||
osdmap_epoch(0),
|
||||
pool_cache_epoch(0),
|
||||
lock("librados::RadosClient::lock"),
|
||||
pool_cache_rwl("librados::RadosClient::pool_cache_rwl"),
|
||||
timer(cct, lock),
|
||||
refcnt(1),
|
||||
log_last_version(0), log_cb(NULL), log_cb_arg(NULL),
|
||||
@ -85,11 +88,35 @@ librados::RadosClient::RadosClient(CephContext *cct_)
|
||||
|
||||
int64_t librados::RadosClient::lookup_pool(const char *name)
|
||||
{
|
||||
Mutex::Locker l(lock);
|
||||
pool_cache_rwl.get_read();
|
||||
if (pool_cache_epoch && pool_cache_epoch == osdmap_epoch) {
|
||||
map<string, int64_t>::iterator iter = pool_cache.find(name);
|
||||
if (iter != pool_cache.end()) {
|
||||
uint64_t val = iter->second;
|
||||
pool_cache_rwl.unlock();
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
pool_cache_rwl.unlock();
|
||||
|
||||
lock.Lock();
|
||||
|
||||
wait_for_osdmap();
|
||||
int64_t ret = osdmap.lookup_pg_pool_name(name);
|
||||
if (ret < 0)
|
||||
pool_cache_rwl.get_write();
|
||||
lock.Unlock();
|
||||
if (ret < 0) {
|
||||
pool_cache_rwl.unlock();
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (pool_cache_epoch != osdmap_epoch) {
|
||||
pool_cache.clear();
|
||||
pool_cache_epoch = osdmap_epoch;
|
||||
}
|
||||
pool_cache[name] = ret;
|
||||
pool_cache_rwl.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -340,6 +367,9 @@ bool librados::RadosClient::_dispatch(Message *m)
|
||||
break;
|
||||
case CEPH_MSG_OSD_MAP:
|
||||
objecter->handle_osd_map(static_cast<MOSDMap*>(m));
|
||||
pool_cache_rwl.get_write();
|
||||
osdmap_epoch = osdmap.get_epoch();
|
||||
pool_cache_rwl.unlock();
|
||||
cond.Signal();
|
||||
break;
|
||||
case MSG_GETPOOLSTATSREPLY:
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "common/Cond.h"
|
||||
#include "common/Mutex.h"
|
||||
#include "common/RWLock.h"
|
||||
#include "common/Timer.h"
|
||||
#include "include/rados/librados.h"
|
||||
#include "include/rados/librados.hpp"
|
||||
@ -62,7 +63,13 @@ private:
|
||||
|
||||
Objecter *objecter;
|
||||
|
||||
map<string, int64_t> pool_cache;
|
||||
|
||||
epoch_t osdmap_epoch;
|
||||
epoch_t pool_cache_epoch;
|
||||
|
||||
Mutex lock;
|
||||
RWLock pool_cache_rwl;
|
||||
Cond cond;
|
||||
SafeTimer timer;
|
||||
int refcnt;
|
||||
|
Loading…
Reference in New Issue
Block a user