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>());
}
-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;
}
}
logic.acked_me.clear();
peer_info.clear();
- init();
+ logic.init();
// start by trying to elect me
if (logic.epoch % 2 == 0) {
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);
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();
*
* @post @p epoch is set to 1 or higher.
*/
- void init();
+ // void init();
/**
* Inform this class it is supposed to shutdown.
*