]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
elector: hoist init into ElectionLogic
authorGreg Farnum <gfarnum@redhat.com>
Thu, 6 Jun 2019 17:34:19 +0000 (10:34 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Mon, 19 Aug 2019 20:04:59 +0000 (13:04 -0700)
Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/mon/Elector.cc
src/mon/Elector.h
src/mon/Monitor.cc

index 85ec8c619eb3d0e10500716916e7de830bcfb085..4997d2fedeeabb5d0526460923c592b7502cd14f 100644 (file)
@@ -38,6 +38,11 @@ void ElectionLogic::persist_epoch(epoch_t e)
   elector->mon->store->apply_transaction(t);
 }
 
+epoch_t ElectionLogic::read_persisted_epoch()
+{
+  return elector->mon->store->get(Monitor::MONITOR_NAME, "election_epoch");
+}
+
 void ElectionLogic::validate_store()
 {
   auto t(std::make_shared<MonitorDBStore::Transaction>());
@@ -67,21 +72,19 @@ int ElectionLogic::elector_my_rank()
 }
 
 
-void Elector::init()
+void ElectionLogic::init()
 {
-  logic.epoch = mon->store->get(Monitor::MONITOR_NAME, "election_epoch");
-  if (!logic.epoch) {
+  epoch = read_persisted_epoch();
+  if (!epoch) {
     dout(1) << "init, first boot, initializing epoch at 1 " << dendl;
-    logic.epoch = 1;
-  } else if (logic.epoch % 2) {
-    dout(1) << "init, last seen epoch " << logic.epoch
+    epoch = 1;
+  } else if (epoch % 2) {
+    dout(1) << "init, last seen epoch " << epoch
            << ", mid-election, bumping" << dendl;
-    ++logic.epoch;
-    auto t(std::make_shared<MonitorDBStore::Transaction>());
-    t->put(Monitor::MONITOR_NAME, "election_epoch", logic.epoch);
-    mon->store->apply_transaction(t);
+    ++epoch;
+    persist_epoch(epoch);
   } else {
-    dout(1) << "init, last seen epoch " << logic.epoch << dendl;
+    dout(1) << "init, last seen epoch " << epoch << dendl;
   }
 }
 
@@ -119,7 +122,7 @@ void Elector::start()
 
   logic.acked_me.clear();
   peer_info.clear();
-  init();
+  logic.init();
   
   // start by trying to elect me
   if (logic.epoch % 2 == 0) {
index 538ba8f642712d84ae9f6e30edb649a17b7845b2..9820576a4f19f0c9a80e9aff01114fdb58dabf46 100644 (file)
@@ -37,7 +37,7 @@ public:
 
   ElectionLogic(Elector *e) : elector(e), epoch(0),
                              electing_me(false), leader_acked(-1) {}
-
+  void init();
   void bump_epoch(epoch_t e);
   void defer(int who);
   void handle_propose_logic(epoch_t mepoch, int from);
@@ -45,6 +45,7 @@ public:
 private:
   // call-outs
   void persist_epoch(epoch_t e);
+  epoch_t read_persisted_epoch();
   void validate_store();
   bool elector_is_current_member(int rank);
   void elector_trigger_new_election();
@@ -373,7 +374,7 @@ private:
    *
    * @post @p epoch is set to 1 or higher.
    */
-  void init();
+  //  void init();
   /**
    * Inform this class it is supposed to shutdown.
    *
index acc4c34f0616dade3ca486e8fc3c35227dbe43aa..6ee95fee85c66b65f31734a45817ff0d7d4e28cf 100644 (file)
@@ -2095,7 +2095,7 @@ void Monitor::win_standalone_election()
 
   // bump election epoch, in case the previous epoch included other
   // monitors; we need to be able to make the distinction.
-  elector.init();
+  elector.logic.init();
   elector.advance_epoch();
 
   rank = monmap->get_rank(name);