!135 CM query输出格式解决--统一CM和DN输出格式

Merge pull request !135 from T_WRLD/master
This commit is contained in:
opengauss_bot 2023-08-17 08:17:09 +00:00 committed by Gitee
commit fc86fb1561
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 96 additions and 46 deletions

View File

@ -57,6 +57,8 @@
char* g_bin_name = NULL;
char* g_bin_path = NULL;
// Need to change the options here, if options of the commands are added or modified
static const char* g_allowedOptions = "aAb:B:cCD:dE:fFgil:I:j:k:L:m:M:n:NP:pqrRsSt:T:vwxz:";
extern char sys_log_path[MAXPGPATH];
extern const char* prefix_name;
@ -67,6 +69,7 @@ static bool lc_operation = false;
bool got_stop = false;
bool g_detailQuery = false;
bool g_formatQuery = false;
bool g_coupleQuery = false;
bool backup_process_query = false;
bool g_balanceQuery = false;
@ -1034,13 +1037,13 @@ static int CheckCommandQueryLcOperation(void)
if (ctl_command == CM_QUERY_COMMAND && lc_operation) {
if (g_detailQuery) {
write_runlog2(ERROR, errcode(ERRCODE_PARAMETER_FAILURE), errmsg("-C is needed."), errdetail("N/A"),
errmodule(MOD_CMCTL), errcause("%s: The cmdline entered by the user is incorrect.", g_progname),
erraction("Please check the cmdline entered by the user(%s).", g_cmdLine));
errmodule(MOD_CMCTL), errcause("%s: The cmdline entered by the user is incorrect.", g_progname),
erraction("Please check the cmdline entered by the user(%s).", g_cmdLine));
} else {
write_runlog2(ERROR, errcode(ERRCODE_PARAMETER_FAILURE), errmsg("-Cv is needed."),
errdetail("N/A"), errmodule(MOD_CMCTL),
errcause("%s: The cmdline entered by the user is incorrect.", g_progname),
erraction("Please check the cmdline entered by the user(%s).", g_cmdLine));
errdetail("N/A"), errmodule(MOD_CMCTL),
errcause("%s: The cmdline entered by the user is incorrect.", g_progname),
erraction("Please check the cmdline entered by the user(%s).", g_cmdLine));
}
return 1;
}
@ -1067,6 +1070,22 @@ static int CheckCommandQuery(void)
return 1;
}
cond = (g_formatQuery && !g_coupleQuery && !g_detailQuery);
if (cond) {
write_runlog2(ERROR, errcode(ERRCODE_PARAMETER_FAILURE), errmsg("-Cv is needed."), errdetail("N/A"),
errmodule(MOD_CMCTL), errcause("%s: The cmdline entered by the user is incorrect.", g_progname),
erraction("Please check the cmdline entered by the user(%s).", g_cmdLine));
return 1;
}
cond = (g_formatQuery && !g_coupleQuery && g_detailQuery);
if (cond) {
write_runlog2(ERROR, errcode(ERRCODE_PARAMETER_FAILURE), errmsg("-C is needed."), errdetail("N/A"),
errmodule(MOD_CMCTL), errcause("%s: The cmdline entered by the user is incorrect.", g_progname),
erraction("Please check the cmdline entered by the user(%s).", g_cmdLine));
return 1;
}
CM_RETURN_INT_IFERR(CheckCommandQueryLcOperation());
cond = (ctl_command == CM_QUERY_COMMAND) && !logic_cluster_query &&
@ -1810,6 +1829,9 @@ static void ParseCmdArgsCore(int cmd, bool *setDataPath, CtlOption *ctlCtx)
case 'v':
g_detailQuery = true;
break;
case 'w':
g_formatQuery = true;
break;
case 'c':
ctlCtx->build.isNeedCmsBuild = true;
coordinator_dynamic_view = true;
@ -2370,8 +2392,7 @@ int main(int argc, char** argv)
/* process command-line options */
while (optind < argc) {
while ((c = getopt_long(argc, argv, "aAb:B:cCD:dE:fFgil:I:j:k:L:m:M:n:NP:pqrRsSt:T:vxz:", longOptions,
&optionIndex)) != -1) {
while ((c = getopt_long(argc, argv, g_allowedOptions, longOptions, &optionIndex)) != -1) {
/* parse command type */
ParseCmdArgsCore(c, &set_data_path, &ctlCtx);
}

View File

@ -61,7 +61,7 @@ static void UsageHelp(const char *projectName)
#ifdef ENABLE_MULTIPLE_NODES
(void)printf(_(" %s stop [[-z AVAILABILITY_ZONE] | [-n NODEID [-D DATADIR [-R] | -I RESOURCE_INSTANCE_ID]]] "
"[-t SECS] [-m SHUTDOWN-MODE]\n"), projectName);
(void)printf(_(" %s query [-z ALL] [-n NODEID [-D DATADIR -R]] [-l FILENAME] [-v [-C [-s] [-S] [-d] [-i] [-F] "
(void)printf(_(" %s query [-z ALL] [-n NODEID [-D DATADIR -R]] [-l FILENAME] [-v [-C [-w] [-s] [-S] [-d] [-i] [-F] "
"[-L ALL] [-x] [-p]] | [-r]] [-t SECS] [--minorityAz=AZ_NAME]\n"), projectName);
(void)printf(_(" %s restart [-L LCNAME]\n"), projectName);
(void)printf(_(" %s view [-v | -N | -n NODEID | -c] [-l FILENAME]\n"), projectName);
@ -69,7 +69,7 @@ static void UsageHelp(const char *projectName)
#else
(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] "
(void)printf(_(" %s query [-z ALL] [-l FILENAME] [-v [-C [-w] [-s] [-S] [-d] [-i] [-F] [-x] [-p]] | [-r]] [-t SECS] "
"[--minorityAz=AZ_NAME]\n"), projectName);
(void)printf(_(" %s view [-v | -N | -n NODEID] [-l FILENAME]\n"), projectName);
#endif
@ -182,6 +182,7 @@ static void QueryHelp()
(void)printf(_(" -s show instances that need to switchover\n"));
(void)printf(_(" -C show query result by HA relation\n"));
(void)printf(_(" -v show detail query result\n"));
(void)printf(_(" -w show detail query result in vertical format\n"));
(void)printf(_(" -d show instance datapath\n"));
(void)printf(_(" -i show physical node ip\n"));
(void)printf(_(" -F show all fenced UDF master process status\n"));

View File

@ -46,6 +46,7 @@ static status_t QueryResourceStatus(CM_Conn *pCmsCon);
static bool hasFindEtcdL = false;
extern bool g_detailQuery;
extern bool g_coupleQuery;
extern bool g_formatQuery;
extern bool g_balanceQuery;
extern bool g_startStatusQuery;
extern bool g_abnormalQuery;
@ -1896,12 +1897,17 @@ static void print_simple_DN_result(uint32 node_index, cm_to_ctl_instance_status
cm_to_ctl_instance_status_ptr->data_node_member.local_status.buildReason));
}
if (g_multi_az_cluster && ((uint32)cm_to_ctl_instance_status_ptr->member_index < (g_dn_replication_num - 1))) {
(void)fprintf(g_logFilePtr, " | ");
} else if (!g_single_node_cluster && !g_multi_az_cluster &&
(cm_to_ctl_instance_status_ptr->member_index == 0 || cm_to_ctl_instance_status_ptr->member_index == 1)) {
(void)fprintf(g_logFilePtr, " | ");
} else {
if (g_formatQuery) {
(void)fprintf(g_logFilePtr, "\n");
} else {
if (g_multi_az_cluster && ((uint32)cm_to_ctl_instance_status_ptr->member_index < (g_dn_replication_num - 1))) {
(void)fprintf(g_logFilePtr, " | ");
} else if (!g_single_node_cluster && !g_multi_az_cluster &&
(cm_to_ctl_instance_status_ptr->member_index == 0 ||
cm_to_ctl_instance_status_ptr->member_index == 1)) {
(void)fprintf(g_logFilePtr, " | ");
} else {
(void)fprintf(g_logFilePtr, "\n");
}
}
}

View File

@ -30,6 +30,7 @@
extern bool g_detailQuery;
extern bool g_coupleQuery;
extern bool g_formatQuery;
extern bool g_balanceQuery;
extern bool g_startStatusQuery;
extern bool g_portQuery;
@ -453,36 +454,47 @@ void CalcDnHeaderSize(uint32 *nodeLen, uint32 *instanceLen, uint32 *stateLen)
void PrintDnHeaderLine(uint32 nodeLen, uint32 instanceLen, uint32 tmpInstanceLen, uint32 stateLen)
{
if (g_ipQuery) {
if (g_multi_az_cluster) {
for (uint32 jj = 0; jj < g_dn_replication_num - 1; jj++) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%-*s| ",
nodeLen, "node", MAX_IP_LEN + 1, "node_ip",
tmpInstanceLen, "instance", stateLen, "state");
}
} else if (!g_single_node_cluster) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%-*s| ", nodeLen, "node", MAX_IP_LEN + 1,
"node_ip", tmpInstanceLen, "instance", stateLen, "state");
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%-*s| ", nodeLen, "node", MAX_IP_LEN + 1,
"node_ip", tmpInstanceLen, "instance", stateLen, "state");
if (g_formatQuery) {
if (g_ipQuery) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%s\n", nodeLen, "node", MAX_IP_LEN + 1,
"node_ip", tmpInstanceLen, "instance", "state");
} else {
(void)fprintf(g_logFilePtr, "%-*s%-*s%s\n", nodeLen, "node",
g_single_node_cluster ? tmpInstanceLen : instanceLen,
"instance", "state");
}
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%s\n", nodeLen, "node", MAX_IP_LEN + 1,
"node_ip", tmpInstanceLen, "instance", "state");
} else {
if (g_multi_az_cluster) {
for (uint32 jj = 0; jj < g_dn_replication_num - 1; jj++) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s| ", nodeLen, "node",
tmpInstanceLen, "instance", stateLen, "state");
if (g_ipQuery) {
if (g_multi_az_cluster) {
for (uint32 jj = 0; jj < g_dn_replication_num - 1; jj++) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%-*s| ",
nodeLen, "node", MAX_IP_LEN + 1, "node_ip",
tmpInstanceLen, "instance", stateLen, "state");
}
} else if (!g_single_node_cluster) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%-*s| ", nodeLen, "node", MAX_IP_LEN + 1,
"node_ip", tmpInstanceLen, "instance", stateLen, "state");
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%-*s| ", nodeLen, "node", MAX_IP_LEN + 1,
"node_ip", tmpInstanceLen, "instance", stateLen, "state");
}
} else if (!g_single_node_cluster) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s| ", nodeLen, "node",
tmpInstanceLen, "instance", stateLen, "state");
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s| ",
nodeLen, "node", tmpInstanceLen, "instance", stateLen, "state");
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s%s\n", nodeLen, "node", MAX_IP_LEN + 1,
"node_ip", tmpInstanceLen, "instance", "state");
} else {
if (g_multi_az_cluster) {
for (uint32 jj = 0; jj < g_dn_replication_num - 1; jj++) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s| ", nodeLen, "node",
tmpInstanceLen, "instance", stateLen, "state");
}
} else if (!g_single_node_cluster) {
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s| ", nodeLen, "node",
tmpInstanceLen, "instance", stateLen, "state");
(void)fprintf(g_logFilePtr, "%-*s%-*s%-*s| ",
nodeLen, "node", tmpInstanceLen, "instance", stateLen, "state");
}
(void)fprintf(g_logFilePtr, "%-*s%-*s%s\n", nodeLen, "node",
g_single_node_cluster ? tmpInstanceLen : instanceLen,
"instance", "state");
}
(void)fprintf(g_logFilePtr, "%-*s%-*s%s\n", nodeLen, "node",
g_single_node_cluster ? tmpInstanceLen : instanceLen,
"instance", "state");
}
}
@ -507,12 +519,22 @@ void PrintDnStatusLine()
SECONDARY_DYNAMIC_ROLE_LEN + SPACE_LEN +
INSTANCE_DB_STATE_LEN;
if (g_multi_az_cluster || g_single_node_cluster) {
maxLen = g_dn_replication_num *
(nodeLen + tmpInstanceLen + (g_ipQuery ? (MAX_IP_LEN + 1) : 0)) +
g_dn_replication_num * (stateLen + SEPERATOR_LEN + SPACE_LEN);
if (g_formatQuery) {
maxLen = (nodeLen + tmpInstanceLen + (g_ipQuery ? (MAX_IP_LEN + 1) : 0)) +
(stateLen + SEPERATOR_LEN + SPACE_LEN);
} else {
maxLen = g_dn_replication_num *
(nodeLen + tmpInstanceLen + (g_ipQuery ? (MAX_IP_LEN + 1) : 0)) +
g_dn_replication_num * (stateLen + SEPERATOR_LEN + SPACE_LEN);
}
} else {
maxLen = NODE_NUM * (nodeLen + tmpInstanceLen + (g_ipQuery ? (MAX_IP_LEN + 1) : 0)) +
SPACE_NUM * (stateLen + SEPERATOR_LEN + SPACE_LEN) + secondryStateLen;
if (g_formatQuery) {
maxLen = (nodeLen + tmpInstanceLen + (g_ipQuery ? (MAX_IP_LEN + 1) : 0)) +
(stateLen + SEPERATOR_LEN + SPACE_LEN) + secondryStateLen;
} else {
maxLen = NODE_NUM * (nodeLen + tmpInstanceLen + (g_ipQuery ? (MAX_IP_LEN + 1) : 0)) +
SPACE_NUM * (stateLen + SEPERATOR_LEN + SPACE_LEN) + secondryStateLen;
}
}
for (uint32 i = 0; i < maxLen; i++) {
(void)fprintf(g_logFilePtr, "-");