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: Make it easier to swap in a role change
Date Wed, 18 Oct 2017 02:14:07 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 57d5a3151 -> aa7d6a97b


consensus: Make it easier to swap in a role change

This patch simply updates some helper functions to make it easier in a
follow-on patch to modify the role of a member in a copied Raft config.

Change-Id: Icca40d5ee0baeb542360b7047cb88102ff0432bd
Reviewed-on: http://gerrit.cloudera.org:8080/8296
Tested-by: Kudu Jenkins
Reviewed-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/aa7d6a97
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/aa7d6a97
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/aa7d6a97

Branch: refs/heads/master
Commit: aa7d6a97bc8561ae4bc96a5c923736cb4676ecfa
Parents: 57d5a31
Author: Mike Percy <mpercy@apache.org>
Authored: Tue Oct 10 13:39:55 2017 -0700
Committer: Alexey Serbin <aserbin@cloudera.com>
Committed: Wed Oct 18 02:12:48 2017 +0000

----------------------------------------------------------------------
 src/kudu/consensus/quorum_util-test.cc           | 14 +++++++-------
 src/kudu/consensus/quorum_util.cc                | 14 +++++++-------
 src/kudu/consensus/quorum_util.h                 |  6 +++---
 src/kudu/consensus/raft_consensus_quorum-test.cc |  4 ++--
 src/kudu/tserver/tablet_copy_client-test.cc      |  6 +++++-
 5 files changed, 24 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/aa7d6a97/src/kudu/consensus/quorum_util-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/quorum_util-test.cc b/src/kudu/consensus/quorum_util-test.cc
index 9982c74..4b2ad0c 100644
--- a/src/kudu/consensus/quorum_util-test.cc
+++ b/src/kudu/consensus/quorum_util-test.cc
@@ -47,20 +47,20 @@ TEST(QuorumUtilTest, TestMemberExtraction) {
   AddPeer(&config, "C", RaftPeerPB::VOTER);
 
   // Basic test for GetRaftConfigMember().
-  RaftPeerPB peer_pb;
-  Status s = GetRaftConfigMember(config, "invalid", &peer_pb);
+  RaftPeerPB* peer_pb;
+  Status s = GetRaftConfigMember(&config, "invalid", &peer_pb);
   ASSERT_TRUE(s.IsNotFound()) << s.ToString();
-  ASSERT_OK(GetRaftConfigMember(config, "A", &peer_pb));
-  ASSERT_EQ("A", peer_pb.permanent_uuid());
+  ASSERT_OK(GetRaftConfigMember(&config, "A", &peer_pb));
+  ASSERT_EQ("A", peer_pb->permanent_uuid());
 
   // Basic test for GetRaftConfigLeader().
   ConsensusStatePB cstate;
   *cstate.mutable_committed_config() = config;
-  s = GetRaftConfigLeader(cstate, &peer_pb);
+  s = GetRaftConfigLeader(&cstate, &peer_pb);
   ASSERT_TRUE(s.IsNotFound()) << s.ToString();
   cstate.set_leader_uuid("B");
-  ASSERT_OK(GetRaftConfigLeader(cstate, &peer_pb));
-  ASSERT_EQ("B", peer_pb.permanent_uuid());
+  ASSERT_OK(GetRaftConfigLeader(&cstate, &peer_pb));
+  ASSERT_EQ("B", peer_pb->permanent_uuid());
 }
 
 TEST(QuorumUtilTest, TestDiffConsensusStates) {

http://git-wip-us.apache.org/repos/asf/kudu/blob/aa7d6a97/src/kudu/consensus/quorum_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/quorum_util.cc b/src/kudu/consensus/quorum_util.cc
index 55c5bb9..f81f2a7 100644
--- a/src/kudu/consensus/quorum_util.cc
+++ b/src/kudu/consensus/quorum_util.cc
@@ -64,23 +64,23 @@ bool IsVoterRole(RaftPeerPB::Role role) {
   return role == RaftPeerPB::LEADER || role == RaftPeerPB::FOLLOWER;
 }
 
-Status GetRaftConfigMember(const RaftConfigPB& config,
+Status GetRaftConfigMember(RaftConfigPB* config,
                            const std::string& uuid,
-                           RaftPeerPB* peer_pb) {
-  for (const RaftPeerPB& peer : config.peers()) {
+                           RaftPeerPB** peer_pb) {
+  for (RaftPeerPB& peer : *config->mutable_peers()) {
     if (peer.permanent_uuid() == uuid) {
-      *peer_pb = peer;
+      *peer_pb = &peer;
       return Status::OK();
     }
   }
   return Status::NotFound(Substitute("Peer with uuid $0 not found in consensus config", uuid));
 }
 
-Status GetRaftConfigLeader(const ConsensusStatePB& cstate, RaftPeerPB* peer_pb) {
-  if (cstate.leader_uuid().empty()) {
+Status GetRaftConfigLeader(ConsensusStatePB* cstate, RaftPeerPB** peer_pb) {
+  if (cstate->leader_uuid().empty()) {
     return Status::NotFound("Consensus config has no leader");
   }
-  return GetRaftConfigMember(cstate.committed_config(), cstate.leader_uuid(), peer_pb);
+  return GetRaftConfigMember(cstate->mutable_committed_config(), cstate->leader_uuid(),
peer_pb);
 }
 
 bool RemoveFromRaftConfig(RaftConfigPB* config, const string& uuid) {

http://git-wip-us.apache.org/repos/asf/kudu/blob/aa7d6a97/src/kudu/consensus/quorum_util.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/quorum_util.h b/src/kudu/consensus/quorum_util.h
index a8d9032..26b6e78 100644
--- a/src/kudu/consensus/quorum_util.h
+++ b/src/kudu/consensus/quorum_util.h
@@ -42,14 +42,14 @@ bool IsVoterRole(RaftPeerPB::Role role);
 // Get the specified member of the config.
 // Returns Status::NotFound if a member with the specified uuid could not be
 // found in the config.
-Status GetRaftConfigMember(const RaftConfigPB& config,
+Status GetRaftConfigMember(RaftConfigPB* config,
                            const std::string& uuid,
-                           RaftPeerPB* peer_pb);
+                           RaftPeerPB** peer_pb);
 
 // Get the leader of the consensus configuration.
 // Returns Status::NotFound() if the leader RaftPeerPB could not be found in
 // the config, or if there is no leader defined.
-Status GetRaftConfigLeader(const ConsensusStatePB& cstate, RaftPeerPB* peer_pb);
+Status GetRaftConfigLeader(ConsensusStatePB* cstate, RaftPeerPB** peer_pb);
 
 // Modifies 'configuration' remove the peer with the specified 'uuid'.
 // Returns false if the server with 'uuid' is not found in the configuration.

http://git-wip-us.apache.org/repos/asf/kudu/blob/aa7d6a97/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 b6efb6b..694fa00 100644
--- a/src/kudu/consensus/raft_consensus_quorum-test.cc
+++ b/src/kudu/consensus/raft_consensus_quorum-test.cc
@@ -186,8 +186,8 @@ class RaftConsensusQuorumTest : public KuduTest {
     for (int i = 0; i < config_.peers_size(); i++) {
       RETURN_NOT_OK(cmeta_managers_[i]->Create(kTestTablet, config_, kMinimumTerm));
 
-      RaftPeerPB local_peer_pb;
-      RETURN_NOT_OK(GetRaftConfigMember(config_, fs_managers_[i]->uuid(), &local_peer_pb));
+      RaftPeerPB* local_peer_pb;
+      RETURN_NOT_OK(GetRaftConfigMember(&config_, fs_managers_[i]->uuid(), &local_peer_pb));
 
       shared_ptr<RaftConsensus> peer;
       RETURN_NOT_OK(RaftConsensus::Create(options_,

http://git-wip-us.apache.org/repos/asf/kudu/blob/aa7d6a97/src/kudu/tserver/tablet_copy_client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_client-test.cc b/src/kudu/tserver/tablet_copy_client-test.cc
index f5be355..5ffabe5 100644
--- a/src/kudu/tserver/tablet_copy_client-test.cc
+++ b/src/kudu/tserver/tablet_copy_client-test.cc
@@ -74,6 +74,7 @@ namespace kudu {
 namespace tserver {
 
 using consensus::ConsensusMetadataManager;
+using consensus::ConsensusStatePB;
 using consensus::GetRaftConfigLeader;
 using consensus::RaftPeerPB;
 using std::tuple;
@@ -105,7 +106,10 @@ class TabletCopyClientTest : public TabletCopyTest {
                                        cmeta_manager,
                                        messenger_,
                                        nullptr /* no metrics */));
-    ASSERT_OK(GetRaftConfigLeader(tablet_replica_->consensus()->ConsensusState(), &leader_));
+    RaftPeerPB* cstate_leader;
+    ConsensusStatePB cstate = tablet_replica_->consensus()->ConsensusState();
+    ASSERT_OK(GetRaftConfigLeader(&cstate, &cstate_leader));
+    leader_ = *cstate_leader;
 
     HostPort host_port;
     ASSERT_OK(HostPortFromPB(leader_.last_known_addr(), &host_port));


Mime
View raw message