Skip to content

Commit

Permalink
curve: fix curve_ops_tool without snapshotserver
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Cyber-SiKu committed Jul 12, 2022
1 parent 2a26863 commit 95f3bcb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions conf/tools.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/tools/curve_tool_define.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/tools/snapshot_clone_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/tools/snapshot_clone_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 20 additions & 5 deletions src/tools/status_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -488,7 +498,8 @@ bool StatusTool::IsClusterHeatlhy() {
}

// 4、检查snapshot clone server状态
if (!CheckServiceHealthy(ServiceName::kSnapshotCloneServer)) {
if (!noSnapshotServer_ &&
!CheckServiceHealthy(ServiceName::kSnapshotCloneServer)) {
ret = false;
}

Expand Down Expand Up @@ -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<std::string> failedList;
int res = versionTool_->GetAndCheckSnapshotCloneVersion(&version,
Expand Down
5 changes: 4 additions & 1 deletion src/tools/status_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/tools/snapshot_clone_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 95f3bcb

Please sign in to comment.