Rename option "node check --is-shutdown" to "--is-shutdown-cleanly"

As that's what we really want to know. Also return "UNCLEAN_SHUTDOWN"
if that's the case, rather than "RUNNING" which is confusing, even
though it's a command for internal use.
This commit is contained in:
Ian Barwick
2017-09-07 11:15:27 +09:00
parent 79531ae9da
commit edee80cc37
6 changed files with 59 additions and 43 deletions

View File

@@ -54,7 +54,8 @@ typedef enum {
typedef enum {
NODE_STATUS_UNKNOWN = -1,
NODE_STATUS_UP,
NODE_STATUS_DOWN
NODE_STATUS_DOWN,
NODE_STATUS_UNCLEAN_SHUTDOWN
} NodeStatus;
typedef enum {

View File

@@ -25,7 +25,7 @@ static t_server_action parse_server_action(const char *action);
static void _do_node_service_check(void);
static void _do_node_service_list_actions(t_server_action action);
static void _do_node_status_is_shutdown(void);
static void _do_node_status_is_shutdown_cleanly(void);
static void _do_node_archive_config(void);
static void _do_node_restore_config(void);
@@ -42,7 +42,7 @@ static CheckStatus do_node_check_slots(PGconn *conn, OutputMode mode, t_node_inf
* read the data directory.
*
* Parameters:
* --is-shutdown (for internal use only)
* --is-shutdown-cleanly (for internal use only)
* --csv
*/
@@ -66,9 +66,9 @@ do_node_status(void)
char data_dir[MAXPGPATH] = "";
if (runtime_options.is_shutdown == true)
if (runtime_options.is_shutdown_cleanly == true)
{
return _do_node_status_is_shutdown();
return _do_node_status_is_shutdown_cleanly();
}
/* config file required, so we should have "conninfo" and "data_directory" */
@@ -438,20 +438,21 @@ do_node_status(void)
*
* Returns "longopt" output:
*
* --status=(RUNNING|SHUTDOWN|UNKNOWN)
* --status=(RUNNING|SHUTDOWN|UNCLEAN_SHUTDOWN|UNKNOWN)
* --last-checkpoint=...
*/
static
void _do_node_status_is_shutdown(void)
void _do_node_status_is_shutdown_cleanly(void)
{
PGPing status;
PGPing ping_status;
PQExpBufferData output;
bool is_shutdown = true;
DBState db_state;
XLogRecPtr checkPoint = InvalidXLogRecPtr;
NodeStatus node_status = NODE_STATUS_UNKNOWN;
initPQExpBuffer(&output);
appendPQExpBuffer(
@@ -467,17 +468,15 @@ void _do_node_status_is_shutdown(void)
return;
}
status = PQping(config_file_options.conninfo);
ping_status = PQping(config_file_options.conninfo);
switch (status)
switch (ping_status)
{
case PQPING_OK:
appendPQExpBuffer(&output, "RUNNING");
is_shutdown = false;
node_status = NODE_STATUS_UP;
break;
case PQPING_REJECT:
appendPQExpBuffer(&output, "RUNNING");
is_shutdown = false;
node_status = NODE_STATUS_UP;
break;
case PQPING_NO_ATTEMPT:
case PQPING_NO_RESPONSE:
@@ -491,31 +490,43 @@ void _do_node_status_is_shutdown(void)
if (db_state != DB_SHUTDOWNED && db_state != DB_SHUTDOWNED_IN_RECOVERY)
{
appendPQExpBuffer(&output, "RUNNING");
is_shutdown = false;
/* node is not running, but pg_controldata says it is - unclean shutdown */
if (node_status != NODE_STATUS_UP)
{
node_status = NODE_STATUS_UNCLEAN_SHUTDOWN;
}
}
checkPoint = get_latest_checkpoint_location(config_file_options.data_directory);
/* unable to read pg_control, don't know what's happening */
if (checkPoint == InvalidXLogRecPtr)
{
appendPQExpBuffer(&output, "UNKNOWN");
is_shutdown = false;
node_status = NODE_STATUS_UNKNOWN;
}
/* server is running in some state - just output --status */
if (is_shutdown == false)
/* if still "UNKNOWN" at this point, then the node must be cleanly shut down */
else if (node_status == NODE_STATUS_UNKNOWN)
{
printf("%s\n", output.data);
termPQExpBuffer(&output);
return;
node_status = NODE_STATUS_DOWN;
}
appendPQExpBuffer(&output,
"SHUTDOWN --last-checkpoint-lsn=%X/%X",
format_lsn(checkPoint));
switch (node_status)
{
case NODE_STATUS_UP:
appendPQExpBuffer(&output, "RUNNING");
break;
case NODE_STATUS_UNCLEAN_SHUTDOWN:
appendPQExpBuffer(&output, "UNCLEAN_SHUTDOWN");
break;
case NODE_STATUS_DOWN:
appendPQExpBuffer(&output,
"SHUTDOWN --last-checkpoint-lsn=%X/%X",
format_lsn(checkPoint));
break;
case NODE_STATUS_UNKNOWN:
appendPQExpBuffer(&output, "UNKNOWN");
break;
}
printf("%s\n", output.data);
termPQExpBuffer(&output);

View File

@@ -83,7 +83,7 @@ static void get_barman_property(char *dst, char *name, char *local_repmgr_direct
static int get_tablespace_data_barman(char *, TablespaceDataList *);
static char *make_barman_ssh_command(char *buf);
static NodeStatus parse_node_status_is_shutdown(const char *node_status_output, XLogRecPtr *checkPoint);
static NodeStatus parse_node_status_is_shutdown_cleanly(const char *node_status_output, XLogRecPtr *checkPoint);
static CheckStatus parse_node_check_archiver(const char *node_check_output, int *files, int *threshold);
static CheckStatus parse_node_check_replication_lag(const char *node_check_output, int *seconds, int *threshold);
@@ -2579,7 +2579,7 @@ do_standby_switchover(void)
/* database server could not be contacted */
if (ping_res == PQPING_NO_RESPONSE ||PQPING_NO_ATTEMPT)
if (ping_res == PQPING_NO_RESPONSE || ping_res == PQPING_NO_ATTEMPT)
{
bool command_success;
@@ -2593,7 +2593,7 @@ do_standby_switchover(void)
initPQExpBuffer(&remote_command_str);
make_remote_repmgr_path(&remote_command_str, &remote_node_record);
appendPQExpBuffer(&remote_command_str,
"node status --is-shutdown");
"node status --is-shutdown--cleanly");
initPQExpBuffer(&command_output);
@@ -2607,12 +2607,12 @@ do_standby_switchover(void)
if (command_success == true)
{
NodeStatus status = parse_node_status_is_shutdown(command_output.data, &remote_last_checkpoint_lsn);
NodeStatus status = parse_node_status_is_shutdown_cleanly(command_output.data, &remote_last_checkpoint_lsn);
if (status == NODE_STATUS_DOWN && remote_last_checkpoint_lsn != InvalidXLogRecPtr)
{
shutdown_success = true;
log_notice(_("current primary has been shut down at location %X/%X"),
log_notice(_("current primary has been cleanly shut down at location %X/%X"),
format_lsn(remote_last_checkpoint_lsn));
termPQExpBuffer(&command_output);
@@ -4641,7 +4641,7 @@ drop_replication_slot_if_exists(PGconn *conn, int node_id, char *slot_name)
/* TODO: consolidate code in below functions */
static NodeStatus
parse_node_status_is_shutdown(const char *node_status_output, XLogRecPtr *checkPoint)
parse_node_status_is_shutdown_cleanly(const char *node_status_output, XLogRecPtr *checkPoint)
{
int options_len = 0;
char *options_string = NULL;
@@ -4749,6 +4749,10 @@ parse_node_status_is_shutdown(const char *node_status_output, XLogRecPtr *checkP
{
node_status = NODE_STATUS_DOWN;
}
else if (strncmp(optarg, "UNCLEAN_SHUTDOWN", MAXLEN) == 0)
{
node_status = NODE_STATUS_UNCLEAN_SHUTDOWN;
}
else if (strncmp(optarg, "UNKNOWN", MAXLEN) == 0)
{
node_status = NODE_STATUS_UNKNOWN;

View File

@@ -80,7 +80,7 @@ typedef struct
bool siblings_follow;
/* "node status" options */
bool is_shutdown;
bool is_shutdown_cleanly;
/* "node check" options */
bool archive_ready;

View File

@@ -382,8 +382,8 @@ main(int argc, char **argv)
/* "node status" options *
* --------------------- */
case OPT_IS_SHUTDOWN:
runtime_options.is_shutdown = true;
case OPT_IS_SHUTDOWN_CLEANLY:
runtime_options.is_shutdown_cleanly = true;
break;
/* "node check" options *
@@ -1448,8 +1448,8 @@ check_cli_parameters(const int action)
}
}
/* repmgr node status --is-shutdown */
if (runtime_options.is_shutdown == true)
/* repmgr node status --is-shutdown-cleanly */
if (runtime_options.is_shutdown_cleanly == true)
{
switch (action)
{
@@ -1458,7 +1458,7 @@ check_cli_parameters(const int action)
default:
item_list_append_format(
&cli_warnings,
_("--is-shutdown will be ignored when executing %s"),
_("--is-shutdown-cleanly will be ignored when executing %s"),
action_name(action));
}
}

View File

@@ -59,7 +59,7 @@
#define OPT_LIST_ACTIONS 1025
#define OPT_CHECK 1026
#define OPT_CHECKPOINT 1027
#define OPT_IS_SHUTDOWN 1028
#define OPT_IS_SHUTDOWN_CLEANLY 1028
#define OPT_ALWAYS_PROMOTE 1029
#define OPT_FORCE_REWIND 1030
#define OPT_NAGIOS 1031
@@ -133,7 +133,7 @@ static struct option long_options[] =
{"siblings-follow", no_argument, NULL, OPT_SIBLINGS_FOLLOW },
/* "node status" options */
{"is-shutdown", no_argument, NULL, OPT_IS_SHUTDOWN },
{"is-shutdown-cleanly", no_argument, NULL, OPT_IS_SHUTDOWN_CLEANLY },
/* "node check" options */
{"archive-ready", no_argument, NULL, OPT_ARCHIVE_READY },