Skip to content

Commit

Permalink
we need to send notifications when the leader fitness becomes worse s…
Browse files Browse the repository at this point in the history
…o that we repopulate availableCandidates to compare with the new lower fitness
  • Loading branch information
etschannen committed Aug 14, 2018
1 parent 2341e5d commit f52d841
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions fdbclient/CoordinationInterface.h
Expand Up @@ -113,9 +113,11 @@ struct LeaderInfo {
return ((changeID.first() & mask) == (leaderInfo.changeID.first() & mask)) && changeID.second() == leaderInfo.changeID.second();
}

// Change leader only if the candidate has better process class fitness
// Change leader only if
// 1. the candidate has better process class fitness and the candidate is not the leader
// 2. the leader process class fitness becomes worse
bool leaderChangeRequired(LeaderInfo const& candidate) const {
return (changeID.first() & ~mask) > (candidate.changeID.first() & ~mask);
return ((changeID.first() & ~mask) > (candidate.changeID.first() & ~mask) && !equalInternalId(candidate)) || ((changeID.first() & ~mask) < (candidate.changeID.first() & ~mask) && equalInternalId(candidate));
}

template <class Ar>
Expand Down
7 changes: 4 additions & 3 deletions fdbserver/Coordination.actor.cpp
Expand Up @@ -285,15 +285,16 @@ ACTOR Future<Void> leaderRegister(LeaderElectionRegInterface interf, Key key) {
}
}

if (currentNominee.present() && nextNominee.present() && currentNominee.get().equalInternalId(nextNominee.get())) {
currentNominee = nextNominee;
} else if ( !nextNominee.present() || !foundCurrentNominee || currentNominee.get().leaderChangeRequired(nextNominee.get()) ) {
if ( !nextNominee.present() || !foundCurrentNominee || currentNominee.get().leaderChangeRequired(nextNominee.get()) ) {
TraceEvent("NominatingLeader").detail("Nominee", nextNominee.present() ? nextNominee.get().changeID : UID())
.detail("Changed", nextNominee != currentNominee).detail("Key", printable(key));
for(int i=0; i<notify.size(); i++)
notify[i].send( nextNominee );
notify.clear();
currentNominee = nextNominee;
} else if (currentNominee.get().equalInternalId(nextNominee.get())) {
// leader becomes better
currentNominee = nextNominee;
}

if( availableLeaders.size() ) {
Expand Down

0 comments on commit f52d841

Please sign in to comment.