Skip to content

Commit

Permalink
skip heartbeat for tool (#4177)
Browse files Browse the repository at this point in the history
Co-authored-by: Sophie <[email protected]>
  • Loading branch information
critical27 and Sophie-Xie committed Apr 20, 2022
1 parent d09f2e4 commit dfea2d3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ void MetaClient::heartBeatThreadFunc() {
bgThread_->addDelayTask(
FLAGS_heartbeat_interval_secs * 1000, &MetaClient::heartBeatThreadFunc, this);
};
auto ret = heartbeat().get();
if (!ret.ok()) {
LOG(ERROR) << "Heartbeat failed, status:" << ret.status();
return;
// UNKNOWN is reserved for tools such as upgrader, in that case the ip/port is not set. We do
// not send heartbeat to meta to avoid writing error host info (e.g. Host("", 0))
if (options_.role_ != cpp2::HostRole::UNKNOWN) {
auto ret = heartbeat().get();
if (!ret.ok()) {
LOG(ERROR) << "Heartbeat failed, status:" << ret.status();
return;
}
}

// if MetaServer has some changes, refresh the localCache_
Expand Down Expand Up @@ -236,7 +240,9 @@ bool MetaClient::loadUsersAndRoles() {
}

bool MetaClient::loadData() {
if (localDataLastUpdateTime_ == metadLastUpdateTime_) {
// UNKNOWN role will skip heartbeat
if (options_.role_ != cpp2::HostRole::UNKNOWN &&
localDataLastUpdateTime_ == metadLastUpdateTime_) {
return true;
}

Expand Down Expand Up @@ -2958,7 +2964,9 @@ StatusOr<std::vector<RemoteListenerInfo>> MetaClient::getListenerHostTypeBySpace
}

bool MetaClient::loadCfg() {
if (options_.skipConfig_ || localCfgLastUpdateTime_ == metadLastUpdateTime_) {
// UNKNOWN role will skip heartbeat
if (options_.skipConfig_ || (options_.role_ != cpp2::HostRole::UNKNOWN &&
localCfgLastUpdateTime_ == metadLastUpdateTime_)) {
return true;
}
if (!configReady_ && !registerCfg()) {
Expand Down

0 comments on commit dfea2d3

Please sign in to comment.