From 47297624ce8958c6ee02b6d348db2e62d251e464 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Tue, 20 Dec 2016 09:24:19 +0100 Subject: [PATCH] Further rearrangement in election loop. --- arangod/Agency/Constituent.cpp | 50 ++++++++++++---------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/arangod/Agency/Constituent.cpp b/arangod/Agency/Constituent.cpp index 3b6e94e325..1d1e8cc1a1 100644 --- a/arangod/Agency/Constituent.cpp +++ b/arangod/Agency/Constituent.cpp @@ -421,12 +421,22 @@ void Constituent::callElection() { // Collect ballots. I vote for myself. size_t yea = 1; - size_t nea = 0; + size_t nay = 0; size_t majority = size() / 2 + 1; - bool leading = false; + // We collect votes, we leave the following loop when one of the following + // conditions is met: + // (1) A majority of nay votes have been received + // (2) A majority of yea votes (including ourselves) have been received + // (3) At least yyy time has passed, in this case we give up without + // a conclusive vote. while (true) { + if (steady_clock::now() >= timeout) { // Timeout. + follow(_term); + break; + } + auto res = ClusterComm::instance()->wait( "", coordinatorTransactionID, 0, "", duration(steady_clock::now()-timeout).count()); @@ -448,44 +458,20 @@ void Constituent::callElection() { // Check result and counts if(slc.get("voteGranted").getBool()) { // majority in favour? if (++yea >= majority) { - //if (!leading) { lead(savedTerm, votes); break; - //leading = true; - //} - } - } else { - if (++nea >= majority) { // No: majority against? - follow(_term); - break; } + // Vote is counted as yea, continue loop + continue; } - - } else { - if (++nea >= majority) { // Invalid: majority against? - follow(_term); - break; - } - } - } else { - if (++nea >= majority) { // Network: majority against? - follow(_term); - break; } } - - if (steady_clock::now() >= timeout) { // Timeout. - if (yea >= majority) { - if (!leading) { - lead(savedTerm, votes); - leading = true; - } - } else { - follow(_term); - } + // Count the vote as a nay + if (++nay >= majority) { // Network: majority against? + follow(_term); break; } - + } // Clean up