This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 0cb2b7c6225b7502101f350a878216cbbaa7acc2 Author: Yingchun Lai <[email protected]> AuthorDate: Fri Dec 10 00:44:05 2021 +0800 [tools] Add the role field for 'kudu remote_replica list' Added the Raft role field into the output of the 'kudu remote_replica list' CLI tool. It's useful when filtering replicas by their Raft role from the output of the CLI tool (e.g. when it's necessary to find LEADER replicas on a tablet server). Change-Id: Ie38d20d129b18f3a170ec5b0db5a2caf7c0d80ef Reviewed-on: http://gerrit.cloudera.org:8080/18077 Tested-by: Kudu Jenkins Reviewed-by: Andrew Wong <[email protected]> Reviewed-by: Alexey Serbin <[email protected]> --- src/kudu/tools/kudu-tool-test.cc | 12 +++++++----- src/kudu/tools/tool_action_remote_replica.cc | 3 +++ src/kudu/tserver/tablet_service.cc | 8 ++++++++ src/kudu/tserver/tserver.proto | 2 ++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc index cb95973..eac8301 100644 --- a/src/kudu/tools/kudu-tool-test.cc +++ b/src/kudu/tools/kudu-tool-test.cc @@ -3395,12 +3395,14 @@ TEST_F(ToolTest, TestRemoteReplicaList) { NO_FATALS(RunActionStdoutString( Substitute("remote_replica list $0", ts_addr), &stdout)); - // Some fields like state or estimated on disk size may vary. Just check a + // Some fields like estimated on disk size may vary. Just check a // few whose values we should know exactly. - ASSERT_STR_CONTAINS(stdout, - Substitute("Tablet id: $0", tablet_status.tablet_id())); - ASSERT_STR_CONTAINS(stdout, - Substitute("Table name: $0", workload.table_name())); + ASSERT_STR_CONTAINS(stdout, Substitute("Tablet id: $0", tablet_status.tablet_id())); + ASSERT_STR_MATCHES(stdout, Substitute("State: (INITIALIZED|BOOTSTRAPPING|RUNNING)")); + // Check all possible roles regardless of the reality. + ASSERT_STR_MATCHES(stdout, + Substitute("Role: (UNKNOWN_ROLE|FOLLOWER|LEADER|LEARNER|NON_PARTICIPANT)")); + ASSERT_STR_CONTAINS(stdout, Substitute("Table name: $0", workload.table_name())); ASSERT_STR_CONTAINS(stdout, "key INT32 NOT NULL"); ASSERT_STR_CONTAINS(stdout, "Last status: No bootstrap required, opened a new log"); ASSERT_STR_CONTAINS(stdout, "Data state: TABLET_DATA_READY"); diff --git a/src/kudu/tools/tool_action_remote_replica.cc b/src/kudu/tools/tool_action_remote_replica.cc index 7e7ba43..91fe78b 100644 --- a/src/kudu/tools/tool_action_remote_replica.cc +++ b/src/kudu/tools/tool_action_remote_replica.cc @@ -318,6 +318,9 @@ Status ListReplicas(const RunnerContext& context) { cout << "Tablet id: " << rs.tablet_id() << endl; cout << "State: " << state << endl; cout << "Last status: " << rs.last_status() << endl; + if (r.has_role()) { + cout << "Role: " << RaftPeerPB::Role_Name(r.role()) << endl; + } cout << "Table name: " << rs.table_name() << endl; cout << "Partition: " << partition_schema.PartitionDebugString(partition, schema) << endl; diff --git a/src/kudu/tserver/tablet_service.cc b/src/kudu/tserver/tablet_service.cc index d031ebe..53c78a1 100644 --- a/src/kudu/tserver/tablet_service.cc +++ b/src/kudu/tserver/tablet_service.cc @@ -54,6 +54,7 @@ #include "kudu/common/wire_protocol.h" #include "kudu/common/wire_protocol.pb.h" #include "kudu/consensus/consensus.pb.h" +#include "kudu/consensus/metadata.pb.h" #include "kudu/consensus/opid.pb.h" #include "kudu/consensus/raft_consensus.h" #include "kudu/consensus/replica_management.pb.h" @@ -84,6 +85,7 @@ #include "kudu/tablet/ops/write_op.h" #include "kudu/tablet/rowset.h" #include "kudu/tablet/tablet.h" +#include "kudu/tablet/tablet.pb.h" #include "kudu/tablet/tablet_metadata.h" #include "kudu/tablet/tablet_metrics.h" #include "kudu/tablet/tablet_replica.h" @@ -206,6 +208,7 @@ using kudu::consensus::LeaderStepDownRequestPB; using kudu::consensus::LeaderStepDownResponsePB; using kudu::consensus::OpId; using kudu::consensus::RaftConsensus; +using kudu::consensus::RaftPeerPB; using kudu::consensus::RunLeaderElectionRequestPB; using kudu::consensus::RunLeaderElectionResponsePB; using kudu::consensus::StartTabletCopyRequestPB; @@ -2244,6 +2247,11 @@ void TabletServiceImpl::ListTablets(const ListTabletsRequestPB* req, for (const scoped_refptr<TabletReplica>& replica : replicas) { StatusAndSchemaPB* status = replica_status->Add(); replica->GetTabletStatusPB(status->mutable_tablet_status()); + if (status->tablet_status().state() == tablet::RUNNING) { + status->set_role(replica->consensus()->role()); + } else { + status->set_role(RaftPeerPB::UNKNOWN_ROLE); + } if (req->need_schema_info()) { CHECK_OK(SchemaToPB(replica->tablet_metadata()->schema(), diff --git a/src/kudu/tserver/tserver.proto b/src/kudu/tserver/tserver.proto index d464988..82616b0 100644 --- a/src/kudu/tserver/tserver.proto +++ b/src/kudu/tserver/tserver.proto @@ -22,6 +22,7 @@ option java_package = "org.apache.kudu.tserver"; import "kudu/common/common.proto"; import "kudu/common/row_operations.proto"; import "kudu/common/wire_protocol.proto"; +import "kudu/consensus/metadata.proto"; import "kudu/security/token.proto"; import "kudu/tablet/tablet.proto"; import "kudu/util/pb_util.proto"; @@ -206,6 +207,7 @@ message ListTabletsResponsePB { optional SchemaPB schema = 2; optional PartitionSchemaPB partition_schema = 3; optional uint32 schema_version = 4; + optional consensus.RaftPeerPB.Role role = 5; } repeated StatusAndSchemaPB status_and_schema = 2;
