Use "primary" instead of "master"

This commit is contained in:
Ian Barwick
2017-06-23 21:33:54 +09:00
parent 28808a02ab
commit 46c956e61a
14 changed files with 382 additions and 380 deletions

View File

@@ -26,7 +26,7 @@ include Makefile.global
$(info Building against PostgreSQL $(MAJORVERSION))
REPMGR_CLIENT_OBJS = repmgr-client.o repmgr-action-master.o repmgr-action-standby.o repmgr-action-cluster.o \
REPMGR_CLIENT_OBJS = repmgr-client.o repmgr-action-primary.o repmgr-action-standby.o repmgr-action-cluster.o \
config.o log.o strutil.o dbutils.o dirutil.o compat.o controldata.o
REPMGRD_OBJS = repmgrd.o config.o log.o dbutils.o strutil.o
@@ -53,7 +53,7 @@ maintainer-clean: additional-maintainer-clean
additional-clean:
rm -f repmgr-client.o
rm -f repmgr-action-cluster.o
rm -f repmgr-action-master.o
rm -f repmgr-action-primary.o
rm -f repmgr-action-standby.o
rm -f repmgrd.o
rm -f compat.o

View File

@@ -10,7 +10,8 @@ operations.
`repmgr 4` is a complete rewrite of the existing `repmgr` codebase.
Supports PostgreSQL 9.3 and later.
Supports PostgreSQL 9.6 and later; support for 9.3 will be dropped, 9.4/9.5
may be supported if feasible.
Building from source
--------------------
@@ -27,8 +28,8 @@ Commands
Currently available:
repmgr master register
repmgr master unregister
repmgr primary register
repmgr primary unregister
repmgr standby clone
repmgr standby register
@@ -45,7 +46,7 @@ Backwards compatibility
See also: doc/changes-in-repmgr4.md
`repmgr` is now implemented as a PostgreSQL extension. NOTE: no need to
install the extension, this will be done automatically by `repmgr master register`.
install the extension, this will be done automatically by `repmgr primary register`.
Metadata tables have been revised and are not backwards-compatible
with 3.x. (however future DDL updates will be easier as they can be

View File

@@ -234,7 +234,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
memset(options->promote_command, 0, sizeof(options->promote_command));
memset(options->follow_command, 0, sizeof(options->follow_command));
options->monitor_interval_secs = 2;
options->master_response_timeout = 60;
options->primary_response_timeout = 60;
/* default to 6 reconnection attempts at intervals of 10 seconds */
options->reconnect_attempts = 6;
options->reconnect_interval = 10;

View File

@@ -77,7 +77,7 @@ typedef struct
char promote_command[MAXLEN];
char follow_command[MAXLEN];
int monitor_interval_secs;
int master_response_timeout;
int primary_response_timeout;
int reconnect_attempts;
int reconnect_interval;
int retry_promote_interval_secs;

114
dbutils.c
View File

@@ -19,7 +19,7 @@ static PGconn *_establish_db_connection(const char *conninfo,
const bool log_notice,
const bool verbose_only);
static PGconn *_get_master_connection(PGconn *standby_conn, int *master_id, char *master_conninfo_out, bool quiet);
static PGconn *_get_primary_connection(PGconn *standby_conn, int *primary_id, char *primary_conninfo_out, bool quiet);
static bool _set_config(PGconn *conn, const char *config_param, const char *sqlquery);
static RecordStatus _get_node_record(PGconn *conn, char *sqlquery, t_node_info *node_info);
@@ -127,20 +127,20 @@ establish_db_connection_quiet(const char *conninfo)
PGconn
*establish_master_db_connection(PGconn *conn,
*establish_primary_db_connection(PGconn *conn,
const bool exit_on_error)
{
t_node_info master_node_info = T_NODE_INFO_INITIALIZER;
bool master_record_found;
t_node_info primary_node_info = T_NODE_INFO_INITIALIZER;
bool primary_record_found;
master_record_found = get_master_node_record(conn, &master_node_info);
primary_record_found = get_primary_node_record(conn, &primary_node_info);
if (master_record_found == false)
if (primary_record_found == false)
{
return NULL;
}
return establish_db_connection(master_node_info.conninfo,
return establish_db_connection(primary_node_info.conninfo,
exit_on_error);
}
@@ -858,7 +858,7 @@ RecoveryType
get_recovery_type(PGconn *conn)
{
PGresult *res;
RecoveryType recovery_type = RECTYPE_MASTER;
RecoveryType recovery_type = RECTYPE_PRIMARY;
char *sqlquery = "SELECT pg_catalog.pg_is_in_recovery()";
@@ -889,13 +889,13 @@ get_recovery_type(PGconn *conn)
* current primary will be returned first, reducing the number of speculative
* connections which need to be made to other nodes.
*
* If master_conninfo_out points to allocated memory of MAXCONNINFO in length,
* If primary_conninfo_out points to allocated memory of MAXCONNINFO in length,
* the primary server's conninfo string will be copied there.
*/
PGconn *
_get_master_connection(PGconn *conn,
int *master_id, char *master_conninfo_out, bool quiet)
_get_primary_connection(PGconn *conn,
int *primary_id, char *primary_conninfo_out, bool quiet)
{
PQExpBufferData query;
@@ -912,12 +912,12 @@ _get_master_connection(PGconn *conn,
* If the caller wanted to get a copy of the connection info string, sub
* out the local stack pointer for the pointer passed by the caller.
*/
if (master_conninfo_out != NULL)
remote_conninfo = master_conninfo_out;
if (primary_conninfo_out != NULL)
remote_conninfo = primary_conninfo_out;
if (master_id != NULL)
if (primary_id != NULL)
{
*master_id = NODE_NOT_FOUND;
*primary_id = NODE_NOT_FOUND;
}
/* find all registered nodes */
@@ -926,12 +926,12 @@ _get_master_connection(PGconn *conn,
initPQExpBuffer(&query);
appendPQExpBuffer(&query,
" SELECT node_id, conninfo, "
" CASE WHEN type = 'master' THEN 1 ELSE 2 END AS type_priority"
" CASE WHEN type = 'primary' THEN 1 ELSE 2 END AS type_priority"
" FROM repmgr.nodes "
" WHERE type != 'witness' "
"ORDER BY active DESC, type_priority, priority, node_id");
log_verbose(LOG_DEBUG, "get_master_connection():\n%s", query.data);
log_verbose(LOG_DEBUG, "get_primary_connection():\n%s", query.data);
res = PQexec(conn, query.data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -978,14 +978,14 @@ _get_master_connection(PGconn *conn,
continue;
}
if (recovery_type == RECTYPE_MASTER)
if (recovery_type == RECTYPE_PRIMARY)
{
PQclear(res);
log_debug(_("get_master_connection(): current master node is %i"), node_id);
log_debug(_("get_primary_connection(): current primary node is %i"), node_id);
if (master_id != NULL)
if (primary_id != NULL)
{
*master_id = node_id;
*primary_id = node_id;
}
return remote_conn;
@@ -999,30 +999,30 @@ _get_master_connection(PGconn *conn,
}
PGconn *
get_master_connection(PGconn *conn,
int *master_id, char *master_conninfo_out)
get_primary_connection(PGconn *conn,
int *primary_id, char *primary_conninfo_out)
{
return _get_master_connection(conn, master_id, master_conninfo_out, false);
return _get_primary_connection(conn, primary_id, primary_conninfo_out, false);
}
PGconn *
get_master_connection_quiet(PGconn *conn,
int *master_id, char *master_conninfo_out)
get_primary_connection_quiet(PGconn *conn,
int *primary_id, char *primary_conninfo_out)
{
return _get_master_connection(conn, master_id, master_conninfo_out, true);
return _get_primary_connection(conn, primary_id, primary_conninfo_out, true);
}
/*
* Return the id of the active master node, or NODE_NOT_FOUND if no
* Return the id of the active primary node, or NODE_NOT_FOUND if no
* record available.
*
* This reports the value stored in the database only and
* does not verify whether the node is actually available
*/
int
get_master_node_id(PGconn *conn)
get_primary_node_id(PGconn *conn)
{
PQExpBufferData query;
PGresult *res;
@@ -1032,10 +1032,10 @@ get_master_node_id(PGconn *conn)
appendPQExpBuffer(&query,
"SELECT node_id "
" FROM repmgr.nodes "
" WHERE type = 'master' "
" WHERE type = 'primary' "
" AND active IS TRUE ");
log_verbose(LOG_DEBUG, "get_master_node_id():\n%s", query.data);
log_verbose(LOG_DEBUG, "get_primary_node_id():\n%s", query.data);
res = PQexec(conn, query.data);
@@ -1043,13 +1043,13 @@ get_master_node_id(PGconn *conn)
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
log_error(_("get_master_node_id(): query failed\n %s"),
log_error(_("get_primary_node_id(): query failed\n %s"),
PQerrorMessage(conn));
retval = NODE_NOT_FOUND;
}
else if (PQntuples(res) == 0)
{
log_verbose(LOG_WARNING, _("get_master_node_id(): no active primary found\n"));
log_verbose(LOG_WARNING, _("get_primary_node_id(): no active primary found\n"));
retval = NODE_NOT_FOUND;
}
else
@@ -1193,9 +1193,9 @@ _populate_node_record(PGresult *res, t_node_info *node_info, int row)
t_server_type
parse_node_type(const char *type)
{
if (strcmp(type, "master") == 0)
if (strcmp(type, "primary") == 0)
{
return MASTER;
return PRIMARY;
}
else if (strcmp(type, "standby") == 0)
{
@@ -1218,8 +1218,8 @@ get_node_type_string(t_server_type type)
{
switch(type)
{
case MASTER:
return "master";
case PRIMARY:
return "primary";
case STANDBY:
return "standby";
case WITNESS:
@@ -1266,7 +1266,7 @@ RecordStatus
get_node_record_by_name(PGconn *conn, const char *node_name, t_node_info *node_info)
{
PQExpBufferData query;
RecordStatus result;
RecordStatus record_status;
initPQExpBuffer(&query);
@@ -1278,31 +1278,31 @@ get_node_record_by_name(PGconn *conn, const char *node_name, t_node_info *node_i
log_verbose(LOG_DEBUG, "get_node_record_by_name():\n %s", query.data);
result = _get_node_record(conn, query.data, node_info);
record_status = _get_node_record(conn, query.data, node_info);
termPQExpBuffer(&query);
if (result == 0)
if (record_status == RECORD_NOT_FOUND)
{
log_verbose(LOG_DEBUG, "get_node_record(): no record found for node %s",
node_name);
}
return result;
return record_status;
}
bool
get_master_node_record(PGconn *conn, t_node_info *node_info)
get_primary_node_record(PGconn *conn, t_node_info *node_info)
{
int master_node_id = get_master_node_id(conn);
int primary_node_id = get_primary_node_id(conn);
if (master_node_id == UNKNOWN_NODE_ID)
if (primary_node_id == UNKNOWN_NODE_ID)
{
return false;
}
return get_node_record(conn, master_node_id, node_info);
return get_node_record(conn, primary_node_id, node_info);
}
@@ -1430,7 +1430,7 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info)
* No explicit upstream node id provided for standby - attempt to
* get primary node id
*/
int primary_node_id = get_master_node_id(conn);
int primary_node_id = get_primary_node_id(conn);
maxlen_snprintf(upstream_node_id, "%i", primary_node_id);
upstream_node_id_ptr = upstream_node_id;
}
@@ -1507,12 +1507,12 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info)
}
bool
update_node_record_set_master(PGconn *conn, int this_node_id)
update_node_record_set_primary(PGconn *conn, int this_node_id)
{
PQExpBufferData query;
PGresult *res;
log_debug(_("setting node %i as master and marking existing master as failed"),
log_debug(_("setting node %i as primary and marking existing primary as failed"),
this_node_id);
begin_transaction(conn);
@@ -1522,14 +1522,14 @@ update_node_record_set_master(PGconn *conn, int this_node_id)
appendPQExpBuffer(&query,
" UPDATE repmgr.nodes "
" SET active = FALSE "
" WHERE type = 'master' "
" WHERE type = 'primary' "
" AND active IS TRUE ");
res = PQexec(conn, query.data);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
log_error(_("unable to set old master node as inactive:\n %s"),
log_error(_("unable to set old primary node as inactive:\n %s"),
PQerrorMessage(conn));
PQclear(res);
@@ -1544,7 +1544,7 @@ update_node_record_set_master(PGconn *conn, int this_node_id)
appendPQExpBuffer(&query,
" UPDATE repmgr.nodes"
" SET type = 'master', "
" SET type = 'primary', "
" upstream_node_id = NULL "
" WHERE node_id = %i ",
this_node_id);
@@ -1554,7 +1554,7 @@ update_node_record_set_master(PGconn *conn, int this_node_id)
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
log_error(_("unable to set current node %i as active master:\n %s"),
log_error(_("unable to set current node %i as active primary:\n %s"),
this_node_id,
PQerrorMessage(conn));
PQclear(res);
@@ -1658,7 +1658,7 @@ delete_node_record(PGconn *conn, int node)
* Returns true if all operations succeeded, false if one or more failed.
*
* Note this function may be called with `conn` set to NULL in cases where
* the master node is not available and it's therefore not possible to write
* the primary node is not available and it's therefore not possible to write
* an event record. In this case, if `event_notification_command` is set, a
* user-defined notification to be generated; if not, this function will have
* no effect.
@@ -2028,7 +2028,7 @@ drop_replication_slot(PGconn *conn, char *slot_name)
}
int
RecordStatus
get_slot_record(PGconn *conn, char *slot_name, t_replication_slot *record)
{
PQExpBufferData query;
@@ -2053,12 +2053,12 @@ get_slot_record(PGconn *conn, char *slot_name, t_replication_slot *record)
log_error(_("unable to query pg_replication_slots:\n %s"),
PQerrorMessage(conn));
PQclear(res);
return -1;
return RECORD_ERROR;
}
if (!PQntuples(res))
{
return 0;
return RECORD_NOT_FOUND;
}
strncpy(record->slot_name, PQgetvalue(res, 0, 0), MAXLEN);
@@ -2069,7 +2069,7 @@ get_slot_record(PGconn *conn, char *slot_name, t_replication_slot *record)
PQclear(res);
return 1;
return RECORD_FOUND;
}

View File

@@ -17,7 +17,7 @@
typedef enum {
UNKNOWN = 0,
MASTER,
PRIMARY,
STANDBY,
WITNESS,
BDR
@@ -32,7 +32,7 @@ typedef enum {
typedef enum {
RECTYPE_UNKNOWN = 0,
RECTYPE_MASTER,
RECTYPE_PRIMARY,
RECTYPE_STANDBY
} RecoveryType;
@@ -151,11 +151,11 @@ PGconn *establish_db_connection_as_user(const char *conninfo,
PGconn *establish_db_connection_by_params(const char *keywords[],
const char *values[],
const bool exit_on_error);
PGconn *establish_master_db_connection(PGconn *conn,
PGconn *establish_primary_db_connection(PGconn *conn,
const bool exit_on_error);
PGconn *get_master_connection(PGconn *standby_conn, int *master_id, char *master_conninfo_out);
PGconn *get_master_connection_quiet(PGconn *standby_conn, int *master_id, char *master_conninfo_out);
PGconn *get_primary_connection(PGconn *standby_conn, int *primary_id, char *primary_conninfo_out);
PGconn *get_primary_connection_quiet(PGconn *standby_conn, int *primary_id, char *primary_conninfo_out);
bool is_superuser_connection(PGconn *conn, t_connection_user *userinfo);
@@ -189,7 +189,7 @@ bool get_pg_setting(PGconn *conn, const char *setting, char *output);
bool get_cluster_size(PGconn *conn, char *size);
int get_server_version(PGconn *conn, char *server_version);
RecoveryType get_recovery_type(PGconn *conn);
int get_master_node_id(PGconn *conn);
int get_primary_node_id(PGconn *conn);
/* extension functions */
ExtensionStatus get_repmgr_extension_status(PGconn *conn);
@@ -204,14 +204,14 @@ const char * get_node_type_string(t_server_type type);
RecordStatus get_node_record(PGconn *conn, int node_id, t_node_info *node_info);
RecordStatus get_node_record_by_name(PGconn *conn, const char *node_name, t_node_info *node_info);
bool get_local_node_record(PGconn *conn, int node_id, t_node_info *node_info);
bool get_master_node_record(PGconn *conn, t_node_info *node_info);
bool get_primary_node_record(PGconn *conn, t_node_info *node_info);
void get_downstream_node_records(PGconn *conn, int node_id, NodeInfoList *nodes);
bool create_node_record(PGconn *conn, char *repmgr_action, t_node_info *node_info);
bool update_node_record(PGconn *conn, char *repmgr_action, t_node_info *node_info);
bool delete_node_record(PGconn *conn, int node);
bool update_node_record_set_master(PGconn *conn, int this_node_id);
bool update_node_record_set_primary(PGconn *conn, int this_node_id);
bool update_node_record_status(PGconn *conn, int this_node_id, char *type, int upstream_node_id, bool active);
/* event record functions */

View File

@@ -6,7 +6,7 @@ CREATE TABLE nodes (
upstream_node_id INTEGER NULL REFERENCES nodes (node_id) DEFERRABLE,
active BOOLEAN NOT NULL DEFAULT TRUE,
node_name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN('master','standby','witness','bdr')),
type TEXT NOT NULL CHECK (type IN('primary','standby','witness','bdr')),
priority INT NOT NULL DEFAULT 100,
conninfo TEXT NOT NULL,

View File

@@ -1,12 +0,0 @@
/*
* repmgr-action-master.h
* Copyright (c) 2ndQuadrant, 2010-2017
*/
#ifndef _REPMGR_ACTION_MASTER_H_
#define _REPMGR_ACTION_MASTER_H_
extern void do_master_register(void);
extern void do_master_unregister(void);
#endif

View File

@@ -1,7 +1,7 @@
/*
* repmgr-action-cluster.c
* repmgr-action-primary.c
*
* Implements master actions for the repmgr command line utility
* Implements primary actions for the repmgr command line utility
*
* Copyright (c) 2ndQuadrant, 2010-2017
*/
@@ -9,21 +9,21 @@
#include "repmgr.h"
#include "repmgr-client-global.h"
#include "repmgr-action-master.h"
#include "repmgr-action-primary.h"
/*
* do_master_register()
* do_primary_register()
*
* Event(s):
* - master_register
* - primary_register
*/
void
do_master_register(void)
do_primary_register(void)
{
PGconn *conn = NULL;
PGconn *master_conn = NULL;
int current_master_id = UNKNOWN_NODE_ID;
PGconn *primary_conn = NULL;
int current_primary_id = UNKNOWN_NODE_ID;
RecoveryType recovery_type;
t_node_info node_info = T_NODE_INFO_INITIALIZER;
RecordStatus record_status;
@@ -32,22 +32,22 @@ do_master_register(void)
PQExpBufferData event_description;
log_info(_("connecting to master database..."));
log_info(_("connecting to primary database..."));
conn = establish_db_connection(config_file_options.conninfo, true);
log_verbose(LOG_INFO, _("connected to server, checking its state"));
/* verify that node is running a supported server version */
check_server_version(conn, "master", true, NULL);
check_server_version(conn, "primary", true, NULL);
/* check that node is actually a master */
/* check that node is actually a primary */
recovery_type = get_recovery_type(conn);
if (recovery_type != RECTYPE_MASTER)
if (recovery_type != RECTYPE_PRIMARY)
{
if (recovery_type == RECTYPE_STANDBY)
{
log_error(_("server is in standby mode and cannot be registered as a master"));
log_error(_("server is in standby mode and cannot be registered as a primary"));
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
@@ -80,36 +80,36 @@ do_master_register(void)
}
/* Ensure there isn't another registered node which is master */
master_conn = get_master_connection(conn, &current_master_id, NULL);
/* Ensure there isn't another registered node which is primary */
primary_conn = get_primary_connection(conn, &current_primary_id, NULL);
if (master_conn != NULL)
if (primary_conn != NULL)
{
if (current_master_id != config_file_options.node_id)
if (current_primary_id != config_file_options.node_id)
{
/* it's impossible to add a second master to a streaming replication cluster */
log_error(_("there is already an active registered master (node ID: %i) in this cluster"), current_master_id);
PQfinish(master_conn);
/* it's impossible to add a second primary to a streaming replication cluster */
log_error(_("there is already an active registered primary (node ID: %i) in this cluster"), current_primary_id);
PQfinish(primary_conn);
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
/* we've probably connected to ourselves */
PQfinish(master_conn);
PQfinish(primary_conn);
}
begin_transaction(conn);
/*
* Check for an active master node record with a different ID. This shouldn't
* happen, but could do if an existing master was shut down without being unregistered.
* Check for an active primary node record with a different ID. This shouldn't
* happen, but could do if an existing primary was shut down without being unregistered.
*/
current_master_id = get_master_node_id(conn);
if (current_master_id != NODE_NOT_FOUND && current_master_id != config_file_options.node_id)
current_primary_id = get_primary_node_id(conn);
if (current_primary_id != NODE_NOT_FOUND && current_primary_id != config_file_options.node_id)
{
log_error(_("another node with id %i is already registered as master"), current_master_id);
log_detail(_("a streaming replication cluster can have only one master node"));
log_error(_("another node with id %i is already registered as primary"), current_primary_id);
log_detail(_("a streaming replication cluster can have only one primary node"));
rollback_transaction(conn);
PQfinish(conn);
@@ -142,14 +142,14 @@ do_master_register(void)
/* if upstream_node_id set, warn that it will be ignored */
if (config_file_options.upstream_node_id != NO_UPSTREAM_NODE)
{
log_warning(_("master node %i is configured with \"upstream_node_id\" set to %i"),
log_warning(_("primary node %i is configured with \"upstream_node_id\" set to %i"),
node_info.node_id,
config_file_options.upstream_node_id);
log_detail(_("the value set for \"upstream_node_id\" will be ignored"));
}
/* set type to "master", active to "true" and unset upstream_node_id*/
node_info.type = MASTER;
/* set type to "primary", active to "true" and unset upstream_node_id*/
node_info.type = PRIMARY;
node_info.upstream_node_id = NO_UPSTREAM_NODE;
node_info.active = true;
@@ -176,17 +176,17 @@ do_master_register(void)
if (record_status == RECORD_FOUND)
{
record_created = update_node_record(conn,
"master register",
"primary register",
&node_info);
if (record_created == true)
{
appendPQExpBuffer(&event_description,
"existing master record updated");
"existing primary record updated");
}
else
{
appendPQExpBuffer(&event_description,
"error encountered while updating master record:\n%s",
"error encountered while updating primary record:\n%s",
PQerrorMessage(conn));
}
@@ -194,12 +194,12 @@ do_master_register(void)
else
{
record_created = create_node_record(conn,
"master register",
"primary register",
&node_info);
if (record_created == false)
{
appendPQExpBuffer(&event_description,
"error encountered while creating master record:\n%s",
"error encountered while creating primary record:\n%s",
PQerrorMessage(conn));
}
@@ -218,7 +218,7 @@ do_master_register(void)
create_event_record(conn,
&config_file_options,
config_file_options.node_id,
"master_register",
"primary_register",
record_created,
event_description.data);
@@ -227,18 +227,18 @@ do_master_register(void)
if (record_created == false)
{
log_notice(_("unable to register master node - see preceding messages"));
log_notice(_("unable to register primary node - see preceding messages"));
exit(ERR_DB_QUERY);
}
if (record_status == RECORD_FOUND)
{
log_notice(_("master node record (id: %i) updated"),
log_notice(_("primary node record (id: %i) updated"),
config_file_options.node_id);
}
else
{
log_notice(_("master node record (id: %i) registered"),
log_notice(_("primary node record (id: %i) registered"),
config_file_options.node_id);
}
@@ -247,16 +247,16 @@ do_master_register(void)
/*
* do_master_unregister()
* do_primary_unregister()
*
* Event(s):
* - master_unregister
* - primary_unregister
*/
void
do_master_unregister(void)
do_primary_unregister(void)
{
PGconn *master_conn = NULL;
PGconn *primary_conn = NULL;
PGconn *local_conn = NULL;
t_node_info local_node_info = T_NODE_INFO_INITIALIZER;
@@ -272,26 +272,26 @@ do_master_unregister(void)
get_local_node_record(local_conn, config_file_options.node_id, &local_node_info);
/*
* Obtain a connection to the current master node - if this isn't possible,
* Obtain a connection to the current primary node - if this isn't possible,
* abort as we won't be able to update the "nodes" table anyway.
*/
master_conn = establish_master_db_connection(local_conn, false);
primary_conn = establish_primary_db_connection(local_conn, false);
if (PQstatus(master_conn) != CONNECTION_OK)
if (PQstatus(primary_conn) != CONNECTION_OK)
{
t_node_info master_node_info;
t_node_info primary_node_info;
log_error(_("unable to connect to master server"));
log_error(_("unable to connect to primary server"));
if (get_master_node_record(local_conn, &master_node_info))
if (get_primary_node_record(local_conn, &primary_node_info))
{
log_detail(_("current master registered as node %s (id: %i, conninfo: \"%s\")"),
master_node_info.node_name,
master_node_info.node_id,
master_node_info.conninfo);
log_detail(_("current primary registered as node %s (id: %i, conninfo: \"%s\")"),
primary_node_info.node_name,
primary_node_info.node_id,
primary_node_info.conninfo);
}
log_hint(_("you may need to promote this standby or ask it to look for a new master to follow"));
log_hint(_("you may need to promote this standby or ask it to look for a new primary to follow"));
PQfinish(local_conn);
exit(ERR_DB_CONN);
}
@@ -316,7 +316,7 @@ do_master_unregister(void)
* Check for downstream nodes - if any still defined, we won't be able to
* delete the node record due to foreign key constraints.
*/
get_downstream_node_records(master_conn, target_node_info_ptr->node_id, &downstream_nodes);
get_downstream_node_records(primary_conn, target_node_info_ptr->node_id, &downstream_nodes);
if (downstream_nodes.node_count > 0)
{
@@ -334,7 +334,7 @@ do_master_unregister(void)
downstream_nodes.node_count);
}
log_hint(_("ensure these nodes are following the current master with \"repmgr standby follow\""));
log_hint(_("ensure these nodes are following the current primary with \"repmgr standby follow\""));
initPQExpBuffer(&detail);
@@ -349,19 +349,19 @@ do_master_unregister(void)
log_detail(_("the affected node(s) are:\n%s"), detail.data);
termPQExpBuffer(&detail);
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
target_node_conn = establish_db_connection_quiet(target_node_info_ptr->conninfo);
/* If node not reachable, check that the record is for a master node */
/* If node not reachable, check that the record is for a primary node */
if (PQstatus(target_node_conn) != CONNECTION_OK)
{
if (target_node_info_ptr->type != MASTER)
if (target_node_info_ptr->type != PRIMARY)
{
log_error(_("node %s (id: %i) is not a master, unable to unregister"),
log_error(_("node %s (id: %i) is not a primary, unable to unregister"),
target_node_info_ptr->node_name,
target_node_info_ptr->node_id);
if (target_node_info_ptr->type == STANDBY)
@@ -369,7 +369,7 @@ do_master_unregister(void)
log_hint(_("the node can be unregistered with \"repmgr standby unregister\""));
}
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
}
@@ -382,9 +382,9 @@ do_master_unregister(void)
/* Node appears to be a standby */
if (recovery_type == RECTYPE_STANDBY)
{
/* We'll refuse to do anything unless the node record shows it as a master */
/* We'll refuse to do anything unless the node record shows it as a primary */
if (target_node_info_ptr->type != MASTER)
if (target_node_info_ptr->type != PRIMARY)
{
log_error(_("node %s (id: %i) is a %s, unable to unregister"),
target_node_info_ptr->node_name,
@@ -394,7 +394,7 @@ do_master_unregister(void)
}
/*
* If --F/--force not set, hint that it might be appropriate to
* register the node as a standby rather than unregister as master
* register the node as a standby rather than unregister as primary
*/
else if (!runtime_options.force)
{
@@ -402,7 +402,7 @@ do_master_unregister(void)
target_node_info_ptr->node_name,
target_node_info_ptr->node_id);
log_hint(_("the node can be registered as a standby with \"repmgr standby register --force\""));
log_hint(_("use \"repmgr master unregister --force\" to remove this node's metadata entirely"));
log_hint(_("use \"repmgr primary unregister --force\" to remove this node's metadata entirely"));
can_unregister = false;
}
@@ -410,42 +410,42 @@ do_master_unregister(void)
if (can_unregister == false)
{
PQfinish(target_node_conn);
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
}
else if (recovery_type == RECTYPE_MASTER)
else if (recovery_type == RECTYPE_PRIMARY)
{
t_node_info master_node_info = T_NODE_INFO_INITIALIZER;
bool master_record_found;
t_node_info primary_node_info = T_NODE_INFO_INITIALIZER;
bool primary_record_found;
master_record_found = get_master_node_record(master_conn, &master_node_info);
primary_record_found = get_primary_node_record(primary_conn, &primary_node_info);
if (master_record_found == false)
if (primary_record_found == false)
{
log_error(_("node %s (id: %i) is a master node, but no master node record found"),
log_error(_("node %s (id: %i) is a primary node, but no primary node record found"),
target_node_info_ptr->node_name,
target_node_info_ptr->node_id);
log_hint(_("register this node as master with \"repmgr master register --force\""));
log_hint(_("register this node as primary with \"repmgr primary register --force\""));
PQfinish(target_node_conn);
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
/* This appears to be the cluster master - cowardly refuse
/* This appears to be the cluster primary - cowardly refuse
* to delete the record
*/
if (master_node_info.node_id == target_node_info_ptr->node_id)
if (primary_node_info.node_id == target_node_info_ptr->node_id)
{
log_error(_("node %s (id: %i) is the current master node, unable to unregister"),
log_error(_("node %s (id: %i) is the current primary node, unable to unregister"),
target_node_info_ptr->node_name,
target_node_info_ptr->node_id);
if (master_node_info.active == false)
if (primary_node_info.active == false)
{
log_hint(_("node is marked as inactive, activate with \"repmgr master register --force\""));
log_hint(_("node is marked as inactive, activate with \"repmgr primary register --force\""));
}
PQfinish(target_node_conn);
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
}
@@ -461,8 +461,8 @@ do_master_unregister(void)
log_error(_("node %s (id: %i) is marked as active, unable to unregister"),
target_node_info_ptr->node_name,
target_node_info_ptr->node_id);
log_hint(_("run \"repmgr master unregister --force\" to unregister this node"));
PQfinish(master_conn);
log_hint(_("run \"repmgr primary unregister --force\" to unregister this node"));
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
}
@@ -477,7 +477,7 @@ do_master_unregister(void)
else
{
PQExpBufferData event_details;
bool delete_success = delete_node_record(master_conn,
bool delete_success = delete_node_record(primary_conn,
target_node_info_ptr->node_id);
if (delete_success == false)
@@ -485,7 +485,7 @@ do_master_unregister(void)
log_error(_("unable to unregister node %s (id: %i)"),
target_node_info_ptr->node_name,
target_node_info_ptr->node_id);
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_DB_QUERY);
}
@@ -503,10 +503,10 @@ do_master_unregister(void)
config_file_options.node_id);
}
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
config_file_options.node_id,
"master_unregister",
"primary_unregister",
true,
event_details.data);
termPQExpBuffer(&event_details);
@@ -516,6 +516,6 @@ do_master_unregister(void)
target_node_info_ptr->node_id);
}
PQfinish(master_conn);
PQfinish(primary_conn);
return;
}

12
repmgr-action-primary.h Normal file
View File

@@ -0,0 +1,12 @@
/*
* repmgr-action-primary.h
* Copyright (c) 2ndQuadrant, 2010-2017
*/
#ifndef _REPMGR_ACTION_PRIMARY_H_
#define _REPMGR_ACTION_PRIMARY_H_
extern void do_primary_register(void);
extern void do_primary_unregister(void);
#endif

View File

@@ -34,7 +34,7 @@ typedef struct TablespaceDataList
} TablespaceDataList;
static PGconn *master_conn = NULL;
static PGconn *primary_conn = NULL;
static PGconn *source_conn = NULL;
static int server_version_num = UNKNOWN_SERVER_VERSION_NUM;
@@ -62,7 +62,7 @@ static char barman_command_buf[MAXLEN] = "";
static void check_barman_config(void);
static void check_source_server(void);
static void check_source_server_via_barman(void);
static void check_master_standby_version_match(PGconn *conn, PGconn *master_conn);
static void check_primary_standby_version_match(PGconn *conn, PGconn *primary_conn);
static void check_recovery_type(PGconn *conn);
static void initialise_direct_clone(void);
@@ -328,7 +328,7 @@ do_standby_clone(void)
drop_replication_slot(source_conn, repmgr_slot_name);
}
log_error(_("unable to take a base backup of the master server"));
log_error(_("unable to take a base backup of the primary server"));
log_warning(_("data directory (%s) may need to be cleaned up manually"),
local_data_directory);
@@ -407,12 +407,13 @@ do_standby_clone(void)
*/
{
t_node_info node_record = T_NODE_INFO_INITIALIZER;
int node_result;
RecordStatus record_status;
node_result = get_node_record(master_conn,
record_status = get_node_record(primary_conn,
config_file_options.node_id,
&node_record);
if (node_result)
if (record_status == RECORD_FOUND)
{
log_hint(_("after starting the server, you need to re-register this standby with \"repmgr standby register --force\" to overwrite the existing node record"));
}
@@ -451,15 +452,15 @@ do_standby_clone(void)
_("; --force: %s"),
runtime_options.force ? "Y" : "N");
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_clone",
true,
event_details.data);
if (PQstatus(master_conn) == CONNECTION_OK)
PQfinish(master_conn);
if (PQstatus(primary_conn) == CONNECTION_OK)
PQfinish(primary_conn);
if (PQstatus(source_conn) == CONNECTION_OK)
PQfinish(source_conn);
@@ -556,11 +557,11 @@ void
do_standby_register(void)
{
PGconn *conn;
PGconn *master_conn;
PGconn *primary_conn;
bool record_created;
t_node_info node_record = T_NODE_INFO_INITIALIZER;
int node_result;
RecordStatus record_status;
log_info(_("connecting to standby database"));
conn = establish_db_connection_quiet(config_file_options.conninfo);
@@ -574,14 +575,14 @@ do_standby_register(void)
config_file_options.node_name);
log_detail(_("%s"),
PQerrorMessage(conn));
log_hint(_("to register a standby which is not running, provide master connection parameters and use option -F/--force"));
log_hint(_("to register a standby which is not running, provide primary connection parameters and use option -F/--force"));
exit(ERR_BAD_CONFIG);
}
if (!runtime_options.connection_param_provided)
{
log_error(_("unable to connect to local node %i (\"%s\") and no master connection parameters provided"),
log_error(_("unable to connect to local node %i (\"%s\") and no primary connection parameters provided"),
config_file_options.node_id,
config_file_options.node_name);
exit(ERR_BAD_CONFIG);
@@ -594,18 +595,18 @@ do_standby_register(void)
check_recovery_type(conn);
}
/* check if there is a master in this cluster */
log_info(_("connecting to master database"));
/* check if there is a primary in this cluster */
log_info(_("connecting to primary database"));
/* Normal case - we can connect to the local node */
if (PQstatus(conn) == CONNECTION_OK)
{
master_conn = get_master_connection(conn, NULL, NULL);
primary_conn = get_primary_connection(conn, NULL, NULL);
}
/* User is forcing a registration and must have supplied master connection info */
/* User is forcing a registration and must have supplied primary connection info */
else
{
master_conn = establish_db_connection_by_params((const char**)source_conninfo.keywords,
primary_conn = establish_db_connection_by_params((const char**)source_conninfo.keywords,
(const char**)source_conninfo.values,
false);
}
@@ -613,17 +614,17 @@ do_standby_register(void)
/*
* no amount of --force will make it possible to register the standby
* without a master server to connect to
* without a primary server to connect to
*/
if (PQstatus(master_conn) != CONNECTION_OK)
if (PQstatus(primary_conn) != CONNECTION_OK)
{
log_error(_("unable to connect to the master database"));
log_hint(_("a master must be configured before registering a standby"));
log_error(_("unable to connect to the primary database"));
log_hint(_("a primary must be configured before registering a standby"));
exit(ERR_BAD_CONFIG);
}
/*
* Verify that standby and master are supported and compatible server
* Verify that standby and primary are supported and compatible server
* versions
*
* If the user is registering an inactive standby, we'll trust they know
@@ -631,7 +632,7 @@ do_standby_register(void)
*/
if (PQstatus(conn) == CONNECTION_OK)
{
check_master_standby_version_match(conn, master_conn);
check_primary_standby_version_match(conn, primary_conn);
}
@@ -639,18 +640,18 @@ do_standby_register(void)
* Check that an active node with the same node_name doesn't exist already
*/
node_result = get_node_record_by_name(master_conn,
config_file_options.node_name,
&node_record);
record_status = get_node_record_by_name(primary_conn,
config_file_options.node_name,
&node_record);
if (node_result)
if (record_status == RECORD_FOUND)
{
if (node_record.active == true && node_record.node_id != config_file_options.node_id)
{
log_error(_("node %i exists already with node_name \"%s\""),
node_record.node_id,
config_file_options.node_name);
PQfinish(master_conn);
PQfinish(primary_conn);
if (PQstatus(conn) == CONNECTION_OK)
PQfinish(conn);
exit(ERR_BAD_CONFIG);
@@ -659,16 +660,16 @@ do_standby_register(void)
/* Check if node record exists */
node_result = get_node_record(master_conn,
config_file_options.node_id,
&node_record);
record_status= get_node_record(primary_conn,
config_file_options.node_id,
&node_record);
if (node_result && !runtime_options.force)
if (record_status == RECORD_FOUND && !runtime_options.force)
{
log_error(_("node %i is already registered"),
config_file_options.node_id);
log_hint(_("use option -F/--force to overwrite an existing node record"));
PQfinish(master_conn);
PQfinish(primary_conn);
if (PQstatus(conn) == CONNECTION_OK)
PQfinish(conn);
exit(ERR_BAD_CONFIG);
@@ -681,13 +682,13 @@ do_standby_register(void)
if (config_file_options.upstream_node_id != NO_UPSTREAM_NODE)
{
int upstream_node_result;
RecordStatus upstream_record_status;
upstream_node_result = get_node_record(master_conn,
config_file_options.upstream_node_id,
&node_record);
upstream_record_status = get_node_record(primary_conn,
config_file_options.upstream_node_id,
&node_record);
if (!upstream_node_result)
if (upstream_record_status != RECORD_FOUND)
{
t_node_info upstream_node_record = T_NODE_INFO_INITIALIZER;
@@ -697,7 +698,7 @@ do_standby_register(void)
config_file_options.upstream_node_id);
/* footgun alert - only do this if you know what you're doing */
log_hint(_("use option -F/--force to create a dummy upstream record"));
PQfinish(master_conn);
PQfinish(primary_conn);
if (PQstatus(conn) == CONNECTION_OK)
PQfinish(conn);
exit(ERR_BAD_CONFIG);
@@ -712,7 +713,7 @@ do_standby_register(void)
strncpy(upstream_node_record.conninfo, runtime_options.upstream_conninfo, MAXLEN);
upstream_node_record.active = false;
record_created = create_node_record(master_conn,
record_created = create_node_record(primary_conn,
"standby register",
&upstream_node_record);
@@ -728,14 +729,14 @@ do_standby_register(void)
*/
if (record_created == false)
{
upstream_node_result = get_node_record(master_conn,
config_file_options.upstream_node_id,
&node_record);
if (!upstream_node_result)
upstream_record_status = get_node_record(primary_conn,
config_file_options.upstream_node_id,
&node_record);
if (upstream_record_status != RECORD_FOUND)
{
log_error(_("unable to create placeholder record for upstream node %i"),
config_file_options.upstream_node_id);
PQfinish(master_conn);
PQfinish(primary_conn);
if (PQstatus(conn) == CONNECTION_OK)
PQfinish(conn);
exit(ERR_BAD_CONFIG);
@@ -756,7 +757,7 @@ do_standby_register(void)
log_error(_("record for upstream node %i is marked as inactive"),
config_file_options.upstream_node_id);
log_hint(_("use option -F/--force to register a standby with an inactive upstream node"));
PQfinish(master_conn);
PQfinish(primary_conn);
if (PQstatus(conn) == CONNECTION_OK)
PQfinish(conn);
exit(ERR_BAD_CONFIG);
@@ -801,15 +802,15 @@ do_standby_register(void)
* node record exists - update it
* (at this point we have already established that -F/--force is in use)
*/
if (node_result)
if (record_status == RECORD_FOUND)
{
record_created = update_node_record(master_conn,
record_created = update_node_record(primary_conn,
"standby register",
&node_record);
}
else
{
record_created = create_node_record(master_conn,
record_created = create_node_record(primary_conn,
"standby register",
&node_record);
}
@@ -818,14 +819,14 @@ do_standby_register(void)
{
/* XXX add event description */
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_register",
false,
NULL);
PQfinish(master_conn);
PQfinish(primary_conn);
if (PQstatus(conn) == CONNECTION_OK)
PQfinish(conn);
@@ -833,7 +834,7 @@ do_standby_register(void)
}
/* Log the event */
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_register",
@@ -848,18 +849,18 @@ do_standby_register(void)
{
bool sync_ok = false;
int timer = 0;
int node_record_result;
t_node_info node_record_on_master = T_NODE_INFO_INITIALIZER;
RecordStatus node_record_status;
t_node_info node_record_on_primary = T_NODE_INFO_INITIALIZER;
t_node_info node_record_on_standby = T_NODE_INFO_INITIALIZER;
node_record_result = get_node_record(master_conn,
node_record_status = get_node_record(primary_conn,
config_file_options.node_id,
&node_record_on_master);
&node_record_on_primary);
if (node_record_result != 1)
if (node_record_status != RECORD_FOUND)
{
log_error(_("unable to retrieve node record from master"));
PQfinish(master_conn);
log_error(_("unable to retrieve node record from primary"));
PQfinish(primary_conn);
PQfinish(conn);
exit(ERR_REGISTRATION_SYNC);
}
@@ -871,37 +872,37 @@ do_standby_register(void)
if (runtime_options.wait_register_sync_seconds && runtime_options.wait_register_sync_seconds == timer)
break;
node_record_result = get_node_record(conn,
node_record_status = get_node_record(conn,
config_file_options.node_id,
&node_record_on_standby);
if (node_record_result == 0)
if (node_record_status == RECORD_NOT_FOUND)
{
/* no record available yet on standby*/
records_match = false;
}
else if (node_record_result == 1)
else if (node_record_status == RECORD_FOUND)
{
/* compare relevant fields */
if (node_record_on_standby.upstream_node_id != node_record_on_master.upstream_node_id)
if (node_record_on_standby.upstream_node_id != node_record_on_primary.upstream_node_id)
records_match = false;
if (node_record_on_standby.type != node_record_on_master.type)
if (node_record_on_standby.type != node_record_on_primary.type)
records_match = false;
if (node_record_on_standby.priority != node_record_on_master.priority)
if (node_record_on_standby.priority != node_record_on_primary.priority)
records_match = false;
if (node_record_on_standby.active != node_record_on_master.active)
if (node_record_on_standby.active != node_record_on_primary.active)
records_match = false;
if (strcmp(node_record_on_standby.node_name, node_record_on_master.node_name) != 0)
if (strcmp(node_record_on_standby.node_name, node_record_on_primary.node_name) != 0)
records_match = false;
if (strcmp(node_record_on_standby.conninfo, node_record_on_master.conninfo) != 0)
if (strcmp(node_record_on_standby.conninfo, node_record_on_primary.conninfo) != 0)
records_match = false;
if (strcmp(node_record_on_standby.slot_name, node_record_on_master.slot_name) != 0)
if (strcmp(node_record_on_standby.slot_name, node_record_on_primary.slot_name) != 0)
records_match = false;
if (records_match == true)
@@ -919,16 +920,16 @@ do_standby_register(void)
{
log_error(_("node record was not synchronised after %i seconds"),
runtime_options.wait_register_sync_seconds);
PQfinish(master_conn);
PQfinish(primary_conn);
PQfinish(conn);
exit(ERR_REGISTRATION_SYNC);
}
log_info(_("node record on standby synchronised from master"));
log_info(_("node record on standby synchronised from primary"));
}
PQfinish(master_conn);
PQfinish(primary_conn);
if (PQstatus(conn) == CONNECTION_OK)
PQfinish(conn);
@@ -950,7 +951,7 @@ void
do_standby_unregister(void)
{
PGconn *conn;
PGconn *master_conn;
PGconn *primary_conn;
int target_node_id;
t_node_info node_info = T_NODE_INFO_INITIALIZER;
@@ -960,14 +961,14 @@ do_standby_unregister(void)
log_info(_("connecting to local standby"));
conn = establish_db_connection(config_file_options.conninfo, true);
/* check if there is a master in this cluster */
log_info(_("connecting to master database"));
/* check if there is a primary in this cluster */
log_info(_("connecting to primary database"));
master_conn = get_master_connection(conn, NULL, NULL);
primary_conn = get_primary_connection(conn, NULL, NULL);
if (PQstatus(master_conn) != CONNECTION_OK)
if (PQstatus(primary_conn) != CONNECTION_OK)
{
log_error(_("unable to connect to master server"));
log_error(_("unable to connect to primary server"));
log_detail("%s", PQerrorMessage(conn));
exit(ERR_BAD_CONFIG);
}
@@ -983,10 +984,10 @@ do_standby_unregister(void)
/* Check node exists and is really a standby */
if (!get_node_record(master_conn, target_node_id, &node_info))
if (get_node_record(primary_conn, target_node_id, &node_info) != RECORD_FOUND)
{
log_error(_("no record found for node %i"), target_node_id);
PQfinish(master_conn);
PQfinish(primary_conn);
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
@@ -994,32 +995,32 @@ do_standby_unregister(void)
if (node_info.type != STANDBY)
{
log_error(_("node %i is not a standby server"), target_node_id);
PQfinish(master_conn);
PQfinish(primary_conn);
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
/* Now unregister the standby */
log_notice(_("unregistering node %i"), target_node_id);
node_record_deleted = delete_node_record(master_conn,
node_record_deleted = delete_node_record(primary_conn,
target_node_id);
if (node_record_deleted == false)
{
PQfinish(master_conn);
PQfinish(primary_conn);
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
/* Log the event */
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
target_node_id,
"standby_unregister",
true,
NULL);
PQfinish(master_conn);
PQfinish(primary_conn);
PQfinish(conn);
log_info(_("standby unregistration complete"));
@@ -1038,7 +1039,7 @@ void
do_standby_promote(void)
{
PGconn *conn;
PGconn *current_master_conn;
PGconn *current_primary_conn;
char script[MAXLEN];
@@ -1053,7 +1054,7 @@ do_standby_promote(void)
bool success;
PQExpBufferData details;
int existing_master_id = UNKNOWN_NODE_ID;
int existing_primary_id = UNKNOWN_NODE_ID;
log_info(_("connecting to standby database"));
conn = establish_db_connection(config_file_options.conninfo, true);
@@ -1068,7 +1069,7 @@ do_standby_promote(void)
if (recovery_type != RECTYPE_STANDBY)
{
if (recovery_type == RECTYPE_MASTER)
if (recovery_type == RECTYPE_PRIMARY)
{
log_error(_("STANDBY PROMOTE can only be executed on a standby node"));
PQfinish(conn);
@@ -1083,25 +1084,25 @@ do_standby_promote(void)
}
/* check that there's no existing master */
current_master_conn = get_master_connection_quiet(conn, &existing_master_id, NULL);
/* check that there's no existing primary */
current_primary_conn = get_primary_connection_quiet(conn, &existing_primary_id, NULL);
if (PQstatus(current_master_conn) == CONNECTION_OK)
if (PQstatus(current_primary_conn) == CONNECTION_OK)
{
log_error(_("this cluster already has an active master server"));
log_error(_("this cluster already has an active primary server"));
if (existing_master_id != UNKNOWN_NODE_ID)
if (existing_primary_id != UNKNOWN_NODE_ID)
{
t_node_info master_rec;
t_node_info primary_rec;
get_node_record(conn, existing_master_id, &master_rec);
get_node_record(conn, existing_primary_id, &primary_rec);
log_detail(_("current master is %s (node_id: %i)"),
master_rec.node_name,
existing_master_id);
log_detail(_("current primary is %s (node_id: %i)"),
primary_rec.node_name,
existing_primary_id);
}
PQfinish(current_master_conn);
PQfinish(current_primary_conn);
PQfinish(conn);
exit(ERR_PROMOTION_FAIL);
}
@@ -1121,7 +1122,7 @@ do_standby_promote(void)
log_notice(_("promoting standby"));
/*
* Promote standby to master.
* Promote standby to primary.
*
* `pg_ctl promote` returns immediately and (prior to 10.0) has no -w option
* so we can't be sure when or if the promotion completes.
@@ -1144,7 +1145,7 @@ do_standby_promote(void)
r = system(script);
if (r != 0)
{
log_error(_("unable to promote server from standby to master"));
log_error(_("unable to promote server from standby to primary"));
exit(ERR_PROMOTION_FAIL);
}
@@ -1157,7 +1158,7 @@ do_standby_promote(void)
{
recovery_type = get_recovery_type(conn);
if (recovery_type == RECTYPE_MASTER)
if (recovery_type == RECTYPE_PRIMARY)
{
promote_success = true;
break;
@@ -1183,7 +1184,7 @@ do_standby_promote(void)
/* update node information to reflect new status */
if (update_node_record_set_master(conn, config_file_options.node_id) == false)
if (update_node_record_set_primary(conn, config_file_options.node_id) == false)
{
initPQExpBuffer(&details);
appendPQExpBuffer(&details,
@@ -1205,7 +1206,7 @@ do_standby_promote(void)
initPQExpBuffer(&details);
appendPQExpBuffer(&details,
_("node %i was successfully promoted to master"),
_("node %i was successfully promoted to primary"),
config_file_options.node_id);
log_notice(_("STANDBY PROMOTE successful"));
@@ -1243,9 +1244,9 @@ do_standby_follow(void)
t_node_info local_node_record = T_NODE_INFO_INITIALIZER;
int original_upstream_node_id = UNKNOWN_NODE_ID;
PGconn *master_conn = NULL;
int master_id = UNKNOWN_NODE_ID;
t_node_info master_node_record = T_NODE_INFO_INITIALIZER;
PGconn *primary_conn = NULL;
int primary_id = UNKNOWN_NODE_ID;
t_node_info primary_node_record = T_NODE_INFO_INITIALIZER;
char data_dir[MAXPGPATH];
t_conninfo_param_list recovery_conninfo;
@@ -1285,32 +1286,32 @@ do_standby_follow(void)
}
/*
* Attempt to connect to master.
* Attempt to connect to primary.
*
* If --wait provided, loop for up `master_response_timeout`
* If --wait provided, loop for up `primary_response_timeout`
* seconds before giving up
*/
for (timer = 0; timer < config_file_options.master_response_timeout; timer++)
for (timer = 0; timer < config_file_options.primary_response_timeout; timer++)
{
master_conn = get_master_connection_quiet(local_conn,
&master_id,
NULL);
primary_conn = get_primary_connection_quiet(local_conn,
&primary_id,
NULL);
if (PQstatus(master_conn) == CONNECTION_OK || runtime_options.wait == false)
if (PQstatus(primary_conn) == CONNECTION_OK || runtime_options.wait == false)
{
break;
}
}
if (PQstatus(master_conn) != CONNECTION_OK)
if (PQstatus(primary_conn) != CONNECTION_OK)
{
log_error(_("unable to determine master node"));
log_error(_("unable to determine primary node"));
PQfinish(local_conn);
exit(ERR_BAD_CONFIG);
}
check_master_standby_version_match(local_conn, master_conn);
check_primary_standby_version_match(local_conn, primary_conn);
PQfinish(local_conn);
}
@@ -1321,20 +1322,20 @@ do_standby_follow(void)
*/
else
{
master_conn = establish_db_connection_by_params(
primary_conn = establish_db_connection_by_params(
(const char**)source_conninfo.keywords,
(const char**)source_conninfo.values,
true);
master_id = get_master_node_id(master_conn);
primary_id = get_primary_node_id(primary_conn);
strncpy(data_dir, runtime_options.data_dir, MAXPGPATH);
}
if (get_recovery_type(master_conn) != RECTYPE_MASTER)
if (get_recovery_type(primary_conn) != RECTYPE_PRIMARY)
{
log_error(_("the node to follow is not a master"));
log_error(_("the node to follow is not a primary"));
// XXX log detail
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
@@ -1342,55 +1343,55 @@ do_standby_follow(void)
/*
* If 9.4 or later, and replication slots in use, we'll need to create a
* slot on the new master
* slot on the new primary
*/
if (config_file_options.use_replication_slots)
{
int server_version_num = get_server_version(master_conn, NULL);
int server_version_num = get_server_version(primary_conn, NULL);
PQExpBufferData event_details;
initPQExpBuffer(&event_details);
if (create_replication_slot(master_conn, repmgr_slot_name, server_version_num, &event_details) == false)
if (create_replication_slot(primary_conn, repmgr_slot_name, server_version_num, &event_details) == false)
{
log_error("%s", event_details.data);
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_follow",
false,
event_details.data);
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_DB_QUERY);
}
termPQExpBuffer(&event_details);
}
get_node_record(master_conn, master_id, &master_node_record);
get_node_record(primary_conn, primary_id, &primary_node_record);
/* Initialise connection parameters to write as `primary_conninfo` */
initialize_conninfo_params(&recovery_conninfo, false);
/* We ignore any application_name set in the master's conninfo */
parse_conninfo_string(master_node_record.conninfo, &recovery_conninfo, errmsg, true);
/* We ignore any application_name set in the primary's conninfo */
parse_conninfo_string(primary_node_record.conninfo, &recovery_conninfo, errmsg, true);
/* Set the default application name to this node's name */
param_set(&recovery_conninfo, "application_name", config_file_options.node_name);
/* Set the replication user from the master node record */
param_set(&recovery_conninfo, "user", master_node_record.repluser);
/* Set the replication user from the primary node record */
param_set(&recovery_conninfo, "user", primary_node_record.repluser);
/*
* Fetch our node record so we can write application_name, if set,
* and to get the upstream node ID, which we'll need to know if
* replication slots are in use and we want to delete the old slot.
*/
record_status = get_node_record(master_conn,
record_status = get_node_record(primary_conn,
config_file_options.node_id,
&local_node_record);
@@ -1433,16 +1434,16 @@ do_standby_follow(void)
}
else
{
original_upstream_node_id = master_id;
original_upstream_node_id = primary_id;
}
}
log_info(_("changing node %i's master to node %i"),
config_file_options.node_id, master_id);
log_info(_("changing node %i's primary to node %i"),
config_file_options.node_id, primary_id);
if (!create_recovery_file(data_dir, &recovery_conninfo))
{
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
@@ -1471,7 +1472,7 @@ do_standby_follow(void)
if (r != 0)
{
log_error(_("unable to restart server"));
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_NO_RESTART);
}
@@ -1480,7 +1481,7 @@ do_standby_follow(void)
* If replication slots are in use, and an inactive one for this node
* exists on the former upstream, drop it.
*
* XXX check if former upstream is current master?
* XXX check if former upstream is current primary?
*/
if (config_file_options.use_replication_slots && runtime_options.host_param_provided == false && original_upstream_node_id != UNKNOWN_NODE_ID)
@@ -1528,28 +1529,28 @@ do_standby_follow(void)
* It's possible this node was an inactive primary - update the
* relevant fields to ensure it's marked as an active standby
*/
if (update_node_record_status(master_conn,
if (update_node_record_status(primary_conn,
config_file_options.node_id,
"standby",
master_id,
primary_id,
true) == false)
{
log_error(_("unable to update upstream node"));
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
log_notice(_("STANDBY FOLLOW successful"));
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_follow",
true,
NULL);
PQfinish(master_conn);
PQfinish(primary_conn);
return;
}
@@ -1616,7 +1617,7 @@ check_source_server()
/* Verify that upstream node is a supported server version */
log_verbose(LOG_INFO, _("connected to source node, checking its state"));
server_version_num = check_server_version(source_conn, "master", true, NULL);
server_version_num = check_server_version(source_conn, "primary", true, NULL);
check_upstream_config(source_conn, server_version_num, true);
@@ -1648,22 +1649,22 @@ check_source_server()
*/
if (get_recovery_type(source_conn) == RECTYPE_STANDBY)
{
master_conn = get_master_connection(source_conn, NULL, NULL);
primary_conn = get_primary_connection(source_conn, NULL, NULL);
// XXX check this worked?
}
else
{
master_conn = source_conn;
primary_conn = source_conn;
}
/*
* Sanity-check that the master node has a repmgr schema - if not
* Sanity-check that the primary node has a repmgr schema - if not
* present, fail with an error unless -F/--force is used (to enable
* repmgr to be used as a standalone clone tool)
*/
extension_status = get_repmgr_extension_status(master_conn);
extension_status = get_repmgr_extension_status(primary_conn);
if (extension_status != REPMGR_INSTALLED)
{
@@ -1751,7 +1752,7 @@ check_source_server()
* Attempt to find the upstream node record
*/
if (config_file_options.upstream_node_id == NO_UPSTREAM_NODE)
upstream_node_id = get_master_node_id(source_conn);
upstream_node_id = get_primary_node_id(source_conn);
else
upstream_node_id = config_file_options.upstream_node_id;
@@ -2087,7 +2088,7 @@ initialise_direct_clone(void)
{
log_error("%s", event_details.data);
create_event_record(master_conn,
create_event_record(primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_clone",
@@ -2210,7 +2211,7 @@ run_basebackup(void)
*
* From 9.6, if replication slots are in use, we'll have previously
* created a slot with reserved LSN, and will stream from that slot to avoid
* WAL buildup on the master using the -S/--slot, which requires -X/--xlog-method=stream
* WAL buildup on the primary using the -S/--slot, which requires -X/--xlog-method=stream
* (from 10, -X/--wal-method=stream)
*/
if (!strlen(backup_options.xlog_method))
@@ -2951,7 +2952,7 @@ tablespace_data_append(TablespaceDataList *list, const char *name, const char *o
/*
* check_master_standby_version_match()
* check_primary_standby_version_match()
*
* Check server versions of supplied connections are compatible for
* replication purposes.
@@ -2959,32 +2960,32 @@ tablespace_data_append(TablespaceDataList *list, const char *name, const char *o
* Exits on error.
*/
static void
check_master_standby_version_match(PGconn *conn, PGconn *master_conn)
check_primary_standby_version_match(PGconn *conn, PGconn *primary_conn)
{
char standby_version[MAXVERSIONSTR];
int standby_version_num = 0;
char master_version[MAXVERSIONSTR];
int master_version_num = 0;
char primary_version[MAXVERSIONSTR];
int primary_version_num = 0;
standby_version_num = check_server_version(conn, "standby", true, standby_version);
/* Verify that master is a supported server version */
master_version_num = check_server_version(conn, "master", false, master_version);
if (master_version_num < 0)
/* Verify that primary is a supported server version */
primary_version_num = check_server_version(conn, "primary", false, primary_version);
if (primary_version_num < 0)
{
PQfinish(conn);
PQfinish(master_conn);
PQfinish(primary_conn);
exit(ERR_BAD_CONFIG);
}
/* master and standby version should match */
if ((master_version_num / 100) != (standby_version_num / 100))
/* primary and standby version should match */
if ((primary_version_num / 100) != (standby_version_num / 100))
{
PQfinish(conn);
PQfinish(master_conn);
log_error(_("PostgreSQL versions on master (%s) and standby (%s) must match"),
master_version, standby_version);
PQfinish(primary_conn);
log_error(_("PostgreSQL versions on primary (%s) and standby (%s) must match"),
primary_version, standby_version);
exit(ERR_BAD_CONFIG);
}
}
@@ -2997,7 +2998,7 @@ check_recovery_type(PGconn *conn)
if (recovery_type != RECTYPE_STANDBY)
{
if (recovery_type == RECTYPE_MASTER)
if (recovery_type == RECTYPE_PRIMARY)
{
log_error(_("this node should be a standby (%s)"),
config_file_options.conninfo);

View File

@@ -8,8 +8,8 @@
*
* Commands implemented are:
*
* [ MASTER | PRIMARY ] REGISTER
* [ MASTER | PRIMARY ] UNREGISTER
* [ PRIMARY | MASTER ] REGISTER
* [ PRIMARY | MASTER ] UNREGISTER
*
* STANDBY CLONE
* STANDBY REGISTER
@@ -26,7 +26,7 @@
#include "compat.h"
#include "repmgr-client.h"
#include "repmgr-client-global.h"
#include "repmgr-action-master.h"
#include "repmgr-action-primary.h"
#include "repmgr-action-standby.h"
#include "repmgr-action-cluster.h"
@@ -204,7 +204,7 @@ main(int argc, char **argv)
runtime_options.force = true;
break;
/* --replication-user (master/standby register only) */
/* --replication-user (primary/standby register only) */
case OPT_REPLICATION_USER:
strncpy(runtime_options.replication_user, optarg, MAXLEN);
break;
@@ -546,7 +546,7 @@ main(int argc, char **argv)
/*
* Determine the node type and action; following are valid:
*
* { MASTER | PRIMARY } REGISTER |
* { PRIMARY | MASTER } REGISTER |
* STANDBY {REGISTER | UNREGISTER | CLONE [node] | PROMOTE | FOLLOW [node] | SWITCHOVER | REWIND} |
* WITNESS { CREATE | REGISTER | UNREGISTER } |
* BDR { REGISTER | UNREGISTER } |
@@ -570,12 +570,12 @@ main(int argc, char **argv)
if (repmgr_node_type != NULL)
{
if (strcasecmp(repmgr_node_type, "MASTER") == 0 || strcasecmp(repmgr_node_type, "PRIMARY") == 0 )
if (strcasecmp(repmgr_node_type, "PRIMARY") == 0 || strcasecmp(repmgr_node_type, "MASTER") == 0 )
{
if (strcasecmp(repmgr_action, "REGISTER") == 0)
action = MASTER_REGISTER;
action = PRIMARY_REGISTER;
else if (strcasecmp(repmgr_action, "UNREGISTER") == 0)
action = MASTER_UNREGISTER;
action = PRIMARY_UNREGISTER;
}
else if (strcasecmp(repmgr_node_type, "STANDBY") == 0)
{
@@ -784,16 +784,16 @@ main(int argc, char **argv)
if (runtime_options.node_id != UNKNOWN_NODE_ID || runtime_options.node_name[0] != '\0')
{
PGconn *conn;
int record_found;
RecordStatus record_status;
log_verbose(LOG_DEBUG, "connecting to local node to retrieve record for node specified with --node-id or --node-name");
conn = establish_db_connection(config_file_options.conninfo, true);
if (runtime_options.node_id != UNKNOWN_NODE_ID)
{
record_found = get_node_record(conn, runtime_options.node_id, &target_node_info);
record_status = get_node_record(conn, runtime_options.node_id, &target_node_info);
if (!record_found)
if (record_status != RECORD_FOUND)
{
log_error(_("node %i (specified with --node-id) not found"),
runtime_options.node_id);
@@ -811,10 +811,10 @@ main(int argc, char **argv)
exit(ERR_BAD_CONFIG);
}
record_found = get_node_record_by_name(conn, escaped, &target_node_info);
record_status = get_node_record_by_name(conn, escaped, &target_node_info);
pfree(escaped);
if (!record_found)
if (record_status != RECORD_FOUND)
{
log_error(_("node %s (specified with --node-name) not found"),
runtime_options.node_name);
@@ -830,7 +830,7 @@ main(int argc, char **argv)
* Initialise slot name, if required (9.4 and later)
*
* NOTE: the slot name will be defined for each record, including
* the master; the `slot_name` column in `repl_nodes` defines
* the primary; the `slot_name` column in `repl_nodes` defines
* the name of the slot, but does not imply a slot has been created.
* The version check for 9.4 or later is done in check_upstream_config()
*/
@@ -843,11 +843,11 @@ main(int argc, char **argv)
switch (action)
{
case MASTER_REGISTER:
do_master_register();
case PRIMARY_REGISTER:
do_primary_register();
break;
case MASTER_UNREGISTER:
do_master_unregister();
case PRIMARY_UNREGISTER:
do_primary_unregister();
break;
case STANDBY_CLONE:
@@ -910,7 +910,7 @@ check_cli_parameters(const int action)
*/
switch (action)
{
case MASTER_REGISTER:
case PRIMARY_REGISTER:
/* no required parameters */
break;
case STANDBY_CLONE:
@@ -1041,7 +1041,7 @@ check_cli_parameters(const int action)
{
switch (action)
{
case MASTER_UNREGISTER:
case PRIMARY_UNREGISTER:
case STANDBY_UNREGISTER:
case WITNESS_UNREGISTER:
case CLUSTER_EVENT:
@@ -1093,7 +1093,7 @@ check_cli_parameters(const int action)
{
switch (action)
{
case MASTER_REGISTER:
case PRIMARY_REGISTER:
case STANDBY_REGISTER:
break;
case STANDBY_CLONE:
@@ -1153,8 +1153,8 @@ action_name(const int action)
{
switch(action)
{
case MASTER_REGISTER:
return "MASTER REGISTER";
case PRIMARY_REGISTER:
return "PRIMARY REGISTER";
case STANDBY_CLONE:
return "STANDBY CLONE";
case STANDBY_REGISTER:
@@ -1208,8 +1208,8 @@ do_help(void)
}
printf(_("Usage:\n"));
printf(_(" %s [OPTIONS] master register\n"), progname());
printf(_(" %s [OPTIONS] master unregister\n"), progname());
printf(_(" %s [OPTIONS] primary register\n"), progname());
printf(_(" %s [OPTIONS] primary unregister\n"), progname());
printf(_(" %s [OPTIONS] standby clone\n"), progname());
printf(_(" %s [OPTIONS] standby register\n"), progname());
printf(_(" %s [OPTIONS] standby unregister\n"), progname());
@@ -1416,7 +1416,7 @@ create_repmgr_extension(PGconn *conn)
* the connection to check
*
* char *server_type:
* either "master" or "standby"; used to format error message
* either "primary" or "standby"; used to format error message
*
* bool exit_on_error:
* exit if reported server version is too low; optional to enable some callers

View File

@@ -12,8 +12,8 @@
#define NO_ACTION 0 /* Dummy default action */
#define MASTER_REGISTER 1
#define MASTER_UNREGISTER 2
#define PRIMARY_REGISTER 1
#define PRIMARY_UNREGISTER 2
#define STANDBY_REGISTER 3
#define STANDBY_UNREGISTER 4
#define STANDBY_CLONE 5

View File

@@ -24,7 +24,7 @@ t_configuration_options config_file_options = T_CONFIGURATION_OPTIONS_INITIALIZE
static t_node_info local_node_info = T_NODE_INFO_INITIALIZER;
static PGconn *local_conn = NULL;
static PGconn *master_conn = NULL;
static PGconn *primary_conn = NULL;
/* Collate command line errors here for friendlier reporting */
static ItemList cli_errors = { NULL, NULL };
@@ -41,7 +41,7 @@ static void daemonize_process(void);
static void check_and_create_pid_file(const char *pid_file);
static void start_monitoring(void);
static void monitor_streaming_master(void);
static void monitor_streaming_primary(void);
static void monitor_streaming_standby(void);
#ifndef WIN32
@@ -248,7 +248,7 @@ main(int argc, char **argv)
if (record_status != RECORD_FOUND)
{
log_error(_("no metadata record found for this node - terminating"));
log_hint(_("Check that 'repmgr (master|standby) register' was executed for this node"));
log_hint(_("Check that 'repmgr (primary|standby) register' was executed for this node"));
PQfinish(local_conn);
terminate(ERR_BAD_CONFIG);
@@ -271,7 +271,7 @@ main(int argc, char **argv)
if (local_node_info.active == false)
{
char *hint = "Check that 'repmgr (master|standby) register' was executed for this node";
char *hint = "Check that 'repmgr (primary|standby) register' was executed for this node";
switch (config_file_options.failover_mode)
{
@@ -354,8 +354,8 @@ start_monitoring(void)
{
switch (local_node_info.type)
{
case MASTER:
monitor_streaming_master();
case PRIMARY:
monitor_streaming_primary();
break;
case STANDBY:
monitor_streaming_standby();
@@ -372,7 +372,7 @@ start_monitoring(void)
static void
monitor_streaming_master(void)
monitor_streaming_primary(void)
{
while (true)
{
@@ -586,12 +586,12 @@ show_help(void)
static void
close_connections()
{
if (PQstatus(master_conn) == CONNECTION_OK)
if (PQstatus(primary_conn) == CONNECTION_OK)
{
/* cancel any pending queries to the master */
if (PQisBusy(master_conn) == 1)
cancel_query(master_conn, config_file_options.master_response_timeout);
PQfinish(master_conn);
/* cancel any pending queries to the primary */
if (PQisBusy(primary_conn) == 1)
cancel_query(primary_conn, config_file_options.primary_response_timeout);
PQfinish(primary_conn);
}
if (PQstatus(local_conn) == CONNECTION_OK)