diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index df4e3dc91f4..72f5e6b4aa9 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -125,7 +125,9 @@ bool MetaClient::isMetadReady() { return ready_; } -bool MetaClient::waitForMetadReady(int count, int retryIntervalSecs) { +bool MetaClient::waitForMetadReady(const std::string& handshakeKey, + int count, + int retryIntervalSecs) { if (!options_.skipConfig_) { std::string gflagsJsonPath; GflagsManager::getGflagsModule(gflagsModule_); @@ -145,7 +147,7 @@ bool MetaClient::waitForMetadReady(int count, int retryIntervalSecs) { } // Verify the graph server version - auto status = verifyVersion(); + auto status = verifyVersion(handshakeKey); if (!status.ok()) { LOG(ERROR) << status; return false; @@ -3845,10 +3847,12 @@ bool MetaClient::checkIsPlanKilled(SessionID sessionId, ExecutionPlanID planId) return metadata_.load()->killedPlans_.count({sessionId, planId}); } -Status MetaClient::verifyVersion() { +Status MetaClient::verifyVersion(const std::string& handshakeKey) { memory::MemoryCheckOffGuard g; auto req = cpp2::VerifyClientVersionReq(); - req.build_version_ref() = getOriginVersion(); + if (!handshakeKey.empty()) { + req.build_version_ref() = handshakeKey; + } req.host_ref() = options_.localHost_; folly::Promise> promise; auto future = promise.getFuture(); diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 471804df3a8..b443c3105e1 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -248,7 +248,9 @@ class MetaClient : public BaseMetaClient { bool isMetadReady(); - bool waitForMetadReady(int count = -1, int retryIntervalSecs = FLAGS_heartbeat_interval_secs); + bool waitForMetadReady(const std::string& handshakeKey = "", + int count = -1, + int retryIntervalSecs = FLAGS_heartbeat_interval_secs); void notifyStop(); @@ -752,7 +754,7 @@ class MetaClient : public BaseMetaClient { // Checks if the client version is compatible with the server version by checking the // whitelist in meta. - Status verifyVersion(); + Status verifyVersion(const std::string& handshakeKey); // 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. diff --git a/src/graph/service/GraphFlags.cpp b/src/graph/service/GraphFlags.cpp index 534c61cab34..0f79a4ae1a5 100644 --- a/src/graph/service/GraphFlags.cpp +++ b/src/graph/service/GraphFlags.cpp @@ -63,6 +63,10 @@ DEFINE_bool(enable_optimizer, false, "Whether to enable optimizer"); #ifndef BUILD_STANDALONE DEFINE_uint32(ft_request_retry_times, 3, "Retry times if fulltext request failed"); DEFINE_bool(enable_client_white_list, true, "Turn on/off the client white list."); +DEFINE_string( + handshakeKey, + "", + "set handshakeKey for graph, please make the handshakeKey is in meta's client_white_list"); DEFINE_string(client_white_list, nebula::getOriginVersion() + ":3.0.0", "A white list for different client handshakeKey, separate with colon."); diff --git a/src/graph/service/GraphFlags.h b/src/graph/service/GraphFlags.h index 28a361171d4..b80dec7ac0f 100644 --- a/src/graph/service/GraphFlags.h +++ b/src/graph/service/GraphFlags.h @@ -61,6 +61,7 @@ DECLARE_bool(enable_experimental_feature); DECLARE_bool(enable_data_balance); DECLARE_bool(enable_client_white_list); +DECLARE_string(handshakeKey); DECLARE_string(client_white_list); DECLARE_int32(num_rows_to_check_memory); diff --git a/src/graph/service/GraphService.cpp b/src/graph/service/GraphService.cpp index 72fb94045bb..b28d53b5a0f 100644 --- a/src/graph/service/GraphService.cpp +++ b/src/graph/service/GraphService.cpp @@ -43,7 +43,7 @@ Status GraphService::init(std::shared_ptr ioExecuto metaClient_ = std::make_unique(ioExecutor, std::move(addrs.value()), options); // Load data try 3 time - bool loadDataOk = metaClient_->waitForMetadReady(3); + bool loadDataOk = metaClient_->waitForMetadReady(FLAGS_handshakeKey, 3); if (!loadDataOk) { // Resort to retrying in the background LOG(ERROR) << "Failed to wait for meta service ready synchronously."; diff --git a/src/meta/test/MetaClientTest.cpp b/src/meta/test/MetaClientTest.cpp index d8cf7fc606a..0f1d0164658 100644 --- a/src/meta/test/MetaClientTest.cpp +++ b/src/meta/test/MetaClientTest.cpp @@ -1712,23 +1712,23 @@ TEST(MetaClientTest, VerifyClientTest) { FLAGS_enable_client_white_list = true; { FLAGS_client_white_list = nebula::cpp2::common_constants::version(); - auto status = client->verifyVersion(); + auto status = client->verifyVersion(""); EXPECT_TRUE(status.ok()); } { FLAGS_client_white_list = ""; - auto status = client->verifyVersion(); + auto status = client->verifyVersion(""); EXPECT_FALSE(status.ok()); } { FLAGS_client_white_list = "1.0.0:1.2.0:"; - auto status = client->verifyVersion(); + auto status = client->verifyVersion(""); EXPECT_FALSE(status.ok()); } { FLAGS_enable_client_white_list = false; FLAGS_client_white_list = "1.0.0:1.2.0:"; - auto status = client->verifyVersion(); + auto status = client->verifyVersion(""); EXPECT_TRUE(status.ok()); } FLAGS_enable_client_white_list = false; diff --git a/src/storage/StorageFlags.cpp b/src/storage/StorageFlags.cpp index bd100191c9f..220fe313e87 100644 --- a/src/storage/StorageFlags.cpp +++ b/src/storage/StorageFlags.cpp @@ -5,6 +5,11 @@ #include "storage/StorageFlags.h" +DEFINE_string( + handshakeKey, + "", + "set handshakeKey for storage, please make the handshakeKey is in meta's client_white_list"); + DEFINE_string(store_type, "nebula", "Which type of KVStore to be used by the storage daemon." diff --git a/src/storage/StorageFlags.h b/src/storage/StorageFlags.h index 197f9318c5c..01197ab5874 100644 --- a/src/storage/StorageFlags.h +++ b/src/storage/StorageFlags.h @@ -8,6 +8,8 @@ #include "common/base/Base.h" +DECLARE_string(handshakeKey); + DECLARE_string(store_type); DECLARE_int32(waiting_catch_up_retry_times); diff --git a/src/storage/StorageServer.cpp b/src/storage/StorageServer.cpp index 228bf7ef284..45fb5a129ff 100644 --- a/src/storage/StorageServer.cpp +++ b/src/storage/StorageServer.cpp @@ -233,7 +233,7 @@ bool StorageServer::start() { } #endif - if (!metaClient_->waitForMetadReady()) { + if (!metaClient_->waitForMetadReady(FLAGS_handshakeKey)) { LOG(ERROR) << "waitForMetadReady error!"; return false; } diff --git a/src/tools/db-dump/DbDumper.cpp b/src/tools/db-dump/DbDumper.cpp index e7341cf1b44..eb8d496f419 100644 --- a/src/tools/db-dump/DbDumper.cpp +++ b/src/tools/db-dump/DbDumper.cpp @@ -56,7 +56,7 @@ Status DbDumper::initMeta() { meta::MetaClientOptions options; options.skipConfig_ = true; metaClient_ = std::make_unique(ioExecutor, std::move(addrs.value()), options); - if (!metaClient_->waitForMetadReady(1)) { + if (!metaClient_->waitForMetadReady("", 1)) { return Status::Error("Meta is not ready: '%s'.", FLAGS_meta_server.c_str()); } schemaMng_ = std::make_unique(); diff --git a/src/tools/db-upgrade/DbUpgraderTool.cpp b/src/tools/db-upgrade/DbUpgraderTool.cpp index b4e05cd143b..dc4444922bf 100644 --- a/src/tools/db-upgrade/DbUpgraderTool.cpp +++ b/src/tools/db-upgrade/DbUpgraderTool.cpp @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) { auto metaClient = std::make_unique(ioExecutor, std::move(addrs.value()), options); CHECK_NOTNULL(metaClient); - if (!metaClient->waitForMetadReady(1)) { + if (!metaClient->waitForMetadReady("", 1)) { LOG(ERROR) << "Meta is not ready: " << FLAGS_upgrade_meta_server; return EXIT_FAILURE; }