diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 6bcb6c21502..38810202016 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -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_ @@ -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; } @@ -2958,7 +2964,9 @@ StatusOr> 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()) {