repmgrd cluster show: add warnings with information about discrepancies

This commit is contained in:
Ian Barwick
2017-08-28 11:19:32 +09:00
parent 4a11551c2f
commit d85b066f45

View File

@@ -64,6 +64,7 @@ do_cluster_show(void)
NodeInfoList nodes = T_NODE_INFO_LIST_INITIALIZER; NodeInfoList nodes = T_NODE_INFO_LIST_INITIALIZER;
NodeInfoListCell *cell = NULL; NodeInfoListCell *cell = NULL;
int i = 0; int i = 0;
ItemList warnings = { NULL, NULL };
/* Connect to local database to obtain cluster connection data */ /* Connect to local database to obtain cluster connection data */
log_verbose(LOG_INFO, _("connecting to database\n")); log_verbose(LOG_INFO, _("connecting to database\n"));
@@ -139,18 +140,36 @@ do_cluster_show(void)
break; break;
case RECTYPE_STANDBY: case RECTYPE_STANDBY:
appendPQExpBuffer(&details, "! running as standby"); appendPQExpBuffer(&details, "! running as standby");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is registered as primary but running as standby",
cell->node_info->node_name, cell->node_info->node_id);
break; break;
case RECTYPE_UNKNOWN: case RECTYPE_UNKNOWN:
appendPQExpBuffer(&details, "! unknown"); appendPQExpBuffer(&details, "! unknown");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) has unknown replication status",
cell->node_info->node_name, cell->node_info->node_id);
break; break;
} }
} }
else else
{ {
if (cell->node_info->recovery_type == RECTYPE_PRIMARY) if (cell->node_info->recovery_type == RECTYPE_PRIMARY)
{
appendPQExpBuffer(&details, "! running"); appendPQExpBuffer(&details, "! running");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is running but the repmgr node record is inactive",
cell->node_info->node_name, cell->node_info->node_id);
}
else else
appendPQExpBuffer(&details, "! running as standby"); appendPQExpBuffer(&details, "! running as standby");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is registered as an inactive primary but running as standby",
cell->node_info->node_name, cell->node_info->node_id);
} }
} }
/* node is unreachable */ /* node is unreachable */
@@ -158,10 +177,18 @@ do_cluster_show(void)
{ {
/* node is unreachable but marked active*/ /* node is unreachable but marked active*/
if (cell->node_info->active == true) if (cell->node_info->active == true)
{
appendPQExpBuffer(&details, "? unreachable"); appendPQExpBuffer(&details, "? unreachable");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is registered as an active primary but is unreachable",
cell->node_info->node_name, cell->node_info->node_id);
}
/* node is unreachable and marked as inactive */ /* node is unreachable and marked as inactive */
else else
{
appendPQExpBuffer(&details, "- failed"); appendPQExpBuffer(&details, "- failed");
}
} }
} }
break; break;
@@ -179,18 +206,38 @@ do_cluster_show(void)
break; break;
case RECTYPE_PRIMARY: case RECTYPE_PRIMARY:
appendPQExpBuffer(&details, "! running as primary"); appendPQExpBuffer(&details, "! running as primary");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is registered as standby but running as primary",
cell->node_info->node_name, cell->node_info->node_id);
break; break;
case RECTYPE_UNKNOWN: case RECTYPE_UNKNOWN:
appendPQExpBuffer(&details, "! unknown"); appendPQExpBuffer(&details, "! unknown");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) has unknown replication status",
cell->node_info->node_name, cell->node_info->node_id);
break; break;
} }
} }
else else
{ {
if (cell->node_info->recovery_type == RECTYPE_STANDBY) if (cell->node_info->recovery_type == RECTYPE_STANDBY)
{
appendPQExpBuffer(&details, "! running"); appendPQExpBuffer(&details, "! running");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is running but the repmgr node record is inactive",
cell->node_info->node_name, cell->node_info->node_id);
}
else else
{
appendPQExpBuffer(&details, "! running as primary"); appendPQExpBuffer(&details, "! running as primary");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is running as primary but the repmgr node record is inactive",
cell->node_info->node_name, cell->node_info->node_id);
}
} }
} }
/* node is unreachable */ /* node is unreachable */
@@ -198,9 +245,17 @@ do_cluster_show(void)
{ {
/* node is unreachable but marked active*/ /* node is unreachable but marked active*/
if (cell->node_info->active == true) if (cell->node_info->active == true)
{
appendPQExpBuffer(&details, "? unreachable"); appendPQExpBuffer(&details, "? unreachable");
item_list_append_format(
&warnings,
"node \"%s\" (ID: %i) is registered as an active standby but is unreachable",
cell->node_info->node_name, cell->node_info->node_id);
}
else else
{
appendPQExpBuffer(&details, "- failed"); appendPQExpBuffer(&details, "- failed");
}
} }
} }
break; break;
@@ -327,6 +382,19 @@ do_cluster_show(void)
clear_node_info_list(&nodes); clear_node_info_list(&nodes);
PQfinish(conn); PQfinish(conn);
/* emit any warnings */
if (warnings.head != NULL && runtime_options.terse == false)
{
ItemListCell *cell = NULL;
printf(_("\nWARNING: following issues were detected\n"));
for (cell = warnings.head; cell; cell = cell->next)
{
printf(_(" %s\n"), cell->string);
}
}
} }