From 6896b9cadcbec6e067881399f528b13b421f211c Mon Sep 17 00:00:00 2001 From: nebula-bots <88429921+nebula-bots@users.noreply.github.com> Date: Wed, 9 Mar 2022 19:17:34 +0800 Subject: [PATCH] machine not registed should response leader address (#666) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What type of PR is this? - [ ] bug - [ ] feature - [x] enhancement ## What problem(s) does this PR solve? #### Issue(s) number: #### Description: ## How do you solve it? ## Special notes for your reviewer, ex. impact of this fix, design document, etc: ## Checklist: Tests: - [ ] Unit test(positive and negative cases) - [ ] Function test - [ ] Performance test - [ ] N/A Affects: - [x] Documentation affected (Please add the label if documentation needs to be modified.) - [ ] Incompatibility (If it breaks the compatibility, please describe it and add the label.) - [ ] If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).) - [ ] Performance impacted: Consumes more CPU/Memory ## Release notes: Please confirm whether to be reflected in release notes and how to describe: > ex. Fixed the bug ..... Fix faq, see https://docs.nebula-graph.com.cn/3.0.0/20.appendix/0.FAQ/#nebula_graph_nebula-storaged Migrated from vesoft-inc/nebula#3950 Co-authored-by: yaphet <4414314+darionyaphet@users.noreply.github.com> --- src/clients/meta/MetaClient.cpp | 7 ++++--- src/meta/processors/BaseProcessor.h | 14 ++++---------- src/meta/processors/admin/HBProcessor.cpp | 10 ++++++++++ src/meta/processors/admin/HBProcessor.h | 2 ++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index cf1a8586cc6..0950ce71ef8 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -834,11 +834,12 @@ void MetaClient::getResponse(Request req, } auto&& resp = t.value(); - if (resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED) { + auto code = resp.get_code(); + if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { // succeeded pro.setValue(respGen(std::move(resp))); return; - } else if (resp.get_code() == nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { + } else if (code == nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { updateLeader(resp.get_leader()); if (retry < retryLimit) { evb->runAfterDelay( @@ -861,7 +862,7 @@ void MetaClient::getResponse(Request req, FLAGS_meta_client_retry_interval_secs * 1000); return; } - } else if (resp.get_code() == nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE) { + } else if (code == nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE) { pro.setValue(respGen(std::move(resp))); return; } else if (resp.get_code() == nebula::cpp2::ErrorCode::E_MACHINE_NOT_FOUND) { diff --git a/src/meta/processors/BaseProcessor.h b/src/meta/processors/BaseProcessor.h index 0d29d36c660..038f46b4d57 100644 --- a/src/meta/processors/BaseProcessor.h +++ b/src/meta/processors/BaseProcessor.h @@ -67,26 +67,20 @@ class BaseProcessor { * @brief Set error code and handle leader changed. * * @param code - * @param spaceId - * @param partId */ - void handleErrorCode(nebula::cpp2::ErrorCode code, - GraphSpaceID spaceId = kDefaultSpaceId, - PartitionID partId = kDefaultPartId) { + void handleErrorCode(nebula::cpp2::ErrorCode code) { resp_.code_ref() = code; if (code == nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { - handleLeaderChanged(spaceId, partId); + handleLeaderChanged(); } } /** * @brief Set leader address to reponse. * - * @param spaceId - * @param partId */ - void handleLeaderChanged(GraphSpaceID spaceId, PartitionID partId) { - auto leaderRet = kvstore_->partLeader(spaceId, partId); + void handleLeaderChanged() { + auto leaderRet = kvstore_->partLeader(kDefaultSpaceId, kDefaultPartId); if (ok(leaderRet)) { resp_.leader_ref() = toThriftHost(nebula::value(leaderRet)); } else { diff --git a/src/meta/processors/admin/HBProcessor.cpp b/src/meta/processors/admin/HBProcessor.cpp index 9ca4a2f3c0e..162227ade57 100644 --- a/src/meta/processors/admin/HBProcessor.cpp +++ b/src/meta/processors/admin/HBProcessor.cpp @@ -52,6 +52,7 @@ void HBProcessor::process(const cpp2::HBReq& req) { if (!ActiveHostsMan::machineRegisted(kvstore_, host)) { LOG(INFO) << "Machine " << host << " is not registed"; handleErrorCode(nebula::cpp2::ErrorCode::E_MACHINE_NOT_FOUND); + setLeaderInfo(); onFinished(); return; } @@ -173,5 +174,14 @@ nebula::cpp2::ErrorCode HBProcessor::checkNodeNumber(const cpp2::HostRole role, return nebula::cpp2::ErrorCode::SUCCEEDED; } +void HBProcessor::setLeaderInfo() { + auto leaderRet = kvstore_->partLeader(kDefaultSpaceId, kDefaultPartId); + if (ok(leaderRet)) { + resp_.leader_ref() = toThriftHost(nebula::value(leaderRet)); + } else { + resp_.code_ref() = nebula::error(leaderRet); + } +} + } // namespace meta } // namespace nebula diff --git a/src/meta/processors/admin/HBProcessor.h b/src/meta/processors/admin/HBProcessor.h index 99138092b22..27571482346 100644 --- a/src/meta/processors/admin/HBProcessor.h +++ b/src/meta/processors/admin/HBProcessor.h @@ -60,6 +60,8 @@ class HBProcessor : public BaseProcessor { nebula::cpp2::ErrorCode checkNodeNumber(const cpp2::HostRole role, const HostAddr& host); + void setLeaderInfo(); + ClusterID clusterId_{0}; const HBCounters* counters_{nullptr}; static std::atomic metaVersion_;