You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2018/05/03 20:18:03 UTC

kudu git commit: KUDU-2214 Update logging to differentiate voting while copying/tombstoned

Repository: kudu
Updated Branches:
  refs/heads/master d19844f33 -> 7767679a6


KUDU-2214 Update logging to differentiate voting while copying/tombstoned

Change-Id: I07007601d0a86d6161065629ba167121a33635d6
Reviewed-on: http://gerrit.cloudera.org:8080/10169
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>
Reviewed-by: Mike Percy <mp...@apache.org>


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

Branch: refs/heads/master
Commit: 7767679a6643743e6db672e68d61b3a0eb70bdca
Parents: d19844f
Author: fwang29 <fw...@cloudera.com>
Authored: Wed May 2 11:40:10 2018 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Thu May 3 20:17:47 2018 +0000

----------------------------------------------------------------------
 src/kudu/consensus/consensus-test-util.h        |  4 ++-
 src/kudu/consensus/raft_consensus.cc            | 15 ++++++---
 src/kudu/consensus/raft_consensus.h             | 12 ++++++-
 .../consensus/raft_consensus_quorum-test.cc     | 33 +++++++++++++++-----
 src/kudu/tserver/tablet_service.cc              |  5 ++-
 5 files changed, 53 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/7767679a/src/kudu/consensus/consensus-test-util.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/consensus-test-util.h b/src/kudu/consensus/consensus-test-util.h
index 36c2354..2d71b5c 100644
--- a/src/kudu/consensus/consensus-test-util.h
+++ b/src/kudu/consensus/consensus-test-util.h
@@ -544,7 +544,9 @@ class LocalTestPeerProxy : public TestPeerProxy {
     Status s = peers_->GetPeerByUuid(peer_uuid_, &peer);
 
     if (s.ok()) {
-      s = peer->RequestVote(&other_peer_req, boost::none, &other_peer_resp);
+      s = peer->RequestVote(&other_peer_req,
+                            TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                            &other_peer_resp);
     }
     if (!s.ok()) {
       LOG(WARNING) << "Could not RequestVote from replica with request: "

http://git-wip-us.apache.org/repos/asf/kudu/blob/7767679a/src/kudu/consensus/raft_consensus.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.cc b/src/kudu/consensus/raft_consensus.cc
index f60714a..c8569ac 100644
--- a/src/kudu/consensus/raft_consensus.cc
+++ b/src/kudu/consensus/raft_consensus.cc
@@ -1501,7 +1501,7 @@ void RaftConsensus::FillConsensusResponseError(ConsensusResponsePB* response,
 }
 
 Status RaftConsensus::RequestVote(const VoteRequestPB* request,
-                                  optional<OpId> tombstone_last_logged_opid,
+                                  TabletVotingState tablet_voting_state,
                                   VoteResponsePB* response) {
   TRACE_EVENT2("consensus", "RaftConsensus::RequestVote",
                "peer", peer_uuid(),
@@ -1551,15 +1551,20 @@ Status RaftConsensus::RequestVote(const VoteRequestPB* request,
       local_last_logged_opid = queue_->GetLastOpIdInLog();
       break;
     default:
-      if (!tombstone_last_logged_opid) {
+      if (!tablet_voting_state.tombstone_last_logged_opid_) {
         return Status::IllegalState("must be running to vote when last-logged opid is not known");
       }
       if (!FLAGS_raft_enable_tombstoned_voting) {
         return Status::IllegalState("must be running to vote when tombstoned voting is disabled");
       }
-      local_last_logged_opid = *tombstone_last_logged_opid;
-      LOG_WITH_PREFIX_UNLOCKED(INFO) << "voting while tombstoned based on last-logged opid "
-                                     << local_last_logged_opid;
+      local_last_logged_opid = *(tablet_voting_state.tombstone_last_logged_opid_);
+      if (tablet_voting_state.data_state_ == tablet::TABLET_DATA_COPYING) {
+        LOG_WITH_PREFIX_UNLOCKED(INFO) << "voting while copying based on last-logged opid "
+                                       << local_last_logged_opid;
+      } else if (tablet_voting_state.data_state_ == tablet::TABLET_DATA_TOMBSTONED) {
+        LOG_WITH_PREFIX_UNLOCKED(INFO) << "voting while tombstoned based on last-logged opid "
+                                       << local_last_logged_opid;
+      }
       break;
   }
   DCHECK(local_last_logged_opid.IsInitialized());

http://git-wip-us.apache.org/repos/asf/kudu/blob/7767679a/src/kudu/consensus/raft_consensus.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.h b/src/kudu/consensus/raft_consensus.h
index 6db6774..a92ebc1 100644
--- a/src/kudu/consensus/raft_consensus.h
+++ b/src/kudu/consensus/raft_consensus.h
@@ -42,6 +42,7 @@
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/port.h"
 #include "kudu/gutil/ref_counted.h"
+#include "kudu/tablet/metadata.pb.h"
 #include "kudu/tserver/tserver.pb.h"
 #include "kudu/util/atomic.h"
 #include "kudu/util/locks.h"
@@ -83,6 +84,15 @@ struct ConsensusOptions {
   std::string tablet_id;
 };
 
+struct TabletVotingState {
+  boost::optional<OpId> tombstone_last_logged_opid_;
+  tablet::TabletDataState data_state_;
+  TabletVotingState(boost::optional<OpId> tombstone_last_logged_opid,
+                    tablet::TabletDataState data_state)
+          : tombstone_last_logged_opid_(std::move(tombstone_last_logged_opid)),
+            data_state_(data_state) {}
+};
+
 typedef int64_t ConsensusTerm;
 typedef StdStatusCallback ConsensusReplicatedCallback;
 
@@ -250,7 +260,7 @@ class RaftConsensus : public std::enable_shared_from_this<RaftConsensus>,
   // in kInitialized and kStopped states, instead of just in the kRunning
   // state.
   Status RequestVote(const VoteRequestPB* request,
-                     boost::optional<OpId> tombstone_last_logged_opid,
+                     TabletVotingState tablet_voting_state,
                      VoteResponsePB* response);
 
   // Implement a ChangeConfig() request.

http://git-wip-us.apache.org/repos/asf/kudu/blob/7767679a/src/kudu/consensus/raft_consensus_quorum-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus_quorum-test.cc b/src/kudu/consensus/raft_consensus_quorum-test.cc
index 4467c09..dc6cdb9 100644
--- a/src/kudu/consensus/raft_consensus_quorum-test.cc
+++ b/src/kudu/consensus/raft_consensus_quorum-test.cc
@@ -63,6 +63,7 @@
 #include "kudu/gutil/stl_util.h"
 #include "kudu/gutil/strings/strcat.h"
 #include "kudu/gutil/strings/substitute.h"
+#include "kudu/tablet/metadata.pb.h"
 #include "kudu/util/async_util.h"
 #include "kudu/util/mem_tracker.h"
 #include "kudu/util/metrics.h"
@@ -1027,7 +1028,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   VoteResponsePB response;
   request.set_candidate_uuid(fs_managers_[0]->uuid());
   request.set_candidate_term(last_op_id.term() + 1);
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_FALSE(response.vote_granted());
   ASSERT_EQ(ConsensusErrorPB::LEADER_IS_ALIVE, response.consensus_error().code());
   ASSERT_EQ(0, flush_count() - flush_count_before)
@@ -1039,7 +1042,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   // This will allow the rest of the requests in the test to go through.
   flush_count_before = flush_count();
   request.set_ignore_live_leader(true);
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_TRUE(response.vote_granted());
   ASSERT_EQ(last_op_id.term() + 1, response.responder_term());
   ASSERT_NO_FATAL_FAILURE(AssertDurableTermAndVote(kPeerIndex, last_op_id.term() + 1,
@@ -1050,7 +1055,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   // Ensure we get same response for same term and same UUID.
   response.Clear();
   flush_count_before = flush_count();
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_TRUE(response.vote_granted());
   ASSERT_EQ(0, flush_count() - flush_count_before)
       << "Confirming a previous vote should not flush";
@@ -1059,7 +1066,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   flush_count_before = flush_count();
   response.Clear();
   request.set_candidate_uuid(fs_managers_[2]->uuid());
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_FALSE(response.vote_granted());
   ASSERT_TRUE(response.has_consensus_error());
   ASSERT_EQ(ConsensusErrorPB::ALREADY_VOTED, response.consensus_error().code());
@@ -1079,7 +1088,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   request.set_candidate_uuid(fs_managers_[0]->uuid());
   request.set_candidate_term(last_op_id.term() + 2);
   response.Clear();
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_TRUE(response.vote_granted());
   ASSERT_EQ(last_op_id.term() + 2, response.responder_term());
   ASSERT_NO_FATAL_FAILURE(AssertDurableTermAndVote(kPeerIndex, last_op_id.term() + 2,
@@ -1093,7 +1104,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   flush_count_before = flush_count();
   request.set_candidate_term(last_op_id.term() + 1);
   response.Clear();
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_FALSE(response.vote_granted());
   ASSERT_TRUE(response.has_consensus_error());
   ASSERT_EQ(ConsensusErrorPB::INVALID_TERM, response.consensus_error().code());
@@ -1109,7 +1122,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   request.set_candidate_term(last_op_id.term() + 3);
   request.set_is_pre_election(true);
   response.Clear();
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_TRUE(response.vote_granted());
   ASSERT_FALSE(response.has_consensus_error());
   ASSERT_EQ(last_op_id.term() + 2, response.responder_term());
@@ -1128,7 +1143,9 @@ TEST_F(RaftConsensusQuorumTest, TestRequestVote) {
   request.set_candidate_term(last_op_id.term() + 3);
   request.mutable_candidate_status()->mutable_last_received()->CopyFrom(MinimumOpId());
   response.Clear();
-  ASSERT_OK(peer->RequestVote(&request, boost::none, &response));
+  ASSERT_OK(peer->RequestVote(&request,
+                              TabletVotingState(boost::none, tablet::TABLET_DATA_READY),
+                              &response));
   ASSERT_FALSE(response.vote_granted());
   ASSERT_TRUE(response.has_consensus_error());
   ASSERT_EQ(ConsensusErrorPB::LAST_OPID_TOO_OLD, response.consensus_error().code());

http://git-wip-us.apache.org/repos/asf/kudu/blob/7767679a/src/kudu/tserver/tablet_service.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_service.cc b/src/kudu/tserver/tablet_service.cc
index 7339dd4..cb4cf12 100644
--- a/src/kudu/tserver/tablet_service.cc
+++ b/src/kudu/tserver/tablet_service.cc
@@ -1013,7 +1013,10 @@ void ConsensusServiceImpl::RequestConsensusVote(const VoteRequestPB* req,
   shared_ptr<RaftConsensus> consensus;
   if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
 
-  Status s = consensus->RequestVote(req, std::move(last_logged_opid), resp);
+  Status s = consensus->RequestVote(req,
+                                    consensus::TabletVotingState(std::move(last_logged_opid),
+                                                                 data_state),
+                                    resp);
   if (PREDICT_FALSE(!s.ok())) {
     SetupErrorAndRespond(resp->mutable_error(), s,
                          TabletServerErrorPB::UNKNOWN_ERROR,