Skip to content

Commit

Permalink
Merge branch 'master' into fix_build
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu authored Jan 11, 2024
2 parents cb1f003 + be4f199 commit 1b83952
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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;
Expand Down Expand Up @@ -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<StatusOr<cpp2::VerifyClientVersionResp>> promise;
auto future = promise.getFuture();
Expand Down
6 changes: 4 additions & 2 deletions src/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/graph/service/GraphFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
1 change: 1 addition & 0 deletions src/graph/service/GraphFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/service/GraphService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Status GraphService::init(std::shared_ptr<folly::IOThreadPoolExecutor> ioExecuto
metaClient_ = std::make_unique<meta::MetaClient>(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.";
Expand Down
8 changes: 4 additions & 4 deletions src/meta/test/MetaClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/storage/StorageFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 2 additions & 0 deletions src/storage/StorageFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "common/base/Base.h"

DECLARE_string(handshakeKey);

DECLARE_string(store_type);

DECLARE_int32(waiting_catch_up_retry_times);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/StorageServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ bool StorageServer::start() {
}
#endif

if (!metaClient_->waitForMetadReady()) {
if (!metaClient_->waitForMetadReady(FLAGS_handshakeKey)) {
LOG(ERROR) << "waitForMetadReady error!";
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/db-dump/DbDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Status DbDumper::initMeta() {
meta::MetaClientOptions options;
options.skipConfig_ = true;
metaClient_ = std::make_unique<meta::MetaClient>(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<meta::ServerBasedSchemaManager>();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/db-upgrade/DbUpgraderTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) {
auto metaClient =
std::make_unique<nebula::meta::MetaClient>(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;
}
Expand Down

0 comments on commit 1b83952

Please sign in to comment.