mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
repmgr standby follow: initial code
This commit is contained in:
@@ -950,7 +950,7 @@ get_master_connection(PGconn *conn,
|
|||||||
node_id = atoi(PQgetvalue(res, i, 0));
|
node_id = atoi(PQgetvalue(res, i, 0));
|
||||||
strncpy(remote_conninfo, PQgetvalue(res, i, 1), MAXCONNINFO);
|
strncpy(remote_conninfo, PQgetvalue(res, i, 1), MAXCONNINFO);
|
||||||
log_verbose(LOG_INFO,
|
log_verbose(LOG_INFO,
|
||||||
_("checking role of cluster node '%i'"),
|
_("checking role of node '%i'"),
|
||||||
node_id);
|
node_id);
|
||||||
remote_conn = establish_db_connection(remote_conninfo, false);
|
remote_conn = establish_db_connection(remote_conninfo, false);
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ static void check_barman_config(void);
|
|||||||
static void check_source_server(void);
|
static void check_source_server(void);
|
||||||
static void check_source_server_via_barman(void);
|
static void check_source_server_via_barman(void);
|
||||||
static void check_master_standby_version_match(PGconn *conn, PGconn *master_conn);
|
static void check_master_standby_version_match(PGconn *conn, PGconn *master_conn);
|
||||||
|
static void check_recovery_type(PGconn *conn);
|
||||||
|
|
||||||
static void initialise_direct_clone(void);
|
static void initialise_direct_clone(void);
|
||||||
static void config_file_list_init(t_configfile_list *list, int max_size);
|
static void config_file_list_init(t_configfile_list *list, int max_size);
|
||||||
@@ -589,25 +589,7 @@ do_standby_register(void)
|
|||||||
|
|
||||||
if (PQstatus(conn) == CONNECTION_OK)
|
if (PQstatus(conn) == CONNECTION_OK)
|
||||||
{
|
{
|
||||||
t_recovery_type recovery_type = get_recovery_type(conn);
|
check_recovery_type(conn);
|
||||||
|
|
||||||
if (recovery_type != RECTYPE_STANDBY)
|
|
||||||
{
|
|
||||||
if (recovery_type == RECTYPE_MASTER)
|
|
||||||
{
|
|
||||||
log_error(_("this node should be a standby (%s)"),
|
|
||||||
config_file_options.conninfo);
|
|
||||||
PQfinish(conn);
|
|
||||||
exit(ERR_BAD_CONFIG);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log_error(_("connection to node (%s) lost"),
|
|
||||||
config_file_options.conninfo);
|
|
||||||
PQfinish(conn);
|
|
||||||
exit(ERR_DB_CONN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if there is a master in this cluster */
|
/* check if there is a master in this cluster */
|
||||||
@@ -1227,10 +1209,82 @@ do_standby_promote(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Follow a new primary.
|
||||||
|
*
|
||||||
|
* This function has two "modes":
|
||||||
|
* 1) no primary info provided - determine primary from standby metadata
|
||||||
|
* 2) primary info provided - use that info to connect to the primary.
|
||||||
|
*
|
||||||
|
* (2) is mainly for when a node has been stopped as part of a switchover
|
||||||
|
* and needs to be started with recovery.conf correctly configured.
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
do_standby_follow(void)
|
do_standby_follow(void)
|
||||||
{
|
{
|
||||||
puts("not implemented");
|
PGconn *local_conn;
|
||||||
|
char data_dir[MAXPGPATH];
|
||||||
|
|
||||||
|
log_verbose(LOG_DEBUG, "do_standby_follow()");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If -h/--host wasn't provided, attempt to connect to standby
|
||||||
|
* to determine primary, and carry out some other checks while we're
|
||||||
|
* at it.
|
||||||
|
*/
|
||||||
|
if (runtime_options.host_param_provided == false)
|
||||||
|
{
|
||||||
|
bool success;
|
||||||
|
PGconn *master_conn = NULL;
|
||||||
|
char master_conninfo[MAXLEN];
|
||||||
|
int master_id = UNKNOWN_NODE_ID;
|
||||||
|
int timer;
|
||||||
|
|
||||||
|
local_conn = establish_db_connection(config_file_options.conninfo, true);
|
||||||
|
|
||||||
|
log_verbose(LOG_INFO, _("connected to local node"));
|
||||||
|
|
||||||
|
check_recovery_type(local_conn);
|
||||||
|
|
||||||
|
success = get_pg_setting(local_conn, "data_directory", data_dir);
|
||||||
|
|
||||||
|
if (success == false)
|
||||||
|
{
|
||||||
|
log_error(_("unable to determine data directory"));
|
||||||
|
PQfinish(local_conn);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Attempt to connect to master.
|
||||||
|
*
|
||||||
|
* If --wait provided, loop for up `master_response_timeout`
|
||||||
|
* seconds before giving up
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (timer = 0; timer < config_file_options.master_response_timeout; timer++)
|
||||||
|
{
|
||||||
|
master_conn = get_master_connection(local_conn,
|
||||||
|
&master_id,
|
||||||
|
(char *) &master_conninfo);
|
||||||
|
|
||||||
|
if (PQstatus(master_conn) == CONNECTION_OK || runtime_options.wait == false)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
|
{
|
||||||
|
log_error(_("unable to determine master node"));
|
||||||
|
PQfinish(local_conn);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("OK");
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2669,3 +2723,28 @@ check_master_standby_version_match(PGconn *conn, PGconn *master_conn)
|
|||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_recovery_type(PGconn *conn)
|
||||||
|
{
|
||||||
|
t_recovery_type recovery_type = get_recovery_type(conn);
|
||||||
|
|
||||||
|
if (recovery_type != RECTYPE_STANDBY)
|
||||||
|
{
|
||||||
|
if (recovery_type == RECTYPE_MASTER)
|
||||||
|
{
|
||||||
|
log_error(_("this node should be a standby (%s)"),
|
||||||
|
config_file_options.conninfo);
|
||||||
|
PQfinish(conn);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log_error(_("connection to node (%s) lost"),
|
||||||
|
config_file_options.conninfo);
|
||||||
|
PQfinish(conn);
|
||||||
|
exit(ERR_DB_CONN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ typedef struct
|
|||||||
bool dry_run;
|
bool dry_run;
|
||||||
bool force;
|
bool force;
|
||||||
char pg_bindir[MAXLEN]; /* overrides setting in repmgr.conf */
|
char pg_bindir[MAXLEN]; /* overrides setting in repmgr.conf */
|
||||||
|
bool wait;
|
||||||
|
|
||||||
/* logging options */
|
/* logging options */
|
||||||
char loglevel[MAXLEN]; /* overrides setting in repmgr.conf */
|
char loglevel[MAXLEN]; /* overrides setting in repmgr.conf */
|
||||||
@@ -79,7 +80,7 @@ typedef struct
|
|||||||
/* configuration metadata */ \
|
/* configuration metadata */ \
|
||||||
false, false, false, false, false, \
|
false, false, false, false, false, \
|
||||||
/* general configuration options */ \
|
/* general configuration options */ \
|
||||||
"", false, false, "", \
|
"", false, false, "", false, \
|
||||||
/* logging options */ \
|
/* logging options */ \
|
||||||
"", false, false, false, \
|
"", false, false, false, \
|
||||||
/* database connection options */ \
|
/* database connection options */ \
|
||||||
|
|||||||
@@ -204,6 +204,11 @@ main(int argc, char **argv)
|
|||||||
runtime_options.force = true;
|
runtime_options.force = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* -W/--wait */
|
||||||
|
case 'W':
|
||||||
|
runtime_options.wait = true;
|
||||||
|
break;
|
||||||
|
|
||||||
/* database connection options */
|
/* database connection options */
|
||||||
/* --------------------------- */
|
/* --------------------------- */
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ static struct option long_options[] =
|
|||||||
{"dry-run", no_argument, NULL, OPT_DRY_RUN},
|
{"dry-run", no_argument, NULL, OPT_DRY_RUN},
|
||||||
{"force", no_argument, NULL, 'F'},
|
{"force", no_argument, NULL, 'F'},
|
||||||
{"pg_bindir", required_argument, NULL, 'b'},
|
{"pg_bindir", required_argument, NULL, 'b'},
|
||||||
|
{"wait", no_argument, NULL, 'W'},
|
||||||
|
|
||||||
/* connection options */
|
/* connection options */
|
||||||
{"dbname", required_argument, NULL, 'd'},
|
{"dbname", required_argument, NULL, 'd'},
|
||||||
@@ -119,7 +120,6 @@ static struct option long_options[] =
|
|||||||
|
|
||||||
/* not yet handled */
|
/* not yet handled */
|
||||||
{"keep-history", required_argument, NULL, 'k'},
|
{"keep-history", required_argument, NULL, 'k'},
|
||||||
{"wait", no_argument, NULL, 'W'},
|
|
||||||
{"mode", required_argument, NULL, 'm'},
|
{"mode", required_argument, NULL, 'm'},
|
||||||
{"remote-config-file", required_argument, NULL, 'C'},
|
{"remote-config-file", required_argument, NULL, 'C'},
|
||||||
{"check-upstream-config", no_argument, NULL, OPT_CHECK_UPSTREAM_CONFIG},
|
{"check-upstream-config", no_argument, NULL, OPT_CHECK_UPSTREAM_CONFIG},
|
||||||
|
|||||||
Reference in New Issue
Block a user