diff --git a/proto/topology.proto b/proto/topology.proto index 6476da32f0..c438f146bd 100644 --- a/proto/topology.proto +++ b/proto/topology.proto @@ -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); @@ -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); + } diff --git a/src/mds/topology/topology.cpp b/src/mds/topology/topology.cpp index b46a4b64f0..e380a54562 100644 --- a/src/mds/topology/topology.cpp +++ b/src/mds/topology/topology.cpp @@ -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 diff --git a/src/mds/topology/topology.h b/src/mds/topology/topology.h index 25f9e72f4e..5ea2888672 100644 --- a/src/mds/topology/topology.h +++ b/src/mds/topology/topology.h @@ -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 @@ -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(); diff --git a/src/mds/topology/topology_item.h b/src/mds/topology/topology_item.h index 31d620b7c1..805f9651b4 100644 --- a/src/mds/topology/topology_item.h +++ b/src/mds/topology/topology_item.h @@ -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_; } diff --git a/src/mds/topology/topology_service.cpp b/src/mds/topology/topology_service.cpp index fa114c8755..2eeab166a7 100644 --- a/src/mds/topology/topology_service.cpp +++ b/src/mds/topology/topology_service.cpp @@ -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(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(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 diff --git a/src/mds/topology/topology_service.h b/src/mds/topology/topology_service.h index b1e6a154eb..d8d73df11a 100644 --- a/src/mds/topology/topology_service.h +++ b/src/mds/topology/topology_service.h @@ -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 topology_; diff --git a/src/mds/topology/topology_service_manager.cpp b/src/mds/topology/topology_service_manager.cpp index 3fa0dd3fa1..e87229b089 100644 --- a/src/mds/topology/topology_service_manager.cpp +++ b/src/mds/topology/topology_service_manager.cpp @@ -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 diff --git a/src/mds/topology/topology_service_manager.h b/src/mds/topology/topology_service_manager.h index 8c47cef1e7..237d1737d9 100644 --- a/src/mds/topology/topology_service_manager.h +++ b/src/mds/topology/topology_service_manager.h @@ -183,6 +183,12 @@ class TopologyServiceManager { ChunkServerIdType id, const std::vector ©setInfos); + virtual void UpdateChunkServer(const UpdateChunkServerRequest *request, + UpdateChunkServerResponse *response); + + virtual void UpdateServer(const UpdateServerRequest *request, + UpdateServerResponse *response); + private: /** * @brief create copyset for logical pool diff --git a/src/tools/curve_tool_define.h b/src/tools/curve_tool_define.h index 2a5ace15d0..3e1b47a554 100644 --- a/src/tools/curve_tool_define.h +++ b/src/tools/curve_tool_define.h @@ -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"; diff --git a/src/tools/curve_tool_main.cpp b/src/tools/curve_tool_main.cpp index 86c45d13c8..96facee457 100644 --- a/src/tools/curve_tool_main.cpp +++ b/src/tools/curve_tool_main.cpp @@ -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" diff --git a/src/tools/mds_client.cpp b/src/tools/mds_client.cpp index 69ed731a58..21d014eb9a 100644 --- a/src/tools/mds_client.cpp +++ b/src/tools/mds_client.cpp @@ -1046,5 +1046,47 @@ int MDSClient::ListPoolset(std::vector* 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 diff --git a/src/tools/mds_client.h b/src/tools/mds_client.h index 31bf058e22..89e3f961d3 100644 --- a/src/tools/mds_client.h +++ b/src/tools/mds_client.h @@ -440,6 +440,12 @@ class MDSClient { int ListPoolset(std::vector* 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 diff --git a/src/tools/status_tool.cpp b/src/tools/status_tool.cpp index b0b31d6870..1d506fd397 100644 --- a/src/tools/status_tool.cpp +++ b/src/tools/status_tool.cpp @@ -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"; @@ -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) { @@ -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; } @@ -1059,6 +1075,26 @@ 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; @@ -1088,6 +1124,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; diff --git a/src/tools/status_tool.h b/src/tools/status_tool.h index 44a20af89c..701fa345d3 100644 --- a/src/tools/status_tool.h +++ b/src/tools/status_tool.h @@ -143,6 +143,8 @@ class StatusTool : public CurveTool { int ServerListCmd(); int LogicalPoolListCmd(); int ChunkServerStatusCmd(); + int UpdateChunkServerCmd(); + int UpdateServerCmd(); int GetPoolsInCluster(std::vector* phyPools, std::vector* lgPools); int GetSpaceInfo(SpaceInfo* spaceInfo);