]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/PaxosService: cache {first,last}_committed
authorJoao Eduardo Luis <joao.luis@inktank.com>
Sun, 2 Jun 2013 23:15:02 +0000 (16:15 -0700)
committerSage Weil <sage@inktank.com>
Mon, 24 Jun 2013 23:16:40 +0000 (16:16 -0700)
Refresh the in-memory values when we are told the on-disk paxos state
may have changed.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
(cherry picked from commit 2fccb300bdf6ffd44db3462eb05115da11322ed4)

src/mon/PaxosService.cc
src/mon/PaxosService.h

index 4cbdb0fee3c70236a8fd5e393f4cfdd8beca06b4..cf08ec46811584586e92c27a81a9b534fe4b65f2 100644 (file)
@@ -106,7 +106,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();
 }
 
index 158eda7def8f147c004b28965506887bd87d9a4f..9ca926292b742dc3d082aea5bab0077249a1d6a7 100644 (file)
@@ -196,7 +196,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)
   {
     proposing.set(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
    *