From 95f3bcbefc4ea7e9e2ff038b49dfa2619c169391 Mon Sep 17 00:00:00 2001 From: Cyber-SiKu Date: Wed, 6 Jul 2022 18:05:22 +0800 Subject: [PATCH] curve: fix curve_ops_tool without snapshotserver 1. rm the default snapshot server addr 2. If there is no SnapshotServer address, it can be considered that there is no snapshot service 3. add Add noSnapshotServer_ to StatusTool to mark if a SnapshotServer exists Signed-off-by: Cyber-SiKu --- conf/tools.conf | 4 ++-- src/tools/curve_tool_define.cpp | 4 ++-- src/tools/snapshot_clone_client.cpp | 4 ++-- src/tools/snapshot_clone_client.h | 6 +++++- src/tools/status_tool.cpp | 25 ++++++++++++++++++----- src/tools/status_tool.h | 5 ++++- test/tools/snapshot_clone_client_test.cpp | 3 ++- 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/conf/tools.conf b/conf/tools.conf index c6ff8efad0..4ca2e98f09 100644 --- a/conf/tools.conf +++ b/conf/tools.conf @@ -9,8 +9,8 @@ rpcRetryTimes=5 # etcd地址 etcdAddr=127.0.0.1:2379 # snapshot clone server 地址 -snapshotCloneAddr=127.0.0.1:5555 +snapshotCloneAddr= # snapshot clone server dummy port -snapshotCloneDummyPort=8081 +snapshotCloneDummyPort= rootUserName=root rootUserPassword=root_password diff --git a/src/tools/curve_tool_define.cpp b/src/tools/curve_tool_define.cpp index cee0781080..8f4a9b7b90 100644 --- a/src/tools/curve_tool_define.cpp +++ b/src/tools/curve_tool_define.cpp @@ -31,8 +31,8 @@ DEFINE_string(mdsDummyPort, "6667", "dummy port of mds, " DEFINE_string(etcdAddr, "127.0.0.1:2379", "etcd addr"); DEFINE_uint64(rpcTimeout, 3000, "millisecond for rpc timeout"); DEFINE_uint64(rpcRetryTimes, 5, "rpc retry times"); -DEFINE_string(snapshotCloneAddr, "127.0.0.1:5555", "snapshot clone addr"); -DEFINE_string(snapshotCloneDummyPort, "8081", "dummy port of snapshot clone, " +DEFINE_string(snapshotCloneAddr, "", "snapshot clone addr"); +DEFINE_string(snapshotCloneDummyPort, "", "dummy port of snapshot clone, " "can specify one or several. " "if specify several, the order should " "be the same as snapshot clone addr"); diff --git a/src/tools/snapshot_clone_client.cpp b/src/tools/snapshot_clone_client.cpp index 5a3adbd285..02e617cfea 100644 --- a/src/tools/snapshot_clone_client.cpp +++ b/src/tools/snapshot_clone_client.cpp @@ -29,8 +29,8 @@ int SnapshotCloneClient::Init(const std::string& serverAddr, const std::string& dummyPort) { curve::common::SplitString(serverAddr, ",", &serverAddrVec_); if (serverAddrVec_.empty()) { - std::cout << "Split snapshot clone server address fail!" << std::endl; - return -1; + // no snapshot clone server + return 1; } int res = InitDummyServerMap(dummyPort); diff --git a/src/tools/snapshot_clone_client.h b/src/tools/snapshot_clone_client.h index 6286603b6e..295134bd50 100644 --- a/src/tools/snapshot_clone_client.h +++ b/src/tools/snapshot_clone_client.h @@ -46,7 +46,11 @@ class SnapshotCloneClient { * @param dummyPort dummy port列表,只输入一个的话 * 所有server用同样的dummy port,用字符串分隔有多个的话 * 为每个server设置不同的dummy port - * @return 成功返回0,失败返回-1 + * @return + * success: 0 + * failed: -1 + * no snapshot server: 1 + * */ virtual int Init(const std::string& serverAddr, const std::string& dummyPort); diff --git a/src/tools/status_tool.cpp b/src/tools/status_tool.cpp index 70731a9dc2..f0f876acbf 100644 --- a/src/tools/status_tool.cpp +++ b/src/tools/status_tool.cpp @@ -82,10 +82,20 @@ int StatusTool::Init(const std::string& command) { etcdInited_ = true; } if (CommandNeedSnapshotClone(command)) { - if (snapshotClient_->Init(FLAGS_snapshotCloneAddr, - FLAGS_snapshotCloneDummyPort) != 0) { - std::cout << "Init snapshotClient failed!" << std::endl; - return -1; + int snapshotRet = snapshotClient_->Init(FLAGS_snapshotCloneAddr, + FLAGS_snapshotCloneDummyPort); + switch (snapshotRet) { + case 0: + // success + break; + case 1: + // no snapshot clone server + noSnapshotServer_ = true; + break; + default: + // -1 and other + std::cout << "Init snapshotClient failed!" << std::endl; + return -1; } } return 0; @@ -488,7 +498,8 @@ bool StatusTool::IsClusterHeatlhy() { } // 4、检查snapshot clone server状态 - if (!CheckServiceHealthy(ServiceName::kSnapshotCloneServer)) { + if (!noSnapshotServer_ && + !CheckServiceHealthy(ServiceName::kSnapshotCloneServer)) { ret = false; } @@ -631,6 +642,10 @@ int StatusTool::PrintEtcdStatus() { int StatusTool::PrintSnapshotCloneStatus() { std::cout << "SnapshotCloneServer status:" << std::endl; + if (noSnapshotServer_) { + std::cout << "No SnapshotCloneServer" << std::endl; + return 0; + } std::string version; std::vector failedList; int res = versionTool_->GetAndCheckSnapshotCloneVersion(&version, diff --git a/src/tools/status_tool.h b/src/tools/status_tool.h index 292c5abf9a..66629dc483 100644 --- a/src/tools/status_tool.h +++ b/src/tools/status_tool.h @@ -93,7 +93,8 @@ class StatusTool : public CurveTool { versionTool_(versionTool), metricClient_(metricClient), snapshotClient_(snapshotClient), - mdsInited_(false), etcdInited_(false) {} + mdsInited_(false), etcdInited_(false), + noSnapshotServer_(false) {} ~StatusTool() = default; /** @@ -202,6 +203,8 @@ class StatusTool : public CurveTool { bool mdsInited_; // etcd是否初始化过 bool etcdInited_; + // Is there a snapshot service or not + bool noSnapshotServer_; }; } // namespace tool } // namespace curve diff --git a/test/tools/snapshot_clone_client_test.cpp b/test/tools/snapshot_clone_client_test.cpp index de4e1eed87..024a270a69 100644 --- a/test/tools/snapshot_clone_client_test.cpp +++ b/test/tools/snapshot_clone_client_test.cpp @@ -47,7 +47,8 @@ class SnapshotCloneClientTest : public ::testing::Test { TEST_F(SnapshotCloneClientTest, Init) { SnapshotCloneClient client(metricClient_); - ASSERT_EQ(-1, client.Init("", "8081")); + // no snapshot clone server + ASSERT_EQ(1, client.Init("", "")); ASSERT_EQ(-1, client.Init("127.0.0.1:5555", "")); // dummy server与mds不匹配 ASSERT_EQ(-1, client.Init("127.0.0.1:5555", "8081,8082,8083"));