From 076eddece08aad423a3a9c2cd71f27262c2da78b Mon Sep 17 00:00:00 2001 From: xue_meng_en <1836611252@qq.com> Date: Mon, 5 Dec 2022 15:34:23 +0800 Subject: [PATCH] =?UTF-8?q?CM=E6=94=AF=E6=8C=81start/stop=20-I?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cm_ctl/ctl_common_res.cpp | 14 +++++++------- src/cm_ctl/ctl_help.cpp | 4 ++-- src/cm_ctl/ctl_start.cpp | 6 +++--- src/cm_ctl/ctl_stop.cpp | 7 +++---- src/include/cm/cm_ctl/ctl_common_res.h | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/cm_ctl/ctl_common_res.cpp b/src/cm_ctl/ctl_common_res.cpp index 5a397a5..f5b8b8d 100644 --- a/src/cm_ctl/ctl_common_res.cpp +++ b/src/cm_ctl/ctl_common_res.cpp @@ -92,24 +92,24 @@ ResStatus GetResInstStatus(uint32 instId) return result; } -status_t CheckResInstInfo(uint32 nodeId, uint32 instId) +status_t CheckResInstInfo(uint32 *nodeId, uint32 instId) { for (uint32 i = 0; i < CusResCount(); ++i) { - (void)pthread_rwlock_rdlock(&g_resStatus[i].rwlock); for (uint32 j = 0; j < g_resStatus[i].status.instanceCount; ++j) { if (g_resStatus[i].status.resStat[j].cmInstanceId != instId) { continue; } - if (g_resStatus[i].status.resStat[j].nodeId != nodeId) { + if (*nodeId == 0) { + *nodeId = g_resStatus[i].status.resStat[j].nodeId; + return CM_SUCCESS; + } + if (g_resStatus[i].status.resStat[j].nodeId != *nodeId) { write_runlog(FATAL, "resource(%s) instance(%u) is in node(%u) not in node(%u).\n", - g_resStatus[i].status.resName, instId, g_resStatus[i].status.resStat[j].nodeId, nodeId); - (void)pthread_rwlock_unlock(&g_resStatus[i].rwlock); + g_resStatus[i].status.resName, instId, g_resStatus[i].status.resStat[j].nodeId, *nodeId); return CM_ERROR; } - (void)pthread_rwlock_unlock(&g_resStatus[i].rwlock); return CM_SUCCESS; } - (void)pthread_rwlock_unlock(&g_resStatus[i].rwlock); } write_runlog(FATAL, "instanceId(%u) is not a resource instanceId.\n", instId); return CM_ERROR; diff --git a/src/cm_ctl/ctl_help.cpp b/src/cm_ctl/ctl_help.cpp index d6fc251..e8d7ea7 100644 --- a/src/cm_ctl/ctl_help.cpp +++ b/src/cm_ctl/ctl_help.cpp @@ -31,7 +31,7 @@ static void StartUsage(const char *projectName) projectName); #else (void)printf(_(" %s start [-z AVAILABILITY_ZONE [--cm_arbitration_mode=ARBITRATION_MODE]] | " - "[-n NODEID [-D DATADIR | -I RESOURCE_INSTANCE_ID]] [-t SECS] \n"), + "[-n NODEID [-D DATADIR]] | [-I RESOURCE_INSTANCE_ID [-n NODEID]] [-t SECS] \n"), projectName); #endif } @@ -67,7 +67,7 @@ static void UsageHelp(const char *projectName) (void)printf(_(" %s view [-v | -N | -n NODEID | -c] [-l FILENAME]\n"), projectName); (void)printf(_(" %s disable -n NODEID -D DATADIR [-t SECS]\n"), projectName); #else - (void)printf(_(" %s stop [[-z AVAILABILITY_ZONE] | [-n NODEID [-D DATADIR | -I RESOURCE_INSTANCE_ID]]] [-t SECS] " + (void)printf(_(" %s stop [[-z AVAILABILITY_ZONE] | [-n NODEID [-D DATADIR]] | [-I RESOURCE_INSTANCE_ID [-n NODEID]]] [-t SECS] " "[-m SHUTDOWN-MODE]\n"), projectName); (void)printf(_(" %s query [-z ALL] [-l FILENAME] [-v [-C [-s] [-S] [-d] [-i] [-F] [-x] [-p]] | [-r]] [-t SECS] " "[--minorityAz=AZ_NAME]\n"), projectName); diff --git a/src/cm_ctl/ctl_start.cpp b/src/cm_ctl/ctl_start.cpp index 85d7130..d61491a 100644 --- a/src/cm_ctl/ctl_start.cpp +++ b/src/cm_ctl/ctl_start.cpp @@ -247,7 +247,7 @@ status_t do_start(void) (void)clock_gettime(CLOCK_MONOTONIC, &g_startTime); /* start the whole cluster */ - if (g_command_operation_azName == NULL && g_commandOperationNodeId == 0) { + if (g_commandOperationInstanceId == 0 && g_command_operation_azName == NULL && g_commandOperationNodeId == 0) { #ifdef ENABLE_MULTIPLE_NODES if (cn_resumes_restart) { write_stderr(_("%s: enable resuming the fault CN.\n"), g_progname); @@ -322,8 +322,8 @@ status_t do_start(void) /* start a az with availability zone name */ write_runlog(LOG, "start the availability zone: %s. \n", g_command_operation_azName); start_az(g_command_operation_azName); - } else if (g_commandOperationNodeId > 0 && g_commandOperationInstanceId > 0) { - if (CheckResInstInfo(g_commandOperationNodeId, g_commandOperationInstanceId) != CM_SUCCESS) { + } else if (g_commandOperationInstanceId > 0) { + if (CheckResInstInfo(&g_commandOperationNodeId, g_commandOperationInstanceId) != CM_SUCCESS) { write_runlog(ERROR, "can't do start resource instance, instId:%u.\n", g_commandOperationInstanceId); return CM_ERROR; } diff --git a/src/cm_ctl/ctl_stop.cpp b/src/cm_ctl/ctl_stop.cpp index ed6ab7f..4cda5dd 100644 --- a/src/cm_ctl/ctl_stop.cpp +++ b/src/cm_ctl/ctl_stop.cpp @@ -147,15 +147,14 @@ int DoStop(void) } #endif - if (g_command_operation_azName == NULL && g_commandOperationNodeId == 0) { + if (g_commandOperationInstanceId == 0 && g_command_operation_azName == NULL && g_commandOperationNodeId == 0) { write_runlog(LOG, "stop cluster. \n"); stop_cluster(); } else if (g_command_operation_azName != NULL) { write_runlog(LOG, "stop the availability zone: %s. \n", g_command_operation_azName); - stop_az(g_command_operation_azName); - } else if ((g_commandOperationNodeId > 0) && (g_commandOperationInstanceId > 0)) { - if (CheckResInstInfo(g_commandOperationNodeId, g_commandOperationInstanceId) != CM_SUCCESS) { + } else if (g_commandOperationInstanceId > 0) { + if (CheckResInstInfo(&g_commandOperationNodeId, g_commandOperationInstanceId) != CM_SUCCESS) { write_runlog(ERROR, "can't do stop resource instance, instId:%u.\n", g_commandOperationInstanceId); return 1; } diff --git a/src/include/cm/cm_ctl/ctl_common_res.h b/src/include/cm/cm_ctl/ctl_common_res.h index f098b64..aa9f502 100644 --- a/src/include/cm/cm_ctl/ctl_common_res.h +++ b/src/include/cm/cm_ctl/ctl_common_res.h @@ -28,6 +28,6 @@ #include "cm_defs.h" ResStatus GetResInstStatus(uint32 instId); -status_t CheckResInstInfo(uint32 nodeId, uint32 instId); +status_t CheckResInstInfo(uint32 *nodeId, uint32 instId); #endif // CM_CTL_COMMON_RES_H