From 2fccb300bdf6ffd44db3462eb05115da11322ed4 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Sun, 2 Jun 2013 16:15:02 -0700 Subject: [PATCH] mon/PaxosService: cache {first,last}_committed Refresh the in-memory values when we are told the on-disk paxos state may have changed. Signed-off-by: Joao Eduardo Luis --- src/mon/PaxosService.cc | 5 +++++ src/mon/PaxosService.h | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/mon/PaxosService.cc b/src/mon/PaxosService.cc index 8dc1b42bec5f0..30b3b6e767c60 100644 --- a/src/mon/PaxosService.cc +++ b/src/mon/PaxosService.cc @@ -111,7 +111,12 @@ bool PaxosService::dispatch(PaxosServiceMessage *m) void PaxosService::refresh() { + // update cached versions + cached_first_committed = mon->store->get(get_service_name(), first_committed_name); + cached_last_committed = mon->store->get(get_service_name(), last_committed_name); + dout(10) << __func__ << dendl; + update_from_paxos(); } diff --git a/src/mon/PaxosService.h b/src/mon/PaxosService.h index 31f5ee8961998..ce232e559d3b6 100644 --- a/src/mon/PaxosService.h +++ b/src/mon/PaxosService.h @@ -197,7 +197,8 @@ public: first_committed_name("first_committed"), last_accepted_name("last_accepted"), mkfs_name("mkfs"), - full_version_name("full"), full_latest_name("latest") + full_version_name("full"), full_latest_name("latest"), + cached_first_committed(0), cached_last_committed(0) { } @@ -473,6 +474,22 @@ public: * @} */ + /** + * @defgroup PaxosService_h_version_cache Variables holding cached values + * for the most used versions (first + * and last committed); we only have + * to read them when the store is + * updated, so in-between updates we + * may very well use cached versions + * and avoid the overhead. + * @{ + */ + version_t cached_first_committed; + version_t cached_last_committed; + /** + * @} + */ + /** * Callback list to be used whenever we are running a proposal through * Paxos. These callbacks will be awaken whenever the said proposal @@ -874,13 +891,19 @@ public: * the back store for reading purposes * @{ */ + + /** + * @defgroup PaxosService_h_version_cache Obtain cached versions for this + * service. + * @{ + */ /** * Get the first committed version * * @returns Our first committed version (that is available) */ version_t get_first_committed() { - return mon->store->get(get_service_name(), first_committed_name); + return cached_first_committed; } /** * Get the last committed version @@ -888,7 +911,7 @@ public: * @returns Our last committed version */ version_t get_last_committed() { - return mon->store->get(get_service_name(), last_committed_name); + return cached_last_committed; } /** * Get our current version @@ -898,6 +921,11 @@ public: version_t get_version() { return get_last_committed(); } + + /** + * @} + */ + /** * Get the contents of a given version @p ver * -- 2.39.5