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 ae21698
Show file tree
Hide file tree
Showing 14 changed files with 281 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 = 2;
optional string externalIp = 3;
}

message UpdateChunkServerResponse {
required sint32 statusCode = 1;
}

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

message UpdateServerResponse {
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);

}
50 changes: 50 additions & 0 deletions src/mds/topology/topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,56 @@ 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;

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) {
WriteLockGuard wlockServer(serverMutex_);
auto it = serverMap_.find(serverId);
if (it != serverMap_.end()) {
Server temp = it->second;

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);
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
8 changes: 8 additions & 0 deletions src/mds/topology/topology_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ class Server {
desc_ = desc;
}

void SetInternalHostIp(const std::string &ip) {
internalHostIp_ = ip;
}

void SetExternalHostIp(const std::string &ip) {
externalHostIp_ = ip;
}

std::string GetDesc() const {
return desc_;
}
Expand Down
34 changes: 34 additions & 0 deletions src/mds/topology/topology_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,40 @@ 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);
}

void TopologyServiceImpl::UpdateServer(
google::protobuf::RpcController *cntl_base,
const UpdateServerRequest *request,
UpdateServerResponse *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()
<< ". [UpdateServerRequest] "
<< request->DebugString();
topology_->UpdateServer(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,
UpdateServerResponse* 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
Loading

0 comments on commit ae21698

Please sign in to comment.