From a56f620d1f43bcc82c44c1b585f798f9c881eed3 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 15 Aug 2019 18:44:24 -0700 Subject: [PATCH] elector: const-ify a bunch of functions Signed-off-by: Greg Farnum --- src/mon/ElectionLogic.h | 17 ++++++++--------- src/mon/Elector.cc | 12 ++++++------ src/mon/Elector.h | 12 ++++++------ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/mon/ElectionLogic.h b/src/mon/ElectionLogic.h index f146d055dd86f..86bb8d391d51d 100644 --- a/src/mon/ElectionLogic.h +++ b/src/mon/ElectionLogic.h @@ -34,7 +34,7 @@ class ElectionOwner { * * @returns The latest epoch passed to persist_epoch() */ - virtual epoch_t read_persisted_epoch() = 0; + virtual epoch_t read_persisted_epoch() const = 0; /** * Validate that the persistent store is working by committing * to it. (There is no interface for retrieving the value; this @@ -58,7 +58,7 @@ class ElectionOwner { /** * Retrieve this Paxos instance's rank. */ - virtual int get_my_rank() = 0; + virtual int get_my_rank() const = 0; /** * Send a PROPOSE message to all our peers. This happens when * we have started a new election (which may mean attempting to @@ -78,12 +78,12 @@ class ElectionOwner { * * @returns true if we have participated, false otherwise */ - virtual bool ever_participated() = 0; + virtual bool ever_participated() const = 0; /** * Ask the ElectionOwner for the size of the Paxos set. This includes * those monitors which may not be in the current quorum! */ - virtual unsigned paxos_size() = 0; + virtual unsigned paxos_size() const = 0; /** * Tell the ElectionOwner we have started a new election. * @@ -107,14 +107,14 @@ class ElectionOwner { * @param quorum The ranks of our peers which deferred to us and * must be told of our victory */ - virtual void message_victory(const set& quorum) = 0; + virtual void message_victory(const std::set& quorum) = 0; /** * Query the ElectionOwner about if a given rank is in the * currently active quorum. * @param rank the Paxos rank whose status we are checking * @returns true if the rank is in our current quorum, false otherwise. */ - virtual bool is_current_member(int rank) = 0; + virtual bool is_current_member(int rank) const = 0; virtual ~ElectionOwner() {} }; @@ -165,7 +165,7 @@ class ElectionLogic { * If we are acked by ElectionOwner::paxos_size() peers, we will declare * victory. */ - set acked_me; + std::set acked_me; ElectionLogic(ElectionOwner *e, CephContext *c) : elector(e), cct(c), leader_acked(-1), @@ -280,8 +280,7 @@ class ElectionLogic { * * @returns Our current epoch number */ - epoch_t get_epoch() { return epoch; } - + epoch_t get_epoch() const { return epoch; } private: /** diff --git a/src/mon/Elector.cc b/src/mon/Elector.cc index 7268197c60503..754e404995527 100644 --- a/src/mon/Elector.cc +++ b/src/mon/Elector.cc @@ -42,7 +42,7 @@ void Elector::persist_epoch(epoch_t e) mon->store->apply_transaction(t); } -epoch_t Elector::read_persisted_epoch() +epoch_t Elector::read_persisted_epoch() const { return mon->store->get(Monitor::MONITOR_NAME, "election_epoch"); } @@ -55,7 +55,7 @@ void Elector::validate_store() ceph_assert(r >= 0); } -bool Elector::is_current_member(int rank) +bool Elector::is_current_member(int rank) const { return mon->quorum.count(rank); } @@ -65,7 +65,7 @@ void Elector::trigger_new_election() mon->start_election(); } -int Elector::get_my_rank() +int Elector::get_my_rank() const { return mon->rank; } @@ -75,12 +75,12 @@ void Elector::reset_election() mon->bootstrap(); } -bool Elector::ever_participated() +bool Elector::ever_participated() const { return mon->has_ever_joined; } -unsigned Elector::paxos_size() +unsigned Elector::paxos_size() const { return (unsigned)mon->monmap->size(); } @@ -165,7 +165,7 @@ void Elector::cancel_timer() } } -void Elector::message_victory(const set& quorum) +void Elector::message_victory(const std::set& quorum) { uint64_t cluster_features = CEPH_FEATURES_ALL; mon_feature_t mon_features = ceph::features::mon::get_supported(); diff --git a/src/mon/Elector.h b/src/mon/Elector.h index b2762dd3bfb10..74294ba2a9644 100644 --- a/src/mon/Elector.h +++ b/src/mon/Elector.h @@ -183,7 +183,7 @@ class Elector : public ElectionOwner { /* Commit the given epoch to our MonStore */ void persist_epoch(epoch_t e); /* Read the epoch out of our MonStore */ - epoch_t read_persisted_epoch(); + epoch_t read_persisted_epoch() const; /* Write a nonsense key "election_writeable_test" to our MonStore */ void validate_store(); /* Reset my tracking. Currently, just call Monitor::join_election() */ @@ -191,15 +191,15 @@ class Elector : public ElectionOwner { /* Call a new election: Invoke Monitor::start_election() */ void trigger_new_election(); /* Retrieve rank from the Monitor */ - int get_my_rank(); + int get_my_rank() const; /* Send MMonElection OP_PROPOSE to every monitor in the map. */ void propose_to_peers(epoch_t e); /* bootstrap() the Monitor */ void reset_election(); /* Retrieve the Monitor::has_ever_joined member */ - bool ever_participated(); + bool ever_participated() const; /* Retrieve monmap->size() */ - unsigned paxos_size(); + unsigned paxos_size() const; /** * Reset the expire_event timer so we can limit the amount of time we * will be electing. Clean up our peer_info. @@ -222,9 +222,9 @@ class Elector : public ElectionOwner { * Our ElectionLogic told us we won an election! Identify the quorum * features, tell our new peons we've won, and invoke Monitor::win_election(). */ - void message_victory(const set& quorum); + void message_victory(const std::set& quorum); /* Check if rank is in mon->quorum */ - bool is_current_member(int rank); + bool is_current_member(int rank) const; /* * @} */