!4872 增加UWAL配置中replinodes参数的非空校验

Merge pull request !4872 from 胡翔/master
This commit is contained in:
opengauss_bot
2024-02-22 01:13:38 +00:00
committed by Gitee

View File

@ -337,35 +337,44 @@ static bool GsUwalParseConfig(cJSON *uwalConfJSON)
}
cJSON *replinodesJSON = cJSON_GetObjectItem(uwalConfJSON, "uwal_replinodes");
if (cJSON_IsArray(replinodesJSON)) {
int arrLen = cJSON_GetArraySize(replinodesJSON);
for (int i = 0; i < arrLen; i++) {
cJSON *subObj = cJSON_GetArrayItem(replinodesJSON, i);
if (nullptr == subObj) {
continue;
} else {
cJSON *subIdJSON = cJSON_GetObjectItem(subObj, "id");
if (subIdJSON == nullptr) {
ereport(ERROR, (errmsg("No item uwal_nodeid in uwal_replinodes")));
return false;
}
if (subIdJSON->valueint < 0 || subIdJSON->valueint >= MAX_GAUSS_NODE) {
ereport(ERROR, (errmsg("uwal_nodeid out of range [0, 7]")));
return false;
}
int nodeId = subIdJSON->valueint;
cJSON *subProtocolJSON = cJSON_GetObjectItem(subObj, "protocol");
if (subProtocolJSON == nullptr) {
ereport(WARNING, (errmsg("No item protocol in uwal_replinodes, use the default protocol tcp")));
rc = strcpy_s(g_uwalConfig.repliNodes[nodeId], UWAL_PROTOCOL_LEN, "tcp");
securec_check(rc, "\0", "\0");
} else if (strcasecmp(subProtocolJSON->valuestring, "rdma") && strcasecmp(subProtocolJSON->valuestring, "tcp")) {
ereport(WARNING, (errmsg("protocol only support tcp and rdma, use the default protocol tcp")));
rc = strcpy_s(g_uwalConfig.repliNodes[nodeId], UWAL_PROTOCOL_LEN, "tcp");
securec_check(rc, "\0", "\0");
if (replinodesJSON == nullptr) {
ereport(WARNING, (errmsg("No item uwal_replinodes in uwal_config, will use the default protocol tcp")));
for (int i = 0; i <MAX_NODE_NUM; i++) {
rc = strcpy_s(g_uwalConfig.repliNodes[i], UWAL_PROTOCOL_LEN, "tcp");
securec_check(rc, "\0", "\0");
}
} else {
if (cJSON_IsArray(replinodesJSON)) {
int arrLen = cJSON_GetArraySize(replinodesJSON);
for (int i = 0; i < arrLen; i++) {
cJSON *subObj = cJSON_GetArrayItem(replinodesJSON, i);
if (nullptr == subObj) {
continue;
} else {
rc = strcpy_s(g_uwalConfig.repliNodes[nodeId], UWAL_PROTOCOL_LEN, subProtocolJSON->valuestring);
securec_check(rc, "\0", "\0");
cJSON *subIdJSON = cJSON_GetObjectItem(subObj, "id");
if (subIdJSON == nullptr) {
ereport(ERROR, (errmsg("No item uwal_nodeid in uwal_replinodes")));
return false;
}
if (subIdJSON->valueint < 0 || subIdJSON->valueint >= MAX_GAUSS_NODE) {
ereport(ERROR, (errmsg("uwal_nodeid out of range [0, 7]")));
return false;
}
int nodeId = subIdJSON->valueint;
cJSON *subProtocolJSON = cJSON_GetObjectItem(subObj, "protocol");
if (subProtocolJSON == nullptr) {
ereport(WARNING, (errmsg("No item protocol in uwal_replinodes, use the default protocol tcp")));
rc = strcpy_s(g_uwalConfig.repliNodes[nodeId], UWAL_PROTOCOL_LEN, "tcp");
securec_check(rc, "\0", "\0");
} else if (strcasecmp(subProtocolJSON->valuestring, "rdma") &&
strcasecmp(subProtocolJSON->valuestring, "tcp")) {
ereport(WARNING, (errmsg("protocol only support tcp and rdma, use the default protocol tcp")));
rc = strcpy_s(g_uwalConfig.repliNodes[nodeId], UWAL_PROTOCOL_LEN, "tcp");
securec_check(rc, "\0", "\0");
} else {
rc = strcpy_s(g_uwalConfig.repliNodes[nodeId], UWAL_PROTOCOL_LEN, subProtocolJSON->valuestring);
securec_check(rc, "\0", "\0");
}
}
}
}