Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine not registed should response leader address #3950

Merged
merged 2 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,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 @@ -765,7 +766,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 @@ -39,6 +39,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();
darionyaphet marked this conversation as resolved.
Show resolved Hide resolved
onFinished();
return;
}
Expand Down Expand Up @@ -114,5 +115,14 @@ void HBProcessor::process(const cpp2::HBReq& req) {
onFinished();
}

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);
darionyaphet marked this conversation as resolved.
Show resolved Hide resolved
}
}

} // 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 @@ -58,6 +58,8 @@ class HBProcessor : public BaseProcessor<cpp2::HBResp> {
HBProcessor(kvstore::KVStore* kvstore, const HBCounters* counters, ClusterID clusterId)
: BaseProcessor<cpp2::HBResp>(kvstore), clusterId_(clusterId), counters_(counters) {}

void setLeaderInfo();

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