kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpe...@apache.org
Subject [2/3] incubator-kudu git commit: RaftConsensus: Trigger election at startup if single node
Date Thu, 16 Jun 2016 22:39:56 GMT
RaftConsensus: Trigger election at startup if single node

If a tablet's replication factor is 1 then don't wait for the failure
detector to kick in. Simply kick off an election immediately.

Change-Id: Ief51ab20c051db83bea51c146b24a11036d9f953
Reviewed-on: http://gerrit.cloudera.org:8080/3344
Reviewed-by: David Ribeiro Alves <dralves@apache.org>
Tested-by: Mike Percy <mpercy@apache.org>


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

Branch: refs/heads/master
Commit: ee4fc9f6b7b7d81127ec623a630c9221511444f8
Parents: 00562f6
Author: Mike Percy <mpercy@apache.org>
Authored: Wed Jun 8 21:15:39 2016 -0700
Committer: Mike Percy <mpercy@apache.org>
Committed: Thu Jun 16 22:34:27 2016 +0000

----------------------------------------------------------------------
 src/kudu/consensus/raft_consensus.cc            | 20 ++++++++++++++++++++
 src/kudu/consensus/raft_consensus.h             |  4 ++++
 .../integration-tests/raft_consensus-itest.cc   |  7 ++++---
 3 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/ee4fc9f6/src/kudu/consensus/raft_consensus.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.cc b/src/kudu/consensus/raft_consensus.cc
index 710075a..aeaa79a 100644
--- a/src/kudu/consensus/raft_consensus.cc
+++ b/src/kudu/consensus/raft_consensus.cc
@@ -309,6 +309,13 @@ Status RaftConsensus::Start(const ConsensusBootstrapInfo& info) {
     RETURN_NOT_OK(BecomeReplicaUnlocked());
   }
 
+  bool single_voter = false;
+  RETURN_NOT_OK(IsSingleVoterConfig(&single_voter));
+  if (single_voter && FLAGS_enable_leader_failure_detection) {
+    LOG_WITH_PREFIX(INFO) << "Only one voter in the Raft config. Triggering election
immediately";
+    RETURN_NOT_OK(StartElection(NORMAL_ELECTION));
+  }
+
   RETURN_NOT_OK(ExecuteHook(POST_START));
 
   // Report become visible to the Master.
@@ -710,6 +717,19 @@ Status RaftConsensus::StartReplicaTransactionUnlocked(const ReplicateRefPtr&
msg
   return state_->AddPendingOperation(round_ptr);
 }
 
+Status RaftConsensus::IsSingleVoterConfig(bool* single_voter) const {
+  ReplicaState::UniqueLock lock;
+  RETURN_NOT_OK(state_->LockForRead(&lock));
+  const RaftConfigPB& config = state_->GetCommittedConfigUnlocked();
+  const string& uuid = state_->GetPeerUuid();
+  if (CountVoters(config) == 1 && IsRaftConfigVoter(uuid, config)) {
+    *single_voter = true;
+  } else {
+    *single_voter = false;
+  }
+  return Status::OK();
+}
+
 std::string RaftConsensus::LeaderRequest::OpsRangeString() const {
   std::string ret;
   ret.reserve(100);

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/ee4fc9f6/src/kudu/consensus/raft_consensus.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.h b/src/kudu/consensus/raft_consensus.h
index 2864ff3..4bf0fe8 100644
--- a/src/kudu/consensus/raft_consensus.h
+++ b/src/kudu/consensus/raft_consensus.h
@@ -289,6 +289,10 @@ class RaftConsensus : public Consensus,
   // that uses transactions, delegates to StartConsensusOnlyRoundUnlocked().
   Status StartReplicaTransactionUnlocked(const ReplicateRefPtr& msg);
 
+  // Returns OK and sets 'single_voter' if this node is the only voter in the
+  // Raft configuration.
+  Status IsSingleVoterConfig(bool* single_voter) const;
+
   // Return header string for RequestVote log messages. The ReplicaState lock must be held.
   std::string GetRequestVoteLogPrefixUnlocked() const;
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/ee4fc9f6/src/kudu/integration-tests/raft_consensus-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/raft_consensus-itest.cc b/src/kudu/integration-tests/raft_consensus-itest.cc
index 62f8f82..2f21dd1 100644
--- a/src/kudu/integration-tests/raft_consensus-itest.cc
+++ b/src/kudu/integration-tests/raft_consensus-itest.cc
@@ -1075,9 +1075,10 @@ TEST_F(RaftConsensusITest, TestAutomaticLeaderElectionOneReplica) {
   vector<string> ts_flags;
   vector<string> master_flags = { "--catalog_manager_allow_local_consensus=false" };
   BuildAndStart(ts_flags, master_flags);
-
-  TServerDetails* leader;
-  ASSERT_OK(GetLeaderReplicaWithRetries(tablet_id_, &leader));
+  // Ensure that single-node Raft configs elect themselves as leader
+  // immediately upon Consensus startup.
+  ASSERT_OK(GetReplicaStatusAndCheckIfLeader(tablet_servers_[cluster_->tablet_server(0)->uuid()],
+                                             tablet_id_, MonoDelta::FromMilliseconds(500)));
 }
 
 void RaftConsensusITest::StubbornlyWriteSameRowThread(int replica_idx, const AtomicBool*
finish) {


Mime
View raw message