Skip to content

Commit

Permalink
curve_ops_tool: support update chunkserver and server
Browse files Browse the repository at this point in the history
  • Loading branch information
ilixiaocui committed May 31, 2024
1 parent a2f4b1d commit 810c385
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 2 deletions.
25 changes: 25 additions & 0 deletions proto/topology.proto
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,26 @@ message GetCopySetsInClusterResponse {
repeated common.CopysetInfo copysetInfos = 2;
}

message UpdateChunkServerRequest {
required uint32 chunkServerID = 1;
optional string hostIp = 3;
optional string externalIp = 5;
}

message UpdateChunkServerResponse {
required sint32 statusCode = 1;
}

message UpdateServerRequest {
required uint32 serverID = 1;
optional string hostIp = 2;
optional string externalIp = 3;
}

message UpdateChunkServerResponse {
required sint32 statusCode = 1;
}

//TODO(hzsunjianliang): update userPolicy and so on
service TopologyService {
rpc RegistChunkServer(ChunkServerRegistRequest) returns (ChunkServerRegistResponse);
Expand Down Expand Up @@ -548,4 +568,9 @@ service TopologyService {
rpc GetCopySetsInChunkServer(GetCopySetsInChunkServerRequest) returns (GetCopySetsInChunkServerResponse);
rpc GetCopySetsInCluster(GetCopySetsInClusterRequest) returns (GetCopySetsInClusterResponse);
rpc GetClusterInfo(GetClusterInfoRequest) returns (GetClusterInfoResponse);

// ops updateserver\chunkserver
rpc UpdateServer(UpdateServerRequest) returns (UpdateServerResponse);
rpc UpdateChunkServer(UpdateChunkServerRequest) returns (UpdateChunkServerResponse);

}
52 changes: 52 additions & 0 deletions src/mds/topology/topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,58 @@ int TopologyImpl::UpdateChunkServerVersion(const std::string &version,
return ret;
}

int TopologyImpl::UpdateChunkServer(uint32_t chunkserverId,
const std::string &hostIp,
const std::string &externalIP) {
ReadLockGuard rlockChunkServerMap(chunkServerMutex_);
auto it = chunkServerMap_.find(chunkserverId);
if (it != chunkServerMap_.end()) {
WriteLockGuard wlockChunkServer(it->second.GetRWLockRef());
ChunkServer temp = it->second;
temp.SetServerId(chunkserverId);
if (!hostIp.empty() && hostIp != temp.GetHostIp()) {
temp.SetHostIp(hostIp);
}
if (!externalIP.empty() && externalIP != temp.GetExternalHostIp()) {
temp.SetExternalHostIp(externalIP);
}

if (!storage_->UpdateChunkServer(temp)) {
return kTopoErrCodeStorgeFail;
}
it->second = std::move(temp);
it->second.SetDirtyFlag(false);
return kTopoErrCodeSuccess;
} else {
return kTopoErrCodeChunkServerNotFound;
}
}

int TopologyImpl::UpdateServer(uint32_t serverId, const std::string &hostIp,
const std::string &externalIp) {
ReadLockGuard rlockServer(serverMutex_);
auto it = serverMap_.find(serverId);
if (it != serverMap_.end()) {
WriteLockGuard wlockServer(it->second.GetRWLockRef());
Sever temp = it->second;
temp.SetId(serverId);
if (!hostIp.empty() && hostIp != temp.GetInternalHostIp()) {
temp.SetInternalHostIp(hostIp);
}
if (!externalIp.empty() && externalIp != temp.GetExternalHostIp()) {
temp.SetExternalHostIp(externalIp);
}
if (!storage_->UpdateServer(temp)) {
return kTopoErrCodeStorgeFail;
}
it->second = std::move(temp);
it->second.SetDirtyFlag(false);
return kTopoErrCodeSuccess;
} else {
return kTopoErrCodeServerNotFound;
}
}

} // namespace topology
} // namespace mds
} // namespace curve
15 changes: 14 additions & 1 deletion src/mds/topology/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ class Topology {
virtual int UpdateChunkServerStartUpTime(uint64_t time,
ChunkServerIdType id) = 0;

virtual int UpdateChunkServer(uint32_t chunkserverId,
const std::string &hostIp,
const std::string &externalIP) = 0;
virtual int UpdateServer(uint32_t serverId, const std::string &hostIp,
const std::string &externalIp) = 0;

/**
* @brief update copyset info
* @detail
Expand Down Expand Up @@ -660,7 +666,14 @@ class TopologyImpl : public Topology {
int GetBelongPhysicalPoolIdByServerId(ServerIdType serverId,
PoolIdType *physicalPoolIdOut);

private:
int UpdateChunkServer(uint32_t chunkserverId,
const std::string &hostIp,
const std::string &externalIP);

int UpdateServer(uint32_t serverId, const std::string &hostIp,
const std::string &externalIp);

private:
int LoadClusterInfo();

int CleanInvalidLogicalPoolAndCopyset();
Expand Down
18 changes: 18 additions & 0 deletions src/mds/topology/topology_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,24 @@ void TopologyServiceImpl::GetClusterInfo(
}
}

void TopologyServiceImpl::UpdateChunkServer(
google::protobuf::RpcController *cntl_base,
const UpdateChunkServerRequest *request,
UpdateChunkServerResponse *response, google::protobuf::Closure *done) {
brpc::ClosureGuard done_guard(done);

brpc::controller* cntl =
static_cast<brpc::controller*>(cntl_base);

LOG(INFO) << "Received request[log_id=" << cntl->log_id()
<< "] from " << cntl->remote_side()
<< " to " << cntl->local_side()
<< ". [UpdateChunkServerRequest] "
<< request->DebugString();
topology_->UpdateChunkServer(request, response);

}

} // namespace topology
} // namespace mds
} // namespace curve
11 changes: 11 additions & 0 deletions src/mds/topology/topology_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ class TopologyServiceImpl : public TopologyService {
const GetClusterInfoRequest* request,
GetClusterInfoResponse* response,
google::protobuf::Closure* done);

virtual void UpdateChunkServer(
google::protobuf::RpcController* cntl_base,
const UpdateChunkServerRequest* request,
UpdateChunkServerResponse* response,
google::protobuf::Closure* done);
virtual void UpdateServer(
google::protobuf::RpcController* cntl_base,
const UpdateServerRequest* request,
UpdateChunkServerResponse* response,
google::protobuf::Closure* done);

private:
std::shared_ptr<TopologyServiceManager> topology_;
Expand Down
38 changes: 38 additions & 0 deletions src/mds/topology/topology_service_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,44 @@ void TopologyServiceManager::GetClusterInfo(
}
}

void TopologyServiceManager::UpdateChunkServer(
const UpdateChunkServerRequest *request,
UpdateChunkServerResponse *response) {
std::string hostIp, externalIp;
if (request->has_hostip()) {
hostIp = request->hostip();
}

if (request->has_externalip()) {
externalIp = request->externalip();
}

int errorcode = topology_->UpdateChunkServer(request->chunkserverid(), hostIp,
externalIp);
response->set_statuscode(errorcode);
}

void TopologyServiceManager::UpdateServer(const UpdateServerRequest *request,
UpdateServerResponse *response) {
std::string hostIp, externalIp;
if (request->has_hostip()) {
hostIp = request->hostip();
}

if (request->has_externalip()) {
externalIp = request->externalip();
}

if (hostIp.empty() && externalIp.empty()) {
response->set_statuscode(kTopoErrCodeInvalidParam);
return;
}

int errorcode =
topology_->UpdateChunkServer(request->serverid(), hostIp, externalIp);
response->set_statuscode(errorcode);
}

} // namespace topology
} // namespace mds
} // namespace curve
6 changes: 6 additions & 0 deletions src/mds/topology/topology_service_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ class TopologyServiceManager {
ChunkServerIdType id,
const std::vector<CopySetInfo> &copysetInfos);

virtual void UpdateChunkServer(const UpdateChunkServerRequest *request,
UpdateChunkServerResponse *response);

virtual void UpdateServer(const UpdateServerRequest *request,
UpdateServerResponse *response);

private:
/**
* @brief create copyset for logical pool
Expand Down
2 changes: 2 additions & 0 deletions src/tools/curve_tool_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const char kClientStatusCmd[] = "client-status";
const char kClientListCmd[] = "client-list";
const char kSnapshotCloneStatusCmd[] = "snapshot-clone-status";
const char kClusterStatusCmd[] = "cluster-status";
const char kUpdateChunkserverCmd[] = "update-chunkserver";
const char kUpdateServerCmd[] = "update-server";

// NameSpaceTool相关命令
const char kGetCmd[] = "get";
Expand Down
2 changes: 2 additions & 0 deletions src/tools/curve_tool_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ static const char* kHelpStr = "Usage: curve_ops_tool [Command] [OPTIONS...]\n"
"check-copyset : check the health state of one copyset\n"
"check-server : check the health state of the server\n"
"check-operator : check the operators\n"
"update-chunkserver: update chunkserver in&ex ip\n\n"
"update-server: update server in&ex ip\n\n"
"list-may-broken-vol: list all volumes on majority offline copysets\n"
"rapid-leader-schedule: rapid leader schedule in cluster in logicalpool\n\n" //NOLINT
"list-poolsets: list all poolsets in cluster\n\n"
Expand Down
42 changes: 42 additions & 0 deletions src/tools/mds_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,5 +1046,47 @@ int MDSClient::ListPoolset(std::vector<PoolsetInfo>* poolsets) {
return -1;
}

int MDSClient::UpdateChunkServer(uint32_t chunkserverId,
const std::string &internalIp,
const std::string &externalIp) {
curve::mds::topology::UpdateChunkServerRequest request;
curve::mds::topology::UpdateChunkServerResponse response;
curve::mds::topology::TopologyService_Stub stub(&channel_);

auto fp = &curve::mds::topology::TopologyService_Stub::UpdateChunkServer;
if (0 != SendRpcToMds(&request, &response, &stub, fp)) {
std::cout << "UpdateChunkServer fail" << std::endl;
return -1;
}

if (response.statuscode() == curve::mds::topology::kTopoErrCodeSuccess) {
return 0;
}

std::cout << "UpdateChunkServer fail with errCode: " << response.statuscode()
<< std::endl;
return -1;
}

int MDSClient::UpdateServer(uint32_t serverId, const std::string &internalIp,
const std::string &externalIp) {
curve::mds::topology::UpdateServerRequest request;
curve::mds::topology::UpdateServerResponse response;
curve::mds::topology::TopologyService_Stub stub(&channel_);
auto fp = &curve::mds::topology::TopologyService_Stub::UpdateServer;
if (0 != SendRpcToMds(&request, &response, &stub, fp)) {
std::cout << "UpdateServer fail" << std::endl;
return -1;
}

if (response.statuscode() == curve::mds::topology::kTopoErrCodeSuccess) {
return 0;
}

std::cout << "UpdateServer fail with errCode: " << response.statuscode()
<< std::endl;
return -1;
}

} // namespace tool
} // namespace curve
6 changes: 6 additions & 0 deletions src/tools/mds_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ class MDSClient {

int ListPoolset(std::vector<PoolsetInfo>* poolsets);


int UpdateChunkServer(uint32_t chunkserverId, const std::string& internalIp,
const std::string& externalIp);
int UpdateServer(uint32_t serverId, const std::string& internalIp,
const std::string& externalIp);

private:
/**
* @brief 切换mds
Expand Down
41 changes: 40 additions & 1 deletion src/tools/status_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ DEFINE_bool(checkCSAlive, false, "if true, it will check the online state of "
"chunkservers with rpc in chunkserver-list");
DEFINE_bool(listClientInRepo, true, "if true, list-client will list all clients"
" include that in repo");
Define_string(externalIp, "", "external ip");
Define_string(internalIp, "", "internal ip");
DEFINE_uint64(walSegmentSize, 8388608, "wal segment size");
DECLARE_string(mdsAddr);
DECLARE_string(etcdAddr);
DECLARE_string(mdsDummyPort);
DECLARE_bool(detail);
Declare_uint32(chunkserverId);
Declare_uint32(serverId);

const char* kProtocalCurve = "curve";

Expand Down Expand Up @@ -124,7 +128,10 @@ bool StatusTool::SupportCommand(const std::string& command) {
|| command == kSnapshotCloneStatusCmd
|| command == kClusterStatusCmd
|| command == kServerListCmd
|| command == kLogicalPoolList);
|| command == kLogicalPoolList
|| command == kUpdateChunkserverCmd
|| command == kUpdateServerCmd
);
}

void StatusTool::PrintHelp(const std::string& cmd) {
Expand Down Expand Up @@ -154,6 +161,15 @@ void StatusTool::PrintHelp(const std::string& cmd) {
std::cout << " [-listClientInRepo=false]"
<< " [-confPath=/etc/curve/tools.conf]";
}
if (cmd == kUpdateChunkserverCmd) {
std::cout
<< " -chunkserverID=1 [-internalIp=127.0.0.1] [-external=127.0.0.1]"
<< " [-confPath=/etc/curve/tools.conf]";
}
if (cmd == kUpdateServerCmd) {
std::cout << " -serverID=1 [-internalIp=127.0.0.1] [-external=127.0.0.1]"
<< " [-confPath=/etc/curve/tools.conf]";
}
std::cout << std::endl;
}

Expand Down Expand Up @@ -1059,6 +1075,25 @@ int StatusTool::GetSpaceInfo(SpaceInfo* spaceInfo) {
return 0;
}

int StatusTool::UpdateChunkServerCmd() {
int res = mdsClient_->UpdateChunkServer(FLAGS_chunkServerId, FLAGS_internalIp,
FLAGS_externalIp);
if (res != 0) {
std::cout << "UpdateChunkServer fail!" << std::endl;
return -1;
}
return 0;
}
int StatusTool::UpdateServerCmd() {
int res = mdsClient_->UpdateServer(FLAGS_serverId, FLAGS_internalIp,
FLAGS_externalIp);
if (res != 0) {
std::cout << "UpdateServer fail!" << std::endl;
return -1;
}
return 0;
}

int StatusTool::RunCommand(const std::string &cmd) {
if (Init(cmd) != 0) {
std::cout << "Init StatusTool failed" << std::endl;
Expand Down Expand Up @@ -1088,6 +1123,10 @@ int StatusTool::RunCommand(const std::string &cmd) {
return PrintClusterStatus();
} else if (cmd == kClientListCmd) {
return ClientListCmd();
} else if (cmd == kUpdateChunkServerCmd) {
return UpdateChunkServerCmd();
} else if (cmd == kUpdateServerCmd) {
return UpdateServerCmd();
} else {
std::cout << "Command not supported!" << std::endl;
return -1;
Expand Down
2 changes: 2 additions & 0 deletions src/tools/status_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class StatusTool : public CurveTool {
int ServerListCmd();
int LogicalPoolListCmd();
int ChunkServerStatusCmd();
int UpdateChunkServerCmd();
int UpdateServerCmd();
int GetPoolsInCluster(std::vector<PhysicalPoolInfo>* phyPools,
std::vector<LogicalPoolInfo>* lgPools);
int GetSpaceInfo(SpaceInfo* spaceInfo);
Expand Down

0 comments on commit 810c385

Please sign in to comment.