From 37cc70b1276a863312191bd52ee5f09d4fdc3a91 Mon Sep 17 00:00:00 2001 From: liwenhui-soul <38217397+liwenhui-soul@users.noreply.github.com> Date: Wed, 16 Mar 2022 13:11:04 +0800 Subject: [PATCH] show peers in raft state (#4014) Co-authored-by: Doodle <13706157+critical27@users.noreply.github.com> --- src/interface/raftex.thrift | 1 + src/kvstore/raftex/RaftPart.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/interface/raftex.thrift b/src/interface/raftex.thrift index 27d9405c641..5904c9876a7 100644 --- a/src/interface/raftex.thrift +++ b/src/interface/raftex.thrift @@ -133,6 +133,7 @@ struct GetStateResponse { 6: LogID last_log_id; 7: TermID last_log_term; 8: Status status; + 9: list peers; } service RaftexService { diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index d2eb5ac2e51..c187cb3cf53 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -1067,6 +1067,15 @@ void RaftPart::getState(cpp2::GetStateResponse& resp) { resp.last_log_id_ref() = lastLogId_; resp.last_log_term_ref() = lastLogTerm_; resp.status_ref() = status_; + std::vector peers; + for (auto& h : hosts_) { + std::string str = h->address().toString(); + if (h->isLearner()) { + str += "_learner"; + } + peers.emplace_back(str); + } + resp.peers_ref() = peers; } bool RaftPart::processElectionResponses(const RaftPart::ElectionResponses& results,