1
0
Fork 0

More logging of _role and _leaderID changes in agency.

This commit is contained in:
Max Neunhoeffer 2016-10-13 15:57:37 +02:00
parent a95164ed8f
commit 03e331f1af
1 changed files with 19 additions and 3 deletions

View File

@ -60,6 +60,7 @@ void Constituent::configure(Agent* agent) {
if (size() == 1) {
_role = LEADER;
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _role to LEADER in term " << _term;
} else {
_id = _agent->config().id();
}
@ -156,6 +157,7 @@ void Constituent::follow(term_t t) {
_term = t;
_role = FOLLOWER;
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _role to FOLLOWER in term " << _term;
}
/// Become leader
@ -168,7 +170,9 @@ void Constituent::lead(std::map<std::string, bool> const& votes) {
}
_role = LEADER;
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _role to LEADER in term " << _term;
_leaderID = _id;
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _leaderID to " << _id;
}
if (!votes.empty()) {
@ -189,10 +193,12 @@ void Constituent::candidate() {
MUTEX_LOCKER(guard, _castLock);
_leaderID = NO_LEADER;
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _leaderID to " << NO_LEADER;
if (_role != CANDIDATE)
LOG_TOPIC(DEBUG, Logger::AGENCY)
<< _id << ": Converted to candidate in term " << _term;
if (_role != CANDIDATE) {
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _role to CANDIDATE in term "
<< _term;
}
_role = CANDIDATE;
}
@ -241,6 +247,8 @@ bool Constituent::vote(term_t term, std::string id, index_t prevLogIndex,
lid = _leaderID;
_cast = true;
if (appendEntries && t <= term) {
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _leaderID to " << id
<< " in term " << _term;
_leaderID = id;
return true;
}
@ -250,6 +258,8 @@ bool Constituent::vote(term_t term, std::string id, index_t prevLogIndex,
{
MUTEX_LOCKER(guard, _castLock);
_votedFor = id; // The guy I voted for I assume leader.
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _leaderID to " << id
<< " in term " << _term;
_leaderID = id;
}
this->term(term);
@ -276,6 +286,8 @@ void Constituent::callElection() {
votes[_id] = true; // vote for myself
_cast = true;
_votedFor = _id;
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _leaderID to " << NO_LEADER
<< " in term " << _term;
_leaderID = NO_LEADER;
this->term(_term + 1); // raise my term
@ -355,6 +367,8 @@ void Constituent::callElection() {
void Constituent::update(std::string const& leaderID, term_t t) {
MUTEX_LOCKER(guard, _castLock);
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _leaderID to " << leaderID
<< " in term " << _term;
_leaderID = leaderID;
_term = t;
}
@ -422,6 +436,8 @@ void Constituent::run() {
if (size() == 1) {
_leaderID = _agent->config().id();
LOG_TOPIC(INFO, Logger::AGENCY) << "Set _leaderID to " << _leaderID
<< " in term " << _term;
} else {
while (!this->isStopping()) {
if (_role == FOLLOWER) {