mirror of https://gitee.com/bigwinds/arangodb
assuming leadership separated in a preparation part and in a action part
This commit is contained in:
parent
f71109a969
commit
27e4b170cf
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue