From d6df28c401085a5d551d4b21489c296e71d3715c Mon Sep 17 00:00:00 2001 From: Yichen Wang <18348405+Aiee@users.noreply.github.com> Date: Mon, 18 Apr 2022 10:07:06 +0800 Subject: [PATCH] Fix incompatibility imported by https://github.com/vesoft-inc/nebula/pull/4116 (#4165) * Add SaveGraphVersionProcessor to separate client version check and version saving * Update error code * Update error code --- src/clients/meta/MetaClient.cpp | 33 +++++++++++++++++ src/clients/meta/MetaClient.h | 6 ++++ src/interface/meta.thrift | 18 ++++++++-- src/meta/CMakeLists.txt | 1 + src/meta/MetaServiceHandler.cpp | 7 ++++ src/meta/MetaServiceHandler.h | 3 ++ .../admin/SaveGraphVersionProcessor.cpp | 36 +++++++++++++++++++ .../admin/SaveGraphVersionProcessor.h | 27 ++++++++++++++ .../admin/VerifyClientVersionProcessor.cpp | 8 +---- 9 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 src/meta/processors/admin/SaveGraphVersionProcessor.cpp create mode 100644 src/meta/processors/admin/SaveGraphVersionProcessor.h diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index af2c3ef870e..6bcb6c21502 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -129,12 +129,21 @@ bool MetaClient::waitForMetadReady(int count, int retryIntervalSecs) { LOG(ERROR) << "Connect to the MetaServer Failed"; return false; } + + // Verify the graph server version auto status = verifyVersion(); if (!status.ok()) { LOG(ERROR) << status; return false; } + // Save graph version to meta + status = saveVersionToMeta(); + if (!status.ok()) { + LOG(ERROR) << status; + return false; + } + CHECK(bgThread_->start()); LOG(INFO) << "Register time task for heartbeat!"; size_t delayMS = FLAGS_heartbeat_interval_secs * 1000 + folly::Random::rand32(900); @@ -3611,5 +3620,29 @@ Status MetaClient::verifyVersion() { return Status::OK(); } +Status MetaClient::saveVersionToMeta() { + auto req = cpp2::SaveGraphVersionReq(); + req.build_version_ref() = getOriginVersion(); + req.host_ref() = options_.localHost_; + folly::Promise> promise; + auto future = promise.getFuture(); + getResponse( + std::move(req), + [](auto client, auto request) { return client->future_saveGraphVersion(request); }, + [](cpp2::SaveGraphVersionResp&& resp) { return std::move(resp); }, + std::move(promise)); + + auto respStatus = std::move(future).get(); + if (!respStatus.ok()) { + return respStatus.status(); + } + auto resp = std::move(respStatus).value(); + if (resp.get_code() != nebula::cpp2::ErrorCode::SUCCEEDED) { + return Status::Error("Failed to save graph version into meta, error code: %s", + apache::thrift::util::enumNameSafe(resp.get_code()).c_str()); + } + return Status::OK(); +} + } // namespace meta } // namespace nebula diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 7de27e61f7a..15c89620eee 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -733,8 +733,14 @@ class MetaClient : public BaseMetaClient { ListenersMap doGetListenersMap(const HostAddr& host, const LocalCache& localCache); + // Checks if the the client version is compatible with the server version by checking the + // whilelist in meta. Status verifyVersion(); + // Save the version of the graph service into meta so that it could be looked up. + // This method should be only called in the internal client. + Status saveVersionToMeta(); + private: std::shared_ptr ioThreadPool_; std::shared_ptr> clientsMan_; diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift index 08f5f6c40c8..988e560bd33 100644 --- a/src/interface/meta.thrift +++ b/src/interface/meta.thrift @@ -1148,16 +1148,29 @@ struct GetMetaDirInfoReq { struct VerifyClientVersionResp { 1: common.ErrorCode code, 2: common.HostAddr leader, - 3: optional binary error_msg; + 3: optional binary error_msg; } - struct VerifyClientVersionReq { 1: required binary client_version = common.version; 2: common.HostAddr host; 3: binary build_version; } +struct SaveGraphVersionResp { + 1: common.ErrorCode code, + 2: common.HostAddr leader, + 3: optional binary error_msg; +} + +// SaveGraphVersionReq is used to save the graph version of a graph service. +// This is for internal using only. +struct SaveGraphVersionReq { + 1: required binary client_version = common.version; + 2: common.HostAddr host; + 3: binary build_version; +} + service MetaService { ExecResp createSpace(1: CreateSpaceReq req); ExecResp dropSpace(1: DropSpaceReq req); @@ -1263,6 +1276,7 @@ service MetaService { GetMetaDirInfoResp getMetaDirInfo(1: GetMetaDirInfoReq req); VerifyClientVersionResp verifyClientVersion(1: VerifyClientVersionReq req) + SaveGraphVersionResp saveGraphVersion(1: SaveGraphVersionReq req) GetSegmentIdResp getSegmentId(1: GetSegmentIdReq req); } diff --git a/src/meta/CMakeLists.txt b/src/meta/CMakeLists.txt index d805bdbd075..c6f62387815 100644 --- a/src/meta/CMakeLists.txt +++ b/src/meta/CMakeLists.txt @@ -52,6 +52,7 @@ nebula_add_library( processors/admin/ListClusterInfoProcessor.cpp processors/admin/GetMetaDirInfoProcessor.cpp processors/admin/VerifyClientVersionProcessor.cpp + processors/admin/SaveGraphVersionProcessor.cpp processors/config/RegConfigProcessor.cpp processors/config/GetConfigProcessor.cpp processors/config/ListConfigsProcessor.cpp diff --git a/src/meta/MetaServiceHandler.cpp b/src/meta/MetaServiceHandler.cpp index 3be96660b16..59118d8810f 100644 --- a/src/meta/MetaServiceHandler.cpp +++ b/src/meta/MetaServiceHandler.cpp @@ -16,6 +16,7 @@ #include "meta/processors/admin/ListClusterInfoProcessor.h" #include "meta/processors/admin/ListSnapshotsProcessor.h" #include "meta/processors/admin/RestoreProcessor.h" +#include "meta/processors/admin/SaveGraphVersionProcessor.h" #include "meta/processors/admin/VerifyClientVersionProcessor.h" #include "meta/processors/config/GetConfigProcessor.h" #include "meta/processors/config/ListConfigsProcessor.h" @@ -539,6 +540,12 @@ folly::Future MetaServiceHandler::future_verifyCl RETURN_FUTURE(processor); } +folly::Future MetaServiceHandler::future_saveGraphVersion( + const cpp2::SaveGraphVersionReq& req) { + auto* processor = SaveGraphVersionProcessor::instance(kvstore_); + RETURN_FUTURE(processor); +} + folly::Future MetaServiceHandler::future_getWorkerId( const cpp2::GetWorkerIdReq& req) { auto* processor = GetWorkerIdProcessor::instance(kvstore_); diff --git a/src/meta/MetaServiceHandler.h b/src/meta/MetaServiceHandler.h index 8638481f8d9..9a2b4365b64 100644 --- a/src/meta/MetaServiceHandler.h +++ b/src/meta/MetaServiceHandler.h @@ -226,6 +226,9 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf { folly::Future future_verifyClientVersion( const cpp2::VerifyClientVersionReq& req) override; + folly::Future future_saveGraphVersion( + const cpp2::SaveGraphVersionReq& req) override; + folly::Future future_getWorkerId(const cpp2::GetWorkerIdReq& req) override; folly::Future future_getSegmentId( diff --git a/src/meta/processors/admin/SaveGraphVersionProcessor.cpp b/src/meta/processors/admin/SaveGraphVersionProcessor.cpp new file mode 100644 index 00000000000..02df0e41033 --- /dev/null +++ b/src/meta/processors/admin/SaveGraphVersionProcessor.cpp @@ -0,0 +1,36 @@ +/* Copyright (c) 2022 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "meta/processors/admin/SaveGraphVersionProcessor.h" + +#include "common/graph/Response.h" +#include "version/Version.h" + +namespace nebula { +namespace meta { +void SaveGraphVersionProcessor::process(const cpp2::SaveGraphVersionReq& req) { + const auto& host = req.get_host(); + + // Build a map of graph service host and its version + auto versionKey = MetaKeyUtils::versionKey(host); + auto versionVal = MetaKeyUtils::versionVal(req.get_build_version().c_str()); + std::vector versionData; + versionData.emplace_back(std::move(versionKey), std::move(versionVal)); + + // Save the version of the graph service + auto errCode = doSyncPut(versionData); + if (errCode != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << "Failed to save graph version, errorCode: " + << apache::thrift::util::enumNameSafe(errCode); + handleErrorCode(errCode); + onFinished(); + return; + } + handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); + + onFinished(); +} +} // namespace meta +} // namespace nebula diff --git a/src/meta/processors/admin/SaveGraphVersionProcessor.h b/src/meta/processors/admin/SaveGraphVersionProcessor.h new file mode 100644 index 00000000000..5c6bac9a6e2 --- /dev/null +++ b/src/meta/processors/admin/SaveGraphVersionProcessor.h @@ -0,0 +1,27 @@ +/* Copyright (c) 2022 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#ifndef META_SAVEGRAPHVERSIONPROCESSOR_H_ +#define META_SAVEGRAPHVERSIONPROCESSOR_H_ + +#include "meta/processors/BaseProcessor.h" + +namespace nebula { +namespace meta { +class SaveGraphVersionProcessor final : public BaseProcessor { + public: + static SaveGraphVersionProcessor* instance(kvstore::KVStore* kvstore) { + return new SaveGraphVersionProcessor(kvstore); + } + + void process(const cpp2::SaveGraphVersionReq& req); + + private: + explicit SaveGraphVersionProcessor(kvstore::KVStore* kvstore) + : BaseProcessor(kvstore) {} +}; +} // namespace meta +} // namespace nebula +#endif // META_SAVEGRAPHVERSIONPROCESSOR_H_ diff --git a/src/meta/processors/admin/VerifyClientVersionProcessor.cpp b/src/meta/processors/admin/VerifyClientVersionProcessor.cpp index ab400bc4cca..b95f2f2f648 100644 --- a/src/meta/processors/admin/VerifyClientVersionProcessor.cpp +++ b/src/meta/processors/admin/VerifyClientVersionProcessor.cpp @@ -25,14 +25,8 @@ void VerifyClientVersionProcessor::process(const cpp2::VerifyClientVersionReq& r "Meta client version(%s) is not accepted, current meta client white list: %s.", req.get_client_version().c_str(), FLAGS_client_white_list.c_str()); - } else { - const auto& host = req.get_host(); - auto versionKey = MetaKeyUtils::versionKey(host); - auto versionVal = MetaKeyUtils::versionVal(req.get_build_version().c_str()); - std::vector versionData; - versionData.emplace_back(std::move(versionKey), std::move(versionVal)); - handleErrorCode(doSyncPut(versionData)); } + onFinished(); } } // namespace meta