1
0
Fork 0

assuming leadership separated in a preparation part and in a action part

This commit is contained in:
Kaveh Vahedipour 2016-12-19 17:42:07 +01:00
parent f71109a969
commit 27e4b170cf
2 changed files with 21 additions and 14 deletions

View File

@ -864,13 +864,24 @@ void Agent::beginShutdown() {
bool Agent::prepareLead() { bool Agent::prepareLead() {
// Key value stores
rebuildDBs();
// Reset last acknowledged
{
MUTEX_LOCKER(mutexLocker, _ioLock);
for (auto const& i : _config.active()) {
_lastAcked[i] = system_clock::now();
}
}
return true; return true;
} }
/// Becoming leader /// Becoming leader
bool Agent::lead() { bool Agent::lead() {
// Key value stores
rebuildDBs();
// Wake up run // Wake up run
{ {
@ -878,17 +889,12 @@ bool Agent::lead() {
guard.broadcast(); guard.broadcast();
} }
// Agency configuration
term_t myterm; term_t myterm;
// Reset last acknowledged
{ {
MUTEX_LOCKER(mutexLocker, _ioLock); MUTEX_LOCKER(mutexLocker, _ioLock);
for (auto const& i : _config.active()) {
_lastAcked[i] = system_clock::now();
}
myterm = _constituent.term(); myterm = _constituent.term();
} }
// Agency configuration
auto agency = std::make_shared<Builder>(); auto agency = std::make_shared<Builder>();
agency->openArray(); agency->openArray();
agency->openArray(); agency->openArray();

View File

@ -176,6 +176,11 @@ void Constituent::followNoLock(term_t t) {
/// Become leader /// Become leader
void Constituent::lead(term_t term, void Constituent::lead(term_t term,
std::map<std::string, bool> const& votes) { std::map<std::string, bool> const& votes) {
// we need to rebuild spear_head and read_db
_agent->prepareLead();
{ {
MUTEX_LOCKER(guard, _castLock); MUTEX_LOCKER(guard, _castLock);
@ -200,7 +205,7 @@ void Constituent::lead(term_t term,
} }
// give some debug output _id never is changed after // give some debug output _id never is changed after
if (!votes.empty()) { /* if (!votes.empty()) {
std::stringstream ss; std::stringstream ss;
ss << _id << ": Converted to leader in term " << _term << " with votes: "; ss << _id << ": Converted to leader in term " << _term << " with votes: ";
@ -209,11 +214,7 @@ void Constituent::lead(term_t term,
} }
LOG_TOPIC(DEBUG, Logger::AGENCY) << ss.str(); LOG_TOPIC(DEBUG, Logger::AGENCY) << ss.str();
} }*/
// we need to rebuild spear_head and read_db
_agent->prepareLead();
// we need to start work as leader // we need to start work as leader
_agent->lead(); _agent->lead();