Skip to content

Commit

Permalink
elector: const-ify a bunch of functions
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Farnum <gfarnum@redhat.com>
  • Loading branch information
gregsfortytwo committed Aug 19, 2019
1 parent fba2a0d commit a56f620
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
17 changes: 8 additions & 9 deletions src/mon/ElectionLogic.h
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
*
Expand All @@ -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<int>& quorum) = 0;
virtual void message_victory(const std::set<int>& 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() {}
};

Expand Down Expand Up @@ -165,7 +165,7 @@ class ElectionLogic {
* If we are acked by ElectionOwner::paxos_size() peers, we will declare
* victory.
*/
set<int> acked_me;
std::set<int> acked_me;

ElectionLogic(ElectionOwner *e, CephContext *c) : elector(e), cct(c),
leader_acked(-1),
Expand Down Expand Up @@ -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:
/**
Expand Down
12 changes: 6 additions & 6 deletions src/mon/Elector.cc
Expand Up @@ -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");
}
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -165,7 +165,7 @@ void Elector::cancel_timer()
}
}

void Elector::message_victory(const set<int>& quorum)
void Elector::message_victory(const std::set<int>& quorum)
{
uint64_t cluster_features = CEPH_FEATURES_ALL;
mon_feature_t mon_features = ceph::features::mon::get_supported();
Expand Down
12 changes: 6 additions & 6 deletions src/mon/Elector.h
Expand Up @@ -183,23 +183,23 @@ 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() */
void notify_bump_epoch();
/* 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.
Expand All @@ -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<int>& quorum);
void message_victory(const std::set<int>& quorum);
/* Check if rank is in mon->quorum */
bool is_current_member(int rank);
bool is_current_member(int rank) const;
/*
* @}
*/
Expand Down

0 comments on commit a56f620

Please sign in to comment.