kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ale...@apache.org
Subject kudu git commit: [consensus] do not call EnableFailureDetector twice
Date Mon, 16 Oct 2017 21:51:23 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 3a7342a31 -> 441408908


[consensus] do not call EnableFailureDetector twice

This minor clean-up removes second call to EnableFailureDetector()
upon starting the Raft consensus state machine.

Change-Id: I87dac245b20d85dcda991ea02b51d6ee0fe41822
Reviewed-on: http://gerrit.cloudera.org:8080/8271
Reviewed-by: Adar Dembo <adar@cloudera.com>
Tested-by: Alexey Serbin <aserbin@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/44140890
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/44140890
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/44140890

Branch: refs/heads/master
Commit: 4414089085876b6acfc4025391cd2b96bf833944
Parents: 3a7342a
Author: Alexey Serbin <aserbin@cloudera.com>
Authored: Thu Oct 12 23:38:50 2017 -0700
Committer: Alexey Serbin <aserbin@cloudera.com>
Committed: Mon Oct 16 21:50:29 2017 +0000

----------------------------------------------------------------------
 src/kudu/consensus/raft_consensus.cc | 15 ++++++---------
 src/kudu/consensus/raft_consensus.h  |  9 +++++----
 2 files changed, 11 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/44140890/src/kudu/consensus/raft_consensus.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.cc b/src/kudu/consensus/raft_consensus.cc
index 53268db..50b60bf 100644
--- a/src/kudu/consensus/raft_consensus.cc
+++ b/src/kudu/consensus/raft_consensus.cc
@@ -298,7 +298,7 @@ Status RaftConsensus::Start(const ConsensusBootstrapInfo& info,
 
     // If this is the first term expire the FD immediately so that we have a
     // fast first election, otherwise we just let the timer expire normally.
-    boost::optional<MonoDelta> initial_delta;
+    boost::optional<MonoDelta> fd_initial_delta;
     if (CurrentTermUnlocked() == 0) {
       // The failure detector is initialized to a low value to trigger an early
       // election (unless someone else requested a vote from us first, which
@@ -311,14 +311,13 @@ Status RaftConsensus::Start(const ConsensusBootstrapInfo& info,
       if (PREDICT_TRUE(FLAGS_enable_leader_failure_detection)) {
         LOG_WITH_PREFIX_UNLOCKED(INFO) << "Consensus starting up: Expiring failure
detector timer "
                                           "to make a prompt election more likely";
-        initial_delta = MonoDelta::FromMilliseconds(
+        fd_initial_delta = MonoDelta::FromMilliseconds(
             rng_.Uniform(FLAGS_raft_heartbeat_interval_ms));
       }
     }
-    EnableFailureDetector(initial_delta);
 
     // Now assume "follower" duties.
-    RETURN_NOT_OK(BecomeReplicaUnlocked());
+    RETURN_NOT_OK(BecomeReplicaUnlocked(fd_initial_delta));
 
     SetStateUnlocked(kRunning);
   }
@@ -572,16 +571,15 @@ Status RaftConsensus::BecomeLeaderUnlocked() {
   return AppendNewRoundToQueueUnlocked(round);
 }
 
-Status RaftConsensus::BecomeReplicaUnlocked() {
+Status RaftConsensus::BecomeReplicaUnlocked(boost::optional<MonoDelta> fd_delta) {
   DCHECK(lock_.is_locked());
 
   LOG_WITH_PREFIX_UNLOCKED(INFO) << "Becoming Follower/Learner. State: "
                                  << ToStringUnlocked();
-
   ClearLeaderUnlocked();
 
   // FD should be running while we are a follower.
-  EnableFailureDetector();
+  EnableFailureDetector(std::move(fd_delta));
 
   // Now that we're a replica, we can allow voting for other nodes.
   withhold_votes_until_ = MonoTime::Min();
@@ -1496,8 +1494,7 @@ Status RaftConsensus::RequestVote(const VoteRequestPB* request,
   //
   // See also https://ramcloud.stanford.edu/~ongaro/thesis.pdf
   // section 4.2.3.
-  MonoTime now = MonoTime::Now();
-  if (!request->ignore_live_leader() && now < withhold_votes_until_) {
+  if (!request->ignore_live_leader() && MonoTime::Now() < withhold_votes_until_)
{
     return RequestVoteRespondLeaderIsAlive(request, response);
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/44140890/src/kudu/consensus/raft_consensus.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.h b/src/kudu/consensus/raft_consensus.h
index 080bc7e..5ab93b8 100644
--- a/src/kudu/consensus/raft_consensus.h
+++ b/src/kudu/consensus/raft_consensus.h
@@ -435,9 +435,10 @@ class RaftConsensus : public std::enable_shared_from_this<RaftConsensus>,
   Status BecomeLeaderUnlocked();
 
   // Makes the peer become a replica, i.e. a FOLLOWER or a LEARNER.
+  // See EnableFailureDetector() for description of the 'fd_delta' parameter.
   //
   // 'lock_' must be held for configuration change before calling.
-  Status BecomeReplicaUnlocked();
+  Status BecomeReplicaUnlocked(boost::optional<MonoDelta> fd_delta = boost::none);
 
   // Updates the state in a replica by storing the received operations in the log
   // and triggering the required transactions. This method won't return until all
@@ -550,11 +551,11 @@ class RaftConsensus : public std::enable_shared_from_this<RaftConsensus>,
   // Start tracking the leader for failures. This typically occurs at startup
   // and when the local peer steps down as leader.
   //
-  // If 'delta' is set, it is used as the initial failure period. Otherwise,
-  // the minimum election timeout is used.
+  // If 'delta' is set, it is used as the initial period for leader failure
+  // detection. Otherwise, the minimum election timeout is used.
   //
   // If the failure detector is already registered, has no effect.
-  void EnableFailureDetector(boost::optional<MonoDelta> delta = boost::none);
+  void EnableFailureDetector(boost::optional<MonoDelta> delta);
 
   // Stop tracking the current leader for failures. This typically occurs when
   // the local peer becomes leader.


Mime
View raw message