mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Add "location" column
This commit is contained in:
4
config.c
4
config.c
@@ -235,6 +235,8 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
|||||||
* ---------------- */
|
* ---------------- */
|
||||||
options->failover_mode = FAILOVER_MANUAL;
|
options->failover_mode = FAILOVER_MANUAL;
|
||||||
options->priority = DEFAULT_PRIORITY;
|
options->priority = DEFAULT_PRIORITY;
|
||||||
|
memset(options->location, 0, sizeof(options->location));
|
||||||
|
strncpy(options->location, DEFAULT_LOCATION, MAXLEN);
|
||||||
memset(options->promote_command, 0, sizeof(options->promote_command));
|
memset(options->promote_command, 0, sizeof(options->promote_command));
|
||||||
memset(options->follow_command, 0, sizeof(options->follow_command));
|
memset(options->follow_command, 0, sizeof(options->follow_command));
|
||||||
options->monitor_interval_secs = 2;
|
options->monitor_interval_secs = 2;
|
||||||
@@ -399,6 +401,8 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
|||||||
}
|
}
|
||||||
else if (strcmp(name, "priority") == 0)
|
else if (strcmp(name, "priority") == 0)
|
||||||
options->priority = repmgr_atoi(value, name, error_list, 0);
|
options->priority = repmgr_atoi(value, name, error_list, 0);
|
||||||
|
else if (strcmp(name, "location") == 0)
|
||||||
|
strncpy(options->location, value, MAXLEN);
|
||||||
else if (strcmp(name, "promote_command") == 0)
|
else if (strcmp(name, "promote_command") == 0)
|
||||||
strncpy(options->promote_command, value, MAXLEN);
|
strncpy(options->promote_command, value, MAXLEN);
|
||||||
else if (strcmp(name, "follow_command") == 0)
|
else if (strcmp(name, "follow_command") == 0)
|
||||||
|
|||||||
3
config.h
3
config.h
@@ -73,6 +73,7 @@ typedef struct
|
|||||||
|
|
||||||
/* repmgrd settings */
|
/* repmgrd settings */
|
||||||
failover_mode_opt failover_mode;
|
failover_mode_opt failover_mode;
|
||||||
|
char location[MAXLEN];
|
||||||
int priority;
|
int priority;
|
||||||
char promote_command[MAXLEN];
|
char promote_command[MAXLEN];
|
||||||
char follow_command[MAXLEN];
|
char follow_command[MAXLEN];
|
||||||
@@ -123,7 +124,7 @@ typedef struct
|
|||||||
/* standby clone settings */ \
|
/* standby clone settings */ \
|
||||||
false, "", "", "", "", { NULL, NULL }, \
|
false, "", "", "", "", { NULL, NULL }, \
|
||||||
/* repmgrd settings */ \
|
/* repmgrd settings */ \
|
||||||
FAILOVER_MANUAL, DEFAULT_PRIORITY, "", "", 2, 60, 6, 10, 300, false, \
|
FAILOVER_MANUAL, DEFAULT_LOCATION, DEFAULT_PRIORITY, "", "", 2, 60, 6, 10, 300, false, \
|
||||||
/* witness settings */ \
|
/* witness settings */ \
|
||||||
30, \
|
30, \
|
||||||
/* service settings */ \
|
/* service settings */ \
|
||||||
|
|||||||
33
dbutils.c
33
dbutils.c
@@ -1204,8 +1204,9 @@ _populate_node_record(PGresult *res, t_node_info *node_info, int row)
|
|||||||
strncpy(node_info->conninfo, PQgetvalue(res, row, 4), MAXLEN);
|
strncpy(node_info->conninfo, PQgetvalue(res, row, 4), MAXLEN);
|
||||||
strncpy(node_info->repluser, PQgetvalue(res, row, 5), MAXLEN);
|
strncpy(node_info->repluser, PQgetvalue(res, row, 5), MAXLEN);
|
||||||
strncpy(node_info->slot_name, PQgetvalue(res, row, 6), MAXLEN);
|
strncpy(node_info->slot_name, PQgetvalue(res, row, 6), MAXLEN);
|
||||||
node_info->priority = atoi(PQgetvalue(res, row, 7));
|
strncpy(node_info->location, PQgetvalue(res, row, 7), MAXLEN);
|
||||||
node_info->active = atobool(PQgetvalue(res, row, 8));
|
node_info->priority = atoi(PQgetvalue(res, row, 8));
|
||||||
|
node_info->active = atobool(PQgetvalue(res, row, 9));
|
||||||
|
|
||||||
/* Set remaining struct fields with default values */
|
/* Set remaining struct fields with default values */
|
||||||
node_info->is_ready = false;
|
node_info->is_ready = false;
|
||||||
@@ -1267,7 +1268,7 @@ get_node_record(PGconn *conn, int node_id, t_node_info *node_info)
|
|||||||
|
|
||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
appendPQExpBuffer(&query,
|
appendPQExpBuffer(&query,
|
||||||
"SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, priority, active"
|
"SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, location, priority, active"
|
||||||
" FROM repmgr.nodes "
|
" FROM repmgr.nodes "
|
||||||
" WHERE node_id = %i",
|
" WHERE node_id = %i",
|
||||||
node_id);
|
node_id);
|
||||||
@@ -1295,7 +1296,7 @@ get_node_record_by_name(PGconn *conn, const char *node_name, t_node_info *node_i
|
|||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
appendPQExpBuffer(&query,
|
appendPQExpBuffer(&query,
|
||||||
"SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, priority, active"
|
"SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, location, priority, active"
|
||||||
" FROM repmgr.nodes "
|
" FROM repmgr.nodes "
|
||||||
" WHERE node_name = '%s' ",
|
" WHERE node_name = '%s' ",
|
||||||
node_name);
|
node_name);
|
||||||
@@ -1405,7 +1406,7 @@ get_downstream_node_records(PGconn *conn, int node_id, NodeInfoList *node_list)
|
|||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
appendPQExpBuffer(&query,
|
appendPQExpBuffer(&query,
|
||||||
" SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, priority, active"
|
" SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, location, priority, active"
|
||||||
" FROM repmgr.nodes "
|
" FROM repmgr.nodes "
|
||||||
" WHERE upstream_node_id = %i "
|
" WHERE upstream_node_id = %i "
|
||||||
"ORDER BY node_id ",
|
"ORDER BY node_id ",
|
||||||
@@ -1432,7 +1433,7 @@ get_active_sibling_node_records(PGconn *conn, int node_id, int upstream_node_id,
|
|||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
appendPQExpBuffer(&query,
|
appendPQExpBuffer(&query,
|
||||||
" SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, priority, active"
|
" SELECT node_id, type, upstream_node_id, node_name, conninfo, repluser, slot_name, location, priority, active"
|
||||||
" FROM repmgr.nodes "
|
" FROM repmgr.nodes "
|
||||||
" WHERE upstream_node_id = %i "
|
" WHERE upstream_node_id = %i "
|
||||||
" AND node_id != %i "
|
" AND node_id != %i "
|
||||||
@@ -1484,7 +1485,7 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info)
|
|||||||
char slot_name[MAXLEN];
|
char slot_name[MAXLEN];
|
||||||
char *slot_name_ptr = NULL;
|
char *slot_name_ptr = NULL;
|
||||||
|
|
||||||
int param_count = 9;
|
int param_count = 10;
|
||||||
const char *param_values[param_count];
|
const char *param_values[param_count];
|
||||||
|
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
@@ -1518,9 +1519,10 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info)
|
|||||||
param_values[3] = node_info->conninfo;
|
param_values[3] = node_info->conninfo;
|
||||||
param_values[4] = node_info->repluser;
|
param_values[4] = node_info->repluser;
|
||||||
param_values[5] = slot_name_ptr;
|
param_values[5] = slot_name_ptr;
|
||||||
param_values[6] = priority;
|
param_values[6] = node_info->location;
|
||||||
param_values[7] = node_info->active == true ? "TRUE" : "FALSE";
|
param_values[7] = priority;
|
||||||
param_values[8] = node_id;
|
param_values[8] = node_info->active == true ? "TRUE" : "FALSE";
|
||||||
|
param_values[9] = node_id;
|
||||||
|
|
||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
@@ -1530,8 +1532,8 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info)
|
|||||||
"INSERT INTO repmgr.nodes "
|
"INSERT INTO repmgr.nodes "
|
||||||
" (node_id, type, upstream_node_id, "
|
" (node_id, type, upstream_node_id, "
|
||||||
" node_name, conninfo, repluser, slot_name, "
|
" node_name, conninfo, repluser, slot_name, "
|
||||||
" priority, active) "
|
" location, priority, active) "
|
||||||
"VALUES ($9, $1, $2, $3, $4, $5, $6, $7, $8) ");
|
"VALUES ($10, $1, $2, $3, $4, $5, $6, $7, $8, $9) ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1543,9 +1545,10 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info)
|
|||||||
" conninfo = $4, "
|
" conninfo = $4, "
|
||||||
" repluser = $5, "
|
" repluser = $5, "
|
||||||
" slot_name = $6, "
|
" slot_name = $6, "
|
||||||
" priority = $7, "
|
" location = $7, "
|
||||||
" active = $8 "
|
" priority = $8, "
|
||||||
" WHERE node_id = $9 ");
|
" active = $9 "
|
||||||
|
" WHERE node_id = $10 ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,10 @@ typedef struct s_node_info
|
|||||||
char node_name[MAXLEN];
|
char node_name[MAXLEN];
|
||||||
char conninfo[MAXLEN];
|
char conninfo[MAXLEN];
|
||||||
char repluser[NAMEDATALEN];
|
char repluser[NAMEDATALEN];
|
||||||
char slot_name[MAXLEN];
|
char location[MAXLEN];
|
||||||
int priority;
|
int priority;
|
||||||
bool active;
|
bool active;
|
||||||
|
char slot_name[MAXLEN];
|
||||||
/* used during failover to track node status */
|
/* used during failover to track node status */
|
||||||
bool is_ready;
|
bool is_ready;
|
||||||
bool is_visible;
|
bool is_visible;
|
||||||
@@ -73,9 +74,10 @@ typedef struct s_node_info
|
|||||||
"", \
|
"", \
|
||||||
"", \
|
"", \
|
||||||
"", \
|
"", \
|
||||||
"", \
|
DEFAULT_LOCATION, \
|
||||||
DEFAULT_PRIORITY, \
|
DEFAULT_PRIORITY, \
|
||||||
true, \
|
true, \
|
||||||
|
"", \
|
||||||
false, \
|
false, \
|
||||||
false, \
|
false, \
|
||||||
InvalidXLogRecPtr, \
|
InvalidXLogRecPtr, \
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ Changed command line options
|
|||||||
The value (defaults to the user in the conninfo string) will be stored in
|
The value (defaults to the user in the conninfo string) will be stored in
|
||||||
the repmgr metadata for use by standby clone/follow..
|
the repmgr metadata for use by standby clone/follow..
|
||||||
|
|
||||||
|
|
||||||
### repmgrd
|
### repmgrd
|
||||||
|
|
||||||
- `--monitoring-history` is deprecated and has been replaced by the
|
- `--monitoring-history` is deprecated and has been replaced by the
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ CREATE TABLE nodes (
|
|||||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
node_name TEXT NOT NULL,
|
node_name TEXT NOT NULL,
|
||||||
type TEXT NOT NULL CHECK (type IN('primary','standby','witness','bdr')),
|
type TEXT NOT NULL CHECK (type IN('primary','standby','witness','bdr')),
|
||||||
|
location TEXT NOT NULL DEFAULT 'default',
|
||||||
priority INT NOT NULL DEFAULT 100,
|
priority INT NOT NULL DEFAULT 100,
|
||||||
conninfo TEXT NOT NULL,
|
conninfo TEXT NOT NULL,
|
||||||
repluser VARCHAR(63) NOT NULL,
|
repluser VARCHAR(63) NOT NULL,
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ do_primary_register(void)
|
|||||||
|
|
||||||
if (config_file_options.replication_user[0] != '\0')
|
if (config_file_options.replication_user[0] != '\0')
|
||||||
{
|
{
|
||||||
strncpy(node_info.repluser, config_file_options.replication_user, MAXLEN);
|
strncpy(node_info.repluser, config_file_options.replication_user, NAMEDATALEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -160,6 +160,7 @@ do_primary_register(void)
|
|||||||
if (repmgr_slot_name_ptr != NULL)
|
if (repmgr_slot_name_ptr != NULL)
|
||||||
strncpy(node_info.slot_name, repmgr_slot_name_ptr, MAXLEN);
|
strncpy(node_info.slot_name, repmgr_slot_name_ptr, MAXLEN);
|
||||||
|
|
||||||
|
strncpy(node_info.location, config_file_options.location, MAXLEN);
|
||||||
node_info.priority = config_file_options.priority;
|
node_info.priority = config_file_options.priority;
|
||||||
|
|
||||||
initPQExpBuffer(&event_description);
|
initPQExpBuffer(&event_description);
|
||||||
|
|||||||
@@ -781,13 +781,17 @@ do_standby_register(void)
|
|||||||
node_record.priority = config_file_options.priority;
|
node_record.priority = config_file_options.priority;
|
||||||
node_record.active = true;
|
node_record.active = true;
|
||||||
|
|
||||||
|
strncpy(node_record.location, config_file_options.location, MAXLEN);
|
||||||
|
|
||||||
|
printf("XXX %s %s\n", node_record.location, config_file_options.location);
|
||||||
|
|
||||||
strncpy(node_record.node_name, config_file_options.node_name, MAXLEN);
|
strncpy(node_record.node_name, config_file_options.node_name, MAXLEN);
|
||||||
strncpy(node_record.conninfo, config_file_options.conninfo, MAXLEN);
|
strncpy(node_record.conninfo, config_file_options.conninfo, MAXLEN);
|
||||||
|
|
||||||
if (config_file_options.replication_user[0] != '\0')
|
if (config_file_options.replication_user[0] != '\0')
|
||||||
{
|
{
|
||||||
/* Replication user explicitly provided */
|
/* Replication user explicitly provided */
|
||||||
strncpy(node_record.repluser, config_file_options.replication_user, MAXLEN);
|
strncpy(node_record.repluser, config_file_options.replication_user, NAMEDATALEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -820,11 +824,11 @@ do_standby_register(void)
|
|||||||
/* XXX add event description */
|
/* XXX add event description */
|
||||||
|
|
||||||
create_event_notification(primary_conn,
|
create_event_notification(primary_conn,
|
||||||
&config_file_options,
|
&config_file_options,
|
||||||
config_file_options.node_id,
|
config_file_options.node_id,
|
||||||
"standby_register",
|
"standby_register",
|
||||||
false,
|
false,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
PQfinish(primary_conn);
|
PQfinish(primary_conn);
|
||||||
|
|
||||||
@@ -835,11 +839,11 @@ do_standby_register(void)
|
|||||||
|
|
||||||
/* Log the event */
|
/* Log the event */
|
||||||
create_event_notification(primary_conn,
|
create_event_notification(primary_conn,
|
||||||
&config_file_options,
|
&config_file_options,
|
||||||
config_file_options.node_id,
|
config_file_options.node_id,
|
||||||
"standby_register",
|
"standby_register",
|
||||||
true,
|
true,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* if --wait-sync option set, wait for the records to synchronise */
|
/* if --wait-sync option set, wait for the records to synchronise */
|
||||||
|
|
||||||
|
|||||||
1
repmgr.h
1
repmgr.h
@@ -33,6 +33,7 @@
|
|||||||
#define BDR_MONITORING_LOCAL 1
|
#define BDR_MONITORING_LOCAL 1
|
||||||
#define BDR_MONITORING_PRIORITY 2
|
#define BDR_MONITORING_PRIORITY 2
|
||||||
|
|
||||||
|
#define DEFAULT_LOCATION "default"
|
||||||
#define DEFAULT_PRIORITY 100
|
#define DEFAULT_PRIORITY 100
|
||||||
#define FAILOVER_NODES_MAX_CHECK 50
|
#define FAILOVER_NODES_MAX_CHECK 50
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user