]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: make service trim_to stateless
authorSage Weil <sage@inktank.com>
Tue, 9 Jul 2013 04:54:53 +0000 (21:54 -0700)
committerSage Weil <sage@inktank.com>
Tue, 9 Jul 2013 18:09:46 +0000 (11:09 -0700)
Call get_trim_to() when we need to know how much to trim (if any), and
calculate it then.  No need to keep this in a hidden trim_version
variable and remember to update it.  This drops several helpers and
accessors and makes get_trim_to() a single method that services need to
override.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/AuthMonitor.cc
src/mon/AuthMonitor.h
src/mon/LogMonitor.cc
src/mon/LogMonitor.h
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h
src/mon/PGMonitor.cc
src/mon/PGMonitor.h
src/mon/PaxosService.cc
src/mon/PaxosService.h

index e61551b8ba257ef9781383695b9dfd2fa558c4de..8988046954abf7cfdd3a00c00ded1c249154055d 100644 (file)
@@ -279,12 +279,13 @@ void AuthMonitor::encode_full(MonitorDBStore::Transaction *t)
   }
 }
 
-void AuthMonitor::update_trim()
+version_t AuthMonitor::get_trim_to()
 {
   unsigned max = g_conf->paxos_max_join_drift * 2;
   version_t version = get_last_committed();
   if (mon->is_leader() && (version > max))
-    set_trim_to(version - max);
+    return version - max;
+  return 0;
 }
 
 bool AuthMonitor::preprocess_query(PaxosServiceMessage *m)
index 12f7acb4f4bf56f75174aae757069d365cb14027..f538e737856a643f109e87a3bf59577cefddfc32 100644 (file)
@@ -135,7 +135,7 @@ private:
   // propose pending update to peers
   void encode_pending(MonitorDBStore::Transaction *t);
   virtual void encode_full(MonitorDBStore::Transaction *t);
-  void update_trim();
+  version_t get_trim_to();
 
   bool preprocess_query(PaxosServiceMessage *m);  // true if processed.
   bool prepare_update(PaxosServiceMessage *m);
index 065a9bccc7522e28024dbf61e7b004600983736b..cab49060082032787725cb0572aa3a400e5d7953 100644 (file)
@@ -211,12 +211,13 @@ void LogMonitor::encode_full(MonitorDBStore::Transaction *t)
   put_version_latest_full(t, summary.version);
 }
 
-void LogMonitor::update_trim()
+version_t LogMonitor::get_trim_to()
 {
   unsigned max = g_conf->mon_max_log_epochs;
   version_t version = get_last_committed();
   if (mon->is_leader() && version > max)
-    set_trim_to(version - max);
+    return version - max;
+  return 0;
 }
 
 bool LogMonitor::preprocess_query(PaxosServiceMessage *m)
index e20c81e227b4c944463b01ed380db9a48bae084a..439ea4d999b3eb44f0140f6d8961df024bdc142b 100644 (file)
@@ -39,7 +39,7 @@ private:
   // propose pending update to peers
   void encode_pending(MonitorDBStore::Transaction *t);
   virtual void encode_full(MonitorDBStore::Transaction *t);
-  void update_trim();
+  version_t get_trim_to();
   bool preprocess_query(PaxosServiceMessage *m);  // true if processed.
   bool prepare_update(PaxosServiceMessage *m);
 
index 541aac647f3a994cd1d5eb334096fc33fcc5c319..a00dc21eea161a63098e72f4637b6bdd73ebd906 100644 (file)
@@ -533,7 +533,7 @@ void OSDMonitor::share_map_with_random_osd()
   mon->messenger->send_message(m, s->inst);
 }
 
-void OSDMonitor::update_trim()
+version_t OSDMonitor::get_trim_to()
 {
   if (mon->pgmon()->is_readable() &&
       mon->pgmon()->pg_map.creating_pgs.empty()) {
@@ -547,9 +547,9 @@ void OSDMonitor::update_trim()
        floor = 0;
     }
     if (floor > get_first_committed())
-      if (get_trim_to() < floor)
-       set_trim_to(floor);
+      return floor;
   }
+  return 0;
 }
 
 void OSDMonitor::encode_trim_extra(MonitorDBStore::Transaction *tx, version_t first)
@@ -1795,8 +1795,6 @@ void OSDMonitor::tick()
   if (update_pools_status())
     do_propose = true;
 
-  update_trim();
-
   if (do_propose ||
       !pending_inc.new_pg_temp.empty())  // also propose if we adjusted pg_temp
     propose_pending();
index daf2e17dac1253276e279dcb2a922489fd906ff9..3d901a8f1396356857ec588985f1cc769070e054 100644 (file)
@@ -183,7 +183,7 @@ private:
   bool prepare_update(PaxosServiceMessage *m);
   bool should_propose(double &delay);
 
-  void update_trim();
+  version_t get_trim_to();
 
   bool can_mark_down(int o);
   bool can_mark_up(int o);
index ead42a05dcae181c883078069eef2f02e9e2bc04..9455fcec9a1b90ed6ba9e8491f9829b1a3aed12f 100644 (file)
@@ -508,12 +508,13 @@ void PGMonitor::encode_pending(MonitorDBStore::Transaction *t)
   put_last_committed(t, version);
 }
 
-void PGMonitor::update_trim()
+version_t PGMonitor::get_trim_to()
 {
   unsigned max = g_conf->mon_max_pgmap_epochs;
   version_t version = get_last_committed();
   if (mon->is_leader() && (version > max))
-    set_trim_to(version - max);
+    return version - max;
+  return 0;
 }
 
 bool PGMonitor::preprocess_query(PaxosServiceMessage *m)
index c6813eda3b133d174e74b0bf0860bc09c3d4ec75..e9b8f217255b153f293c1b5b01812c7d8c73463d 100644 (file)
@@ -60,7 +60,7 @@ private:
   void handle_osd_timeouts();
   void create_pending();  // prepare a new pending
   // propose pending update to peers
-  void update_trim();
+  version_t get_trim_to();
   void update_logger();
 
   void encode_pending(MonitorDBStore::Transaction *t);
index 44cb64d9adbcc6d0274b68bac1338fb9c4241d5a..2f3bacc36dbf55ececdab1256ae20f9eeecf6951 100644 (file)
@@ -326,12 +326,11 @@ void PaxosService::maybe_trim()
   if (!is_writeable())
     return;
 
-  update_trim();
-  if (get_trim_to() == 0)
+  version_t trim_to = get_trim_to();
+  if (trim_to == 0)
     return;
 
   if (g_conf->paxos_service_trim_min > 0) {
-    version_t trim_to = get_trim_to();
     version_t first = get_first_committed();
     if ((trim_to > 0) &&
        trim_to > first &&
@@ -339,10 +338,10 @@ void PaxosService::maybe_trim()
       return;  // not enough to trim
   }
 
-  dout(10) << __func__ << " trimming" << dendl;
+  dout(10) << __func__ << " trimming to " << trim_to << dendl;
 
   MonitorDBStore::Transaction t;
-  encode_trim(&t, get_trim_to());
+  encode_trim(&t, trim_to);
   bufferlist bl;
   t.encode(bl);
 
@@ -374,9 +373,6 @@ void PaxosService::encode_trim(MonitorDBStore::Transaction *t, version_t trim_to
 
   // let the service add any extra stuff
   encode_trim_extra(t, trim_to_max);
-
-  if (trim_to_max == trim_to)
-    set_trim_to(0);
 }
 
 void PaxosService::trim(MonitorDBStore::Transaction *t,
index 8b11860b3f2b3ff5ec95eebaa792aa9c38e8e003..dc63e4e46b9c9a74c802bc445cf99627171aff0c 100644 (file)
@@ -77,12 +77,6 @@ class PaxosService {
    * then have_pending should be true; otherwise, false.
    */
   bool have_pending; 
-  /**
-   * The version to trim to. If zero, we assume there is no version to be
-   * trimmed; otherwise, we assume we should trim to the version held by
-   * this variable.
-   */
-  version_t trim_version;
 
 protected:
 
@@ -200,7 +194,6 @@ public:
     : mon(mn), paxos(p), service_name(name),
       proposing(false),
       service_version(0), proposal_timer(0), have_pending(false),
-      trim_version(0),
       format_version(0),
       last_committed_name("last_committed"),
       first_committed_name("first_committed"),
@@ -684,31 +677,14 @@ public:
    */
   virtual void encode_trim_extra(MonitorDBStore::Transaction *tx, version_t first) {}
 
-  /**
-   * Update our trim status. We do nothing here, because there is no
-   * straightforward way to update the trim version, since that's service
-   * specific. However, we do not force services to implement it, since there
-   * a couple of services that do not trim anything at all, and we don't want
-   * to shove this function down their throats if they are never going to use
-   * it anyway.
-   */
-  virtual void update_trim() { }
-  /**
-   * Set the trim version variable to @p ver
-   *
-   * @param ver The version to trim to.
-   */
-  void set_trim_to(version_t ver) {
-    trim_version = ver;
-  }
   /**
    * Get the version we should trim to.
    *
    * @returns the version we should trim to; if we return zero, it should be
    *         assumed that there's no version to trim to.
    */
-  version_t get_trim_to() {
-    return trim_version;
+  virtual version_t get_trim_to() {
+    return 0;
   }
   /**
    * @}