Skip to content

Commit

Permalink
machine not registed should response leader address (vesoft-inc#666)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution!
In order to review PR more efficiently, please add information according to the template.
-->

## 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#3950

Co-authored-by: yaphet <[email protected]>
  • Loading branch information
nebula-bots and darionyaphet authored Mar 9, 2022
1 parent 2e3cdcc commit 6896b9c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down
14 changes: 4 additions & 10 deletions src/meta/processors/BaseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions src/meta/processors/admin/HBProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/meta/processors/admin/HBProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class HBProcessor : public BaseProcessor<cpp2::HBResp> {

nebula::cpp2::ErrorCode checkNodeNumber(const cpp2::HostRole role, const HostAddr& host);

void setLeaderInfo();

ClusterID clusterId_{0};
const HBCounters* counters_{nullptr};
static std::atomic<int64_t> metaVersion_;
Expand Down

0 comments on commit 6896b9c

Please sign in to comment.