mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
daemon status: make output more like that of "cluster show"
In particular make any issues with unexpected server state more obvious.
This commit is contained in:
@@ -184,231 +184,10 @@ do_cluster_show(void)
|
||||
|
||||
initPQExpBuffer(&details);
|
||||
|
||||
/*
|
||||
* TODO: count nodes marked as "? unreachable" and add a hint about
|
||||
* the other cluster commands for better determining whether
|
||||
* unreachable.
|
||||
*/
|
||||
switch (cell->node_info->type)
|
||||
{
|
||||
case PRIMARY:
|
||||
{
|
||||
/* node is reachable */
|
||||
if (cell->node_info->node_status == NODE_STATUS_UP)
|
||||
{
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
switch (cell->node_info->recovery_type)
|
||||
{
|
||||
case RECTYPE_PRIMARY:
|
||||
appendPQExpBufferStr(&details, "* running");
|
||||
break;
|
||||
case RECTYPE_STANDBY:
|
||||
appendPQExpBufferStr(&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;
|
||||
case RECTYPE_UNKNOWN:
|
||||
appendPQExpBufferStr(&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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cell->node_info->recovery_type == RECTYPE_PRIMARY)
|
||||
{
|
||||
appendPQExpBufferStr(&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
|
||||
{
|
||||
appendPQExpBufferStr(&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 up but cannot connect */
|
||||
else if (cell->node_info->node_status == NODE_STATUS_REJECTED)
|
||||
{
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
appendPQExpBufferStr(&details, "? running");
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBufferStr(&details, "! running");
|
||||
error_found = true;
|
||||
}
|
||||
}
|
||||
/* node is unreachable */
|
||||
else
|
||||
{
|
||||
/* node is unreachable but marked active */
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
appendPQExpBufferStr(&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 */
|
||||
else
|
||||
{
|
||||
appendPQExpBufferStr(&details, "- failed");
|
||||
error_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STANDBY:
|
||||
{
|
||||
/* node is reachable */
|
||||
if (cell->node_info->node_status == NODE_STATUS_UP)
|
||||
{
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
switch (cell->node_info->recovery_type)
|
||||
{
|
||||
case RECTYPE_STANDBY:
|
||||
appendPQExpBufferStr(&details, " running");
|
||||
break;
|
||||
case RECTYPE_PRIMARY:
|
||||
appendPQExpBufferStr(&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;
|
||||
case RECTYPE_UNKNOWN:
|
||||
appendPQExpBufferStr(&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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cell->node_info->recovery_type == RECTYPE_STANDBY)
|
||||
{
|
||||
appendPQExpBufferStr(&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
|
||||
{
|
||||
appendPQExpBufferStr(&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);
|
||||
}
|
||||
}
|
||||
|
||||
/* warn about issue with paused WAL replay */
|
||||
if (is_wal_replay_paused(cell->node_info->conn, true))
|
||||
{
|
||||
item_list_append_format(&warnings,
|
||||
_("WAL replay is paused on node \"%s\" (ID: %i) with WAL replay pending; this node cannot be manually promoted until WAL replay is resumed"),
|
||||
cell->node_info->node_name, cell->node_info->node_id);
|
||||
}
|
||||
}
|
||||
/* node is up but cannot connect */
|
||||
else if (cell->node_info->node_status == NODE_STATUS_REJECTED)
|
||||
{
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
appendPQExpBufferStr(&details, "? running");
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBufferStr(&details, "! running");
|
||||
error_found = true;
|
||||
}
|
||||
}
|
||||
/* node is unreachable */
|
||||
else
|
||||
{
|
||||
/* node is unreachable but marked active */
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
appendPQExpBufferStr(&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
|
||||
{
|
||||
appendPQExpBufferStr(&details, "- failed");
|
||||
error_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case WITNESS:
|
||||
case BDR:
|
||||
{
|
||||
/* node is reachable */
|
||||
if (cell->node_info->node_status == NODE_STATUS_UP)
|
||||
{
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
appendPQExpBufferStr(&details, "* running");
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBufferStr(&details, "! running");
|
||||
error_found = true;
|
||||
}
|
||||
}
|
||||
/* node is up but cannot connect */
|
||||
else if (cell->node_info->node_status == NODE_STATUS_REJECTED)
|
||||
{
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
appendPQExpBufferStr(&details, "? rejected");
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBufferStr(&details, "! failed");
|
||||
error_found = true;
|
||||
}
|
||||
|
||||
}
|
||||
/* node is unreachable */
|
||||
else
|
||||
{
|
||||
if (cell->node_info->active == true)
|
||||
{
|
||||
appendPQExpBufferStr(&details, "? unreachable");
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBufferStr(&details, "- failed");
|
||||
error_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case UNKNOWN:
|
||||
{
|
||||
/* this should never happen */
|
||||
appendPQExpBufferStr(&details, "? unknown node type");
|
||||
error_found = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (format_node_status(cell->node_info, &details, &warnings) == false)
|
||||
error_found = true;
|
||||
strncpy(cell->node_info->details, details.data, MAXLEN);
|
||||
|
||||
termPQExpBuffer(&details);
|
||||
|
||||
PQfinish(cell->node_info->conn);
|
||||
|
||||
Reference in New Issue
Block a user