From 29acdad6bfb97f97d284043e9ed3ec1bdf27557a Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Wed, 29 Jun 2016 17:42:41 +0200 Subject: [PATCH] unnecessary double condition --- arangod/Agency/Agent.cpp | 2 +- arangod/Agency/Constituent.cpp | 35 +++++++++++++++++--------------- arangod/Agency/Node.cpp | 2 +- scripts/startStandAloneAgency.sh | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/arangod/Agency/Agent.cpp b/arangod/Agency/Agent.cpp index 1b60cb822d..8f6e45e510 100644 --- a/arangod/Agency/Agent.cpp +++ b/arangod/Agency/Agent.cpp @@ -440,7 +440,7 @@ void Agent::run() { while (!this->isStopping() && size() > 1) { if (leading()) { // Only if leading - _appendCV.wait(20000); + _appendCV.wait(25000); } else { _appendCV.wait(); // Else wait for our moment in the sun } diff --git a/arangod/Agency/Constituent.cpp b/arangod/Agency/Constituent.cpp index 40cd44a025..6b9f132ab2 100644 --- a/arangod/Agency/Constituent.cpp +++ b/arangod/Agency/Constituent.cpp @@ -487,25 +487,23 @@ void Constituent::run() { } } } - + // Always start off as follower while (!this->isStopping() && size() > 1) { + + long t = 0; if (_role == FOLLOWER) { bool cast = false; - + { MUTEX_LOCKER(guard, _castLock); _cast = false; // New round set not cast vote } - - int32_t left = static_cast(1000000.0 * config().minPing), right = static_cast(1000000.0 * config().maxPing); - long rand_wait = static_cast(RandomGenerator::interval(left, right)); - - { - CONDITION_LOCKER(guardv, _cv); - _cv.wait(rand_wait); - } + + int32_t left = static_cast(1000000.0 * config().minPing), + right = static_cast(1000000.0 * config().maxPing); + t = static_cast(RandomGenerator::interval(left, right)); { MUTEX_LOCKER(guard, _castLock); @@ -517,14 +515,19 @@ void Constituent::run() { } } else if (_role == CANDIDATE) { + callElection(); // Run for office + continue; + } else { - int32_t left = 100000.0 * config().minPing; - long rand_wait = static_cast(left); - { - CONDITION_LOCKER(guardv, _cv); - _cv.wait(rand_wait); - } + + t = 100000.0 * config().minPing; + + } + + { + CONDITION_LOCKER(guardv, _cv); + _cv.wait(t); } } diff --git a/arangod/Agency/Node.cpp b/arangod/Agency/Node.cpp index 263276b68f..83a38b4a92 100644 --- a/arangod/Agency/Node.cpp +++ b/arangod/Agency/Node.cpp @@ -97,7 +97,7 @@ Slice Node::slice() const { } // Some value - if (!_value.empty() && !_value.empty()) { + if (!_value.empty()) { return Slice(_value.front().data()); } diff --git a/scripts/startStandAloneAgency.sh b/scripts/startStandAloneAgency.sh index 0572414ce8..c29c4009f5 100755 --- a/scripts/startStandAloneAgency.sh +++ b/scripts/startStandAloneAgency.sh @@ -51,7 +51,7 @@ if [ $NRAGENTS -gt 1 ]; then --agency.compaction-step-size $COMP \ --log.force-direct true \ > agency/$port.stdout 2>&1 & - sleep 0 + sleep 1 done fi for aid in `seq 0 $(( $NRAGENTS - 1 ))`; do