mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16:29 +00:00
repmgr: clean up runtime options structure
Place elements in a sensible order and split the associated initializer macro over multiple lines for easier editing. Also move a few related global variables into to the structure to keep everything in the same place.
This commit is contained in:
54
repmgr.c
54
repmgr.c
@@ -178,12 +178,6 @@ static bool config_file_required = true;
|
|||||||
t_runtime_options runtime_options = T_RUNTIME_OPTIONS_INITIALIZER;
|
t_runtime_options runtime_options = T_RUNTIME_OPTIONS_INITIALIZER;
|
||||||
t_configuration_options options = T_CONFIGURATION_OPTIONS_INITIALIZER;
|
t_configuration_options options = T_CONFIGURATION_OPTIONS_INITIALIZER;
|
||||||
|
|
||||||
static bool wal_keep_segments_used = false;
|
|
||||||
static bool conninfo_provided = false;
|
|
||||||
static bool connection_param_provided = false;
|
|
||||||
static bool host_param_provided = false;
|
|
||||||
static bool pg_rewind_supplied = false;
|
|
||||||
|
|
||||||
static char *server_mode = NULL;
|
static char *server_mode = NULL;
|
||||||
static char *server_cmd = NULL;
|
static char *server_cmd = NULL;
|
||||||
|
|
||||||
@@ -365,13 +359,13 @@ main(int argc, char **argv)
|
|||||||
case 'd':
|
case 'd':
|
||||||
strncpy(runtime_options.dbname, optarg, MAXLEN);
|
strncpy(runtime_options.dbname, optarg, MAXLEN);
|
||||||
/* we'll set the dbname parameter below if we detect it's not a conninfo string */
|
/* we'll set the dbname parameter below if we detect it's not a conninfo string */
|
||||||
connection_param_provided = true;
|
runtime_options.connection_param_provided = true;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
strncpy(runtime_options.host, optarg, MAXLEN);
|
strncpy(runtime_options.host, optarg, MAXLEN);
|
||||||
param_set(&source_conninfo, "host", optarg);
|
param_set(&source_conninfo, "host", optarg);
|
||||||
connection_param_provided = true;
|
runtime_options.connection_param_provided = true;
|
||||||
host_param_provided = true;
|
runtime_options.host_param_provided = true;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
repmgr_atoi(optarg, "-p/--port", &cli_errors, false);
|
repmgr_atoi(optarg, "-p/--port", &cli_errors, false);
|
||||||
@@ -379,12 +373,12 @@ main(int argc, char **argv)
|
|||||||
strncpy(runtime_options.masterport,
|
strncpy(runtime_options.masterport,
|
||||||
optarg,
|
optarg,
|
||||||
MAXLEN);
|
MAXLEN);
|
||||||
connection_param_provided = true;
|
runtime_options.connection_param_provided = true;
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
strncpy(runtime_options.username, optarg, MAXLEN);
|
strncpy(runtime_options.username, optarg, MAXLEN);
|
||||||
param_set(&source_conninfo, "user", optarg);
|
param_set(&source_conninfo, "user", optarg);
|
||||||
connection_param_provided = true;
|
runtime_options.connection_param_provided = true;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
strncpy(runtime_options.superuser, optarg, MAXLEN);
|
strncpy(runtime_options.superuser, optarg, MAXLEN);
|
||||||
@@ -403,7 +397,7 @@ main(int argc, char **argv)
|
|||||||
strncpy(runtime_options.wal_keep_segments,
|
strncpy(runtime_options.wal_keep_segments,
|
||||||
optarg,
|
optarg,
|
||||||
MAXLEN);
|
MAXLEN);
|
||||||
wal_keep_segments_used = true;
|
runtime_options.wal_keep_segments_used = true;
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
runtime_options.keep_history = repmgr_atoi(optarg, "-k/--keep-history", &cli_errors, false);
|
runtime_options.keep_history = repmgr_atoi(optarg, "-k/--keep-history", &cli_errors, false);
|
||||||
@@ -519,7 +513,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
strncpy(runtime_options.pg_rewind, optarg, MAXPGPATH);
|
strncpy(runtime_options.pg_rewind, optarg, MAXPGPATH);
|
||||||
}
|
}
|
||||||
pg_rewind_supplied = true;
|
runtime_options.pg_rewind_supplied = true;
|
||||||
break;
|
break;
|
||||||
case OPT_PWPROMPT:
|
case OPT_PWPROMPT:
|
||||||
runtime_options.witness_pwprompt = true;
|
runtime_options.witness_pwprompt = true;
|
||||||
@@ -586,7 +580,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
char *errmsg = NULL;
|
char *errmsg = NULL;
|
||||||
|
|
||||||
conninfo_provided = true;
|
runtime_options.conninfo_provided = true;
|
||||||
|
|
||||||
opts = PQconninfoParse(runtime_options.dbname, &errmsg);
|
opts = PQconninfoParse(runtime_options.dbname, &errmsg);
|
||||||
|
|
||||||
@@ -620,13 +614,13 @@ main(int argc, char **argv)
|
|||||||
(opt->val != NULL && opt->val[0] != '\0'))
|
(opt->val != NULL && opt->val[0] != '\0'))
|
||||||
{
|
{
|
||||||
strncpy(runtime_options.host, opt->val, MAXLEN);
|
strncpy(runtime_options.host, opt->val, MAXLEN);
|
||||||
host_param_provided = true;
|
runtime_options.host_param_provided = true;
|
||||||
}
|
}
|
||||||
if (strcmp(opt->keyword, "hostaddr") == 0 &&
|
if (strcmp(opt->keyword, "hostaddr") == 0 &&
|
||||||
(opt->val != NULL && opt->val[0] != '\0'))
|
(opt->val != NULL && opt->val[0] != '\0'))
|
||||||
{
|
{
|
||||||
strncpy(runtime_options.host, opt->val, MAXLEN);
|
strncpy(runtime_options.host, opt->val, MAXLEN);
|
||||||
host_param_provided = true;
|
runtime_options.host_param_provided = true;
|
||||||
}
|
}
|
||||||
else if (strcmp(opt->keyword, "port") == 0 &&
|
else if (strcmp(opt->keyword, "port") == 0 &&
|
||||||
(opt->val != NULL && opt->val[0] != '\0'))
|
(opt->val != NULL && opt->val[0] != '\0'))
|
||||||
@@ -762,7 +756,7 @@ main(int argc, char **argv)
|
|||||||
initPQExpBuffer(&additional_host_arg);
|
initPQExpBuffer(&additional_host_arg);
|
||||||
appendPQExpBuffer(&additional_host_arg,
|
appendPQExpBuffer(&additional_host_arg,
|
||||||
_("Conflicting parameters: you can't use %s while providing a node separately."),
|
_("Conflicting parameters: you can't use %s while providing a node separately."),
|
||||||
conninfo_provided == true ? "host=" : "-h/--host");
|
runtime_options.conninfo_provided == true ? "host=" : "-h/--host");
|
||||||
item_list_append(&cli_errors, additional_host_arg.data);
|
item_list_append(&cli_errors, additional_host_arg.data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -884,7 +878,7 @@ main(int argc, char **argv)
|
|||||||
* the version check for 9.4 or later is done in check_upstream_config()
|
* the version check for 9.4 or later is done in check_upstream_config()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (options.use_replication_slots && wal_keep_segments_used)
|
if (options.use_replication_slots && runtime_options.wal_keep_segments_used)
|
||||||
{
|
{
|
||||||
log_warning(_("-w/--wal-keep-segments has no effect when replication slots in use\n"));
|
log_warning(_("-w/--wal-keep-segments has no effect when replication slots in use\n"));
|
||||||
}
|
}
|
||||||
@@ -4268,7 +4262,7 @@ do_standby_follow(void)
|
|||||||
* to determine primary, and carry out some other checks while we're
|
* to determine primary, and carry out some other checks while we're
|
||||||
* at it.
|
* at it.
|
||||||
*/
|
*/
|
||||||
if (host_param_provided == false)
|
if (runtime_options.host_param_provided == false)
|
||||||
{
|
{
|
||||||
/* We need to connect to check configuration */
|
/* We need to connect to check configuration */
|
||||||
log_info(_("connecting to standby database\n"));
|
log_info(_("connecting to standby database\n"));
|
||||||
@@ -4562,7 +4556,7 @@ do_standby_switchover(void)
|
|||||||
* Add a friendly notice if --pg_rewind supplied for 9.5 and later - we'll
|
* Add a friendly notice if --pg_rewind supplied for 9.5 and later - we'll
|
||||||
* be ignoring it anyway
|
* be ignoring it anyway
|
||||||
*/
|
*/
|
||||||
if (pg_rewind_supplied == true && server_version_num >= 90500)
|
if (runtime_options.pg_rewind_supplied == true && server_version_num >= 90500)
|
||||||
{
|
{
|
||||||
log_notice(_("--pg_rewind not required for PostgreSQL 9.5 and later\n"));
|
log_notice(_("--pg_rewind not required for PostgreSQL 9.5 and later\n"));
|
||||||
}
|
}
|
||||||
@@ -4677,7 +4671,7 @@ do_standby_switchover(void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 9.3/9.4 - user can use separately-compiled pg_rewind */
|
/* 9.3/9.4 - user can use separately-compiled pg_rewind */
|
||||||
if (pg_rewind_supplied == true)
|
if (runtime_options.pg_rewind_supplied == true)
|
||||||
{
|
{
|
||||||
use_pg_rewind = true;
|
use_pg_rewind = true;
|
||||||
|
|
||||||
@@ -6574,7 +6568,7 @@ run_basebackup(const char *data_dir, int server_version)
|
|||||||
* consistency with other applications accepts a conninfo string
|
* consistency with other applications accepts a conninfo string
|
||||||
* under -d/--dbname)
|
* under -d/--dbname)
|
||||||
*/
|
*/
|
||||||
if (conninfo_provided == true)
|
if (runtime_options.conninfo_provided == true)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(¶ms, " -d '%s'", runtime_options.dbname);
|
appendPQExpBuffer(¶ms, " -d '%s'", runtime_options.dbname);
|
||||||
}
|
}
|
||||||
@@ -6695,7 +6689,7 @@ check_parameters_for_action(const int action)
|
|||||||
* parameters are at least useless and could be confusing so
|
* parameters are at least useless and could be confusing so
|
||||||
* reject them
|
* reject them
|
||||||
*/
|
*/
|
||||||
if (connection_param_provided)
|
if (runtime_options.connection_param_provided)
|
||||||
{
|
{
|
||||||
item_list_append(&cli_warnings, _("master connection parameters not required when executing MASTER REGISTER"));
|
item_list_append(&cli_warnings, _("master connection parameters not required when executing MASTER REGISTER"));
|
||||||
}
|
}
|
||||||
@@ -6712,7 +6706,7 @@ check_parameters_for_action(const int action)
|
|||||||
* need connection parameters to the master because we can detect
|
* need connection parameters to the master because we can detect
|
||||||
* the master in repl_nodes
|
* the master in repl_nodes
|
||||||
*/
|
*/
|
||||||
if (connection_param_provided)
|
if (runtime_options.connection_param_provided)
|
||||||
{
|
{
|
||||||
item_list_append(&cli_warnings, _("master connection parameters not required when executing STANDBY REGISTER"));
|
item_list_append(&cli_warnings, _("master connection parameters not required when executing STANDBY REGISTER"));
|
||||||
}
|
}
|
||||||
@@ -6729,7 +6723,7 @@ check_parameters_for_action(const int action)
|
|||||||
* need connection parameters to the master because we can detect
|
* need connection parameters to the master because we can detect
|
||||||
* the master in repl_nodes
|
* the master in repl_nodes
|
||||||
*/
|
*/
|
||||||
if (connection_param_provided)
|
if (runtime_options.connection_param_provided)
|
||||||
{
|
{
|
||||||
item_list_append(&cli_warnings, _("master connection parameters not required when executing STANDBY UNREGISTER"));
|
item_list_append(&cli_warnings, _("master connection parameters not required when executing STANDBY UNREGISTER"));
|
||||||
}
|
}
|
||||||
@@ -6747,7 +6741,7 @@ check_parameters_for_action(const int action)
|
|||||||
* detect the master in repl_nodes if we can't find it then the
|
* detect the master in repl_nodes if we can't find it then the
|
||||||
* promote action will be cancelled
|
* promote action will be cancelled
|
||||||
*/
|
*/
|
||||||
if (connection_param_provided)
|
if (runtime_options.connection_param_provided)
|
||||||
{
|
{
|
||||||
item_list_append(&cli_warnings, _("master connection parameters not required when executing STANDBY PROMOTE"));
|
item_list_append(&cli_warnings, _("master connection parameters not required when executing STANDBY PROMOTE"));
|
||||||
}
|
}
|
||||||
@@ -6773,7 +6767,7 @@ check_parameters_for_action(const int action)
|
|||||||
item_list_append(&cli_errors, _("master hostname (-h/--host) required when executing STANDBY FOLLOW with -D/--data-dir option"));
|
item_list_append(&cli_errors, _("master hostname (-h/--host) required when executing STANDBY FOLLOW with -D/--data-dir option"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host_param_provided && !runtime_options.dest_dir[0])
|
if (runtime_options.host_param_provided && !runtime_options.dest_dir[0])
|
||||||
{
|
{
|
||||||
item_list_append(&cli_errors, _("local data directory (-D/--data-dir) required when executing STANDBY FOLLOW with -h/--host option"));
|
item_list_append(&cli_errors, _("local data directory (-D/--data-dir) required when executing STANDBY FOLLOW with -h/--host option"));
|
||||||
}
|
}
|
||||||
@@ -6883,7 +6877,7 @@ check_parameters_for_action(const int action)
|
|||||||
item_list_append(&cli_warnings, _("-r/--rsync-only can only be used when executing STANDBY CLONE"));
|
item_list_append(&cli_warnings, _("-r/--rsync-only can only be used when executing STANDBY CLONE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wal_keep_segments_used)
|
if (runtime_options.wal_keep_segments_used)
|
||||||
{
|
{
|
||||||
item_list_append(&cli_warnings, _("-w/--wal-keep-segments can only be used when executing STANDBY CLONE"));
|
item_list_append(&cli_warnings, _("-w/--wal-keep-segments can only be used when executing STANDBY CLONE"));
|
||||||
}
|
}
|
||||||
@@ -6906,7 +6900,7 @@ check_parameters_for_action(const int action)
|
|||||||
/* Warn about parameters which apply to STANDBY SWITCHOVER only */
|
/* Warn about parameters which apply to STANDBY SWITCHOVER only */
|
||||||
if (action != STANDBY_SWITCHOVER)
|
if (action != STANDBY_SWITCHOVER)
|
||||||
{
|
{
|
||||||
if (pg_rewind_supplied == true)
|
if (runtime_options.pg_rewind_supplied == true)
|
||||||
{
|
{
|
||||||
item_list_append(&cli_warnings, _("--pg_rewind can only be used when executing STANDBY SWITCHOVER"));
|
item_list_append(&cli_warnings, _("--pg_rewind can only be used when executing STANDBY SWITCHOVER"));
|
||||||
}
|
}
|
||||||
@@ -7455,7 +7449,7 @@ check_upstream_config(PGconn *conn, int server_version_num, bool exit_on_error)
|
|||||||
/*
|
/*
|
||||||
* -w/--wal-keep-segments was supplied - check against that value
|
* -w/--wal-keep-segments was supplied - check against that value
|
||||||
*/
|
*/
|
||||||
if (wal_keep_segments_used == true)
|
if (runtime_options.wal_keep_segments_used == true)
|
||||||
{
|
{
|
||||||
check_wal_keep_segments = true;
|
check_wal_keep_segments = true;
|
||||||
strncpy(min_wal_keep_segments, runtime_options.wal_keep_segments, MAXLEN);
|
strncpy(min_wal_keep_segments, runtime_options.wal_keep_segments, MAXLEN);
|
||||||
|
|||||||
100
repmgr.h
100
repmgr.h
@@ -64,9 +64,10 @@
|
|||||||
#define OPT_CLUSTER 13
|
#define OPT_CLUSTER 13
|
||||||
|
|
||||||
/* deprecated command line options */
|
/* deprecated command line options */
|
||||||
#define OPT_INITDB_NO_PWPROMPT 999
|
#define OPT_INITDB_NO_PWPROMPT 998
|
||||||
#define OPT_IGNORE_EXTERNAL_CONFIG_FILES 998
|
#define OPT_IGNORE_EXTERNAL_CONFIG_FILES 999
|
||||||
|
|
||||||
|
/* values for --copy-external-config-files */
|
||||||
#define CONFIG_FILE_SAMEPATH 1
|
#define CONFIG_FILE_SAMEPATH 1
|
||||||
#define CONFIG_FILE_PGDATA 2
|
#define CONFIG_FILE_PGDATA 2
|
||||||
|
|
||||||
@@ -74,53 +75,94 @@
|
|||||||
/* Run time options type */
|
/* Run time options type */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
/* general repmgr options */
|
||||||
|
char config_file[MAXPGPATH];
|
||||||
|
bool verbose;
|
||||||
|
bool terse;
|
||||||
|
bool force;
|
||||||
|
|
||||||
|
/* options which override setting in repmgr.conf */
|
||||||
|
char loglevel[MAXLEN];
|
||||||
|
char pg_bindir[MAXLEN];
|
||||||
|
|
||||||
|
/* connection parameters */
|
||||||
char dbname[MAXLEN];
|
char dbname[MAXLEN];
|
||||||
char host[MAXLEN];
|
char host[MAXLEN];
|
||||||
char username[MAXLEN];
|
char username[MAXLEN];
|
||||||
char dest_dir[MAXPGPATH];
|
char dest_dir[MAXPGPATH];
|
||||||
char config_file[MAXPGPATH];
|
|
||||||
char remote_user[MAXLEN];
|
char remote_user[MAXLEN];
|
||||||
char superuser[MAXLEN];
|
char superuser[MAXLEN];
|
||||||
|
char masterport[MAXLEN];
|
||||||
|
bool conninfo_provided;
|
||||||
|
bool connection_param_provided;
|
||||||
|
bool host_param_provided;
|
||||||
|
|
||||||
|
/* standby clone parameters */
|
||||||
|
bool wal_keep_segments_used;
|
||||||
char wal_keep_segments[MAXLEN];
|
char wal_keep_segments[MAXLEN];
|
||||||
bool verbose;
|
|
||||||
bool terse;
|
|
||||||
bool force;
|
|
||||||
bool wait_for_master;
|
|
||||||
bool ignore_rsync_warn;
|
bool ignore_rsync_warn;
|
||||||
bool witness_pwprompt;
|
|
||||||
bool rsync_only;
|
bool rsync_only;
|
||||||
bool fast_checkpoint;
|
bool fast_checkpoint;
|
||||||
bool csv_mode;
|
|
||||||
bool without_barman;
|
bool without_barman;
|
||||||
bool no_upstream_connection;
|
bool no_upstream_connection;
|
||||||
bool copy_external_config_files;
|
bool copy_external_config_files;
|
||||||
int copy_external_config_files_destination;
|
int copy_external_config_files_destination;
|
||||||
bool wait_register_sync;
|
bool wait_register_sync;
|
||||||
int wait_register_sync_seconds;
|
int wait_register_sync_seconds;
|
||||||
char masterport[MAXLEN];
|
|
||||||
/*
|
|
||||||
* configuration file parameters which can be overridden on the
|
|
||||||
* command line
|
|
||||||
*/
|
|
||||||
char loglevel[MAXLEN];
|
|
||||||
|
|
||||||
/* parameter used by STANDBY SWITCHOVER */
|
|
||||||
char remote_config_file[MAXLEN];
|
|
||||||
char pg_rewind[MAXPGPATH];
|
|
||||||
char pg_ctl_mode[MAXLEN];
|
|
||||||
/* parameter used by STANDBY {ARCHIVE_CONFIG | RESTORE_CONFIG} */
|
|
||||||
char config_archive_dir[MAXLEN];
|
|
||||||
/* parameter used by CLUSTER CLEANUP */
|
|
||||||
int keep_history;
|
|
||||||
/* parameter used by {STANDBY|WITNESS} UNREGISTER */
|
|
||||||
int node;
|
|
||||||
|
|
||||||
char pg_bindir[MAXLEN];
|
|
||||||
|
|
||||||
char recovery_min_apply_delay[MAXLEN];
|
char recovery_min_apply_delay[MAXLEN];
|
||||||
|
|
||||||
|
/* witness create parameters */
|
||||||
|
bool witness_pwprompt;
|
||||||
|
|
||||||
|
/* standby follow parameters */
|
||||||
|
bool wait_for_master;
|
||||||
|
|
||||||
|
/* cluster {show|matrix|crosscheck} parameters */
|
||||||
|
bool csv_mode;
|
||||||
|
|
||||||
|
/* cluster cleanup parameters */
|
||||||
|
int keep_history;
|
||||||
|
|
||||||
|
/* standby switchover parameters */
|
||||||
|
char remote_config_file[MAXLEN];
|
||||||
|
bool pg_rewind_supplied;
|
||||||
|
char pg_rewind[MAXPGPATH];
|
||||||
|
char pg_ctl_mode[MAXLEN];
|
||||||
|
|
||||||
|
/* standby {archive_config | restore_config} parameters */
|
||||||
|
char config_archive_dir[MAXLEN];
|
||||||
|
|
||||||
|
/* {standby|witness} unregister parameters */
|
||||||
|
int node;
|
||||||
|
|
||||||
} t_runtime_options;
|
} t_runtime_options;
|
||||||
|
|
||||||
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, false, false, false, false, false, false, false, false, CONFIG_FILE_SAMEPATH, false, 0, "", "", "", "", "fast", "", 0, UNKNOWN_NODE_ID, "", ""}
|
#define T_RUNTIME_OPTIONS_INITIALIZER { \
|
||||||
|
/* general repmgr options */ \
|
||||||
|
"", false, false, false, \
|
||||||
|
/* options which override setting in repmgr.conf */ \
|
||||||
|
"", "", \
|
||||||
|
/* connection parameters */ \
|
||||||
|
"", "", "", "", "", "", "", \
|
||||||
|
false, false, false, \
|
||||||
|
/* standby clone parameters */ \
|
||||||
|
false, DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, false, false, \
|
||||||
|
CONFIG_FILE_SAMEPATH, false, 0, "", \
|
||||||
|
/* witness create parameters */ \
|
||||||
|
false, \
|
||||||
|
/* standby follow parameters */ \
|
||||||
|
false, \
|
||||||
|
/* cluster {show|matrix|crosscheck} parameters */ \
|
||||||
|
false, \
|
||||||
|
/* cluster cleanup parameters */ \
|
||||||
|
0, \
|
||||||
|
/* standby switchover parameters */ \
|
||||||
|
"", false, "", "fast", \
|
||||||
|
/* standby {archive_config | restore_config} parameters */ \
|
||||||
|
"", \
|
||||||
|
/* {standby|witness} unregister parameters */ \
|
||||||
|
UNKNOWN_NODE_ID }
|
||||||
|
|
||||||
struct BackupLabel
|
struct BackupLabel
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user