Skip to content

Commit

Permalink
get meta version in hb
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Aug 26, 2021
1 parent 950243f commit 8fdff96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ MetaClient::~MetaClient() {

bool MetaClient::isMetadReady() {
auto ret = heartbeat().get();
if (!ret.ok() && ret.status() != Status::LeaderChanged()) {
if (!ret.ok()) {
LOG(ERROR) << "Heartbeat failed, status:" << ret.status();
ready_ = false;
return ready_;
} else if (options_.role_ == cpp2::HostRole::STORAGE &&
metaServerVersion_ != EXPECT_META_VERSION) {
LOG(ERROR) << "Expect meta version is " << EXPECT_META_VERSION << ", but actual is "
<< metaServerVersion_;
return ready_;
}

// ready_ will be set in loadData
bool ldRet = loadData();
bool lcRet = true;
if (!options_.skipConfig_) {
Expand Down Expand Up @@ -2328,7 +2333,8 @@ folly::Future<StatusOr<bool>> MetaClient::heartbeat() {
}
metadLastUpdateTime_ = resp.get_last_update_time_in_ms();
VLOG(1) << "Metad last update time: " << metadLastUpdateTime_;
return true; // resp.code == nebula::cpp2::ErrorCode::SUCCEEDED
metaServerVersion_ = resp.get_meta_version();
return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED;
},
std::move(promise));
return future;
Expand Down
5 changes: 4 additions & 1 deletion src/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "interface/gen-cpp2/meta_types.h"

DECLARE_int32(meta_client_retry_times);
DECLARE_int32(heartbeat_interval_secs);

namespace nebula {
namespace meta {
Expand Down Expand Up @@ -184,7 +185,7 @@ class MetaClient {

bool isMetadReady();

bool waitForMetadReady(int count = -1, int retryIntervalSecs = 2);
bool waitForMetadReady(int count = -1, int retryIntervalSecs = FLAGS_heartbeat_interval_secs);

void stop();

Expand Down Expand Up @@ -690,6 +691,8 @@ class MetaClient {
folly::RWSpinLock leaderIdsLock_;
int64_t localLastUpdateTime_{0};
int64_t metadLastUpdateTime_{0};
int64_t metaServerVersion_{-1};
static constexpr int64_t EXPECT_META_VERSION = 2;

// leadersLock_ is used to protect leadersInfo
folly::RWSpinLock leadersLock_;
Expand Down
1 change: 1 addition & 0 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ struct HBResp {
2: common.HostAddr leader,
3: ClusterID cluster_id,
4: i64 last_update_time_in_ms,
5: i32 meta_version,
}

enum HostRole {
Expand Down

0 comments on commit 8fdff96

Please sign in to comment.