From: John Spray Date: Mon, 20 Oct 2014 15:41:29 +0000 (+0100) Subject: osdc/Objecter: add have_map method X-Git-Tag: v0.91~47^2~14 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3ad6ed3d4e81e9b891fd10343b14bdf766ab1f7b;p=ceph.git osdc/Objecter: add have_map method This is for places we're going to call wait_for_map, so that we can easily check if we will *probably* get a true from wait_for_map, and thereby avoid allocating Contexts we won't need. Signed-off-by: John Spray --- diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 3f60c71975e..8f30157418e 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -1457,6 +1457,27 @@ void Objecter::_wait_for_new_map(Context *c, epoch_t epoch, int err) assert(r == 0); } + +/** + * Use this together with wait_for_map: this is a pre-check to avoid + * allocating a Context for wait_for_map if we can see that we definitely + * already have the epoch. + * + * This does *not* replace the need to handle the return value of wait_for_map: + * just because we don't have it in this pre-check doesn't mean we won't + * have it when calling back into wait_for_map, since the objecter lock + * is dropped in between. + */ +bool Objecter::have_map(const epoch_t epoch) +{ + RWLock::RLocker rl(rwlock); + if (osdmap->get_epoch() >= epoch) { + return true; + } else { + return false; + } +} + bool Objecter::wait_for_map(epoch_t epoch, Context *c, int err) { RWLock::WLocker wl(rwlock); diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 94ca79be7a5..9a0c614c393 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -1808,6 +1808,7 @@ public: int get_client_incarnation() const { return client_inc.read(); } void set_client_incarnation(int inc) { client_inc.set(inc); } + bool have_map(epoch_t epoch); /// wait for epoch; true if we already have it bool wait_for_map(epoch_t epoch, Context *c, int err=0); void _wait_for_new_map(Context *c, epoch_t epoch, int err=0);