diff --git a/src/cm_common/cm_misc.cpp b/src/cm_common/cm_misc.cpp index b9e28fc..e0f90c0 100644 --- a/src/cm_common/cm_misc.cpp +++ b/src/cm_common/cm_misc.cpp @@ -1322,11 +1322,25 @@ status_t IsReachableIP(char *ip) if (ip == nullptr) { return CM_ERROR; } + char tmpIp[CM_IP_LENGTH]; + int rc = -1; + rc = strcpy_s(tmpIp, CM_IP_LENGTH, ip); + securec_check_errno(rc, (void)rc); + char *saveptr = NULL; + char *token = strtok_r(tmpIp, ",", &saveptr); char cmd[MAXPGPATH] = {0}; - int rc = snprintf_s(cmd, MAXPGPATH, MAXPGPATH - 1, "timeout 2 ping -c 2 %s > /dev/null 2>&1", ip); - securec_check_intval(rc, (void)rc); - rc = system(cmd); - return rc == 0 ? CM_SUCCESS : CM_ERROR; + while (token != NULL) { + rc = memset_s(cmd, MAXPGPATH, 0, MAXPGPATH); + securec_check_errno(rc, (void)rc); + rc = snprintf_s(cmd, MAXPGPATH, MAXPGPATH - 1, "timeout 2 ping -c 2 %s > /dev/null 2>&1", token); + securec_check_intval(rc, (void)rc); + rc = system(cmd); + if (rc == 0) { + return CM_SUCCESS; + } + token = strtok_r(NULL, ",", &saveptr); + } + return CM_ERROR; } bool IsIPAddrValid(const char *ipAddr) diff --git a/src/cm_server/cm_server.centralized.conf.sample b/src/cm_server/cm_server.centralized.conf.sample index fddf8c4..9e490c1 100644 --- a/src/cm_server/cm_server.centralized.conf.sample +++ b/src/cm_server/cm_server.centralized.conf.sample @@ -74,6 +74,7 @@ agent_network_timeout = 6 dn_arbitrate_mode = quorum agent_fault_timeout = 60 third_party_gateway_ip = '' # used in 2 nodes cluster for ddb role arbitration with network isolation, + # support multiple iP addresses separated by commas, like '172.0.0.1,172.0.0.2' # when cms_enable_failover_on2nodes is true. # default ''. if cms_enable_failover_on2nodes is true, this param must be configured. cms_enable_failover_on2nodes = false # used in 2 nodes cluster. if true, will use third_party_gateway_ip as an arbitrator, diff --git a/src/cm_server/cm_server.centralized_new.conf.sample b/src/cm_server/cm_server.centralized_new.conf.sample index 003098f..9ae30ab 100644 --- a/src/cm_server/cm_server.centralized_new.conf.sample +++ b/src/cm_server/cm_server.centralized_new.conf.sample @@ -71,6 +71,7 @@ agent_network_timeout = 6 dn_arbitrate_mode = quorum delay_arbitrate_max_cluster_timeout = 300 # When resources are in the startup process, delay arbitration of the maximum cluster. third_party_gateway_ip = '' # used in 2 nodes cluster for ddb role arbitration with network isolation, + # support multiple iP addresses separated by commas, like '172.0.0.1,172.0.0.2' # when cms_enable_failover_on2nodes is true. # default ''. if cms_enable_failover_on2nodes is true, this param must be configured. cms_enable_failover_on2nodes = false # used in 2 nodes cluster. if true, will use third_party_gateway_ip as an arbitrator, diff --git a/src/cm_server/cm_server.conf.sample b/src/cm_server/cm_server.conf.sample index 4419b43..b6e375c 100644 --- a/src/cm_server/cm_server.conf.sample +++ b/src/cm_server/cm_server.conf.sample @@ -71,6 +71,7 @@ ddb_log_suppress_enable = 1 # Indicates whether to enable the log s ddb_election_timeout = 3 # DCC election timeout interval [1S,600S] share_disk_path = '' third_party_gateway_ip = '' # used in 2 nodes cluster for ddb role arbitration with network isolation, + # support multiple iP addresses separated by commas, like '172.0.0.1,172.0.0.2' # when cms_enable_failover_on2nodes is true. # default ''. if cms_enable_failover_on2nodes is true, this param must be configured. cms_enable_failover_on2nodes = false # used in 2 nodes cluster. if true, will use third_party_gateway_ip as an arbitrator, diff --git a/src/cm_server/cms_common.cpp b/src/cm_server/cms_common.cpp index 9f19d27..dad634e 100644 --- a/src/cm_server/cms_common.cpp +++ b/src/cm_server/cms_common.cpp @@ -352,10 +352,19 @@ void GetTwoNodesArbitrateParams(void) { } } - if (g_paramsOn2Nodes.cmsEnableFailoverOn2Nodes == true && !IsIPAddrValid(g_paramsOn2Nodes.thirdPartyGatewayIp)) { - write_runlog(ERROR, "parameter \"cms_enable_failover_on2nodes\" is true, " - "but parameter \"third_party_gateway_ip\" is invalid, please check!\n"); - exit(1); + if (g_paramsOn2Nodes.cmsEnableFailoverOn2Nodes) { + char tmpIp[MAXPGPATH]; + strcpy_s(tmpIp, MAXPGPATH, g_paramsOn2Nodes.thirdPartyGatewayIp); + char *saveptr = NULL; + char *token = strtok_r(tmpIp, ",", &saveptr); + while (token != NULL) { + if (!IsIPAddrValid(token)) { + write_runlog(ERROR, "parameter \"cms_enable_failover_on2nodes\" is true, " + "but parameter \"third_party_gateway_ip\" is invalid, please check!\n"); + exit(1); + } + token = strtok_r(NULL, ",", &saveptr); + } } g_paramsOn2Nodes.cmsNetworkIsolationTimeout = (uint32)get_int_value_from_config(configDir,