mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Store upstream node ID if set
Required to manage cascaded standbys
This commit is contained in:
2
config.c
2
config.c
@@ -85,6 +85,8 @@ parse_config(const char *config_file, t_configuration_options * options)
|
||||
strncpy(options->cluster_name, value, MAXLEN);
|
||||
else if (strcmp(name, "node") == 0)
|
||||
options->node = atoi(value);
|
||||
else if (strcmp(name, "upstream_node") == 0)
|
||||
options->upstream_node = atoi(value);
|
||||
else if (strcmp(name, "conninfo") == 0)
|
||||
strncpy(options->conninfo, value, MAXLEN);
|
||||
else if (strcmp(name, "rsync_options") == 0)
|
||||
|
||||
6
config.h
6
config.h
@@ -23,10 +23,13 @@
|
||||
#include "repmgr.h"
|
||||
#include "strutil.h"
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char cluster_name[MAXLEN];
|
||||
int node;
|
||||
int upstream_node;
|
||||
char conninfo[MAXLEN];
|
||||
int failover;
|
||||
int priority;
|
||||
@@ -47,7 +50,8 @@ typedef struct
|
||||
int retry_promote_interval_secs;
|
||||
} t_configuration_options;
|
||||
|
||||
#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "", "", 0, 0 }
|
||||
#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, NO_UPSTREAM_NODE, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "", "", 0, 0 }
|
||||
|
||||
|
||||
void parse_config(const char *config_file, t_configuration_options * options);
|
||||
void parse_line(char *buff, char *name, char *value);
|
||||
|
||||
24
repmgr.c
24
repmgr.c
@@ -65,7 +65,7 @@ static bool write_recovery_file_line(FILE *recovery_file, char *recovery_file_pa
|
||||
static int check_server_version(PGconn *conn, char *server_type, bool exit_on_error, char *server_version_string);
|
||||
static bool check_upstream_config(PGconn *conn, bool exit_on_error);
|
||||
|
||||
static bool create_node_record(PGconn *conn, char *action, int node, char *cluster_name, char *node_name, char *conninfo, int priority, bool witness);
|
||||
static bool create_node_record(PGconn *conn, char *action, int node, int upstream_node, char *cluster_name, char *node_name, char *conninfo, int priority, bool witness);
|
||||
|
||||
static void do_master_register(void);
|
||||
static void do_standby_register(void);
|
||||
@@ -632,6 +632,7 @@ do_master_register(void)
|
||||
node_record_created = create_node_record(conn,
|
||||
"master register",
|
||||
options.node,
|
||||
NO_UPSTREAM_NODE,
|
||||
options.cluster_name,
|
||||
options.node_name,
|
||||
options.conninfo,
|
||||
@@ -753,6 +754,7 @@ do_standby_register(void)
|
||||
node_record_created = create_node_record(master_conn,
|
||||
"standby register",
|
||||
options.node,
|
||||
options.upstream_node,
|
||||
options.cluster_name,
|
||||
options.node_name,
|
||||
options.conninfo,
|
||||
@@ -1555,6 +1557,7 @@ do_witness_create(void)
|
||||
node_record_created = create_node_record(masterconn,
|
||||
"witness create",
|
||||
options.node,
|
||||
NO_UPSTREAM_NODE,
|
||||
options.cluster_name,
|
||||
options.node_name,
|
||||
options.conninfo,
|
||||
@@ -2229,6 +2232,7 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
||||
node_record_created = create_node_record(witnessconn,
|
||||
"copy_configuration",
|
||||
atoi(PQgetvalue(res, i, 0)),
|
||||
NO_UPSTREAM_NODE,
|
||||
options.cluster_name,
|
||||
PQgetvalue(res, i, 1),
|
||||
PQgetvalue(res, i, 2),
|
||||
@@ -2480,17 +2484,29 @@ do_check_upstream_config(void)
|
||||
|
||||
|
||||
static bool
|
||||
create_node_record(PGconn *conn, char *action, int node, char *cluster_name, char *node_name, char *conninfo, int priority, bool witness)
|
||||
create_node_record(PGconn *conn, char *action, int node, int upstream_node, char *cluster_name, char *node_name, char *conninfo, int priority, bool witness)
|
||||
{
|
||||
char sqlquery[QUERY_STR_LEN];
|
||||
char upstream_node_id[QUERY_STR_LEN];
|
||||
PGresult *res;
|
||||
|
||||
if(upstream_node != NO_UPSTREAM_NODE)
|
||||
{
|
||||
sqlquery_snprintf(upstream_node_id, "%i", upstream_node);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlquery_snprintf(upstream_node_id, "%s", "NULL");
|
||||
}
|
||||
|
||||
sqlquery_snprintf(sqlquery,
|
||||
"INSERT INTO %s.repl_nodes "
|
||||
" (id, cluster, name, conninfo, priority, witness) "
|
||||
"VALUES (%d, '%s', '%s', '%s', %d, %s) ",
|
||||
" (id, upstream_node_id, cluster, "
|
||||
" name, conninfo, priority, witness) "
|
||||
"VALUES (%d, %s, '%s', '%s', '%s', %d, %s) ",
|
||||
get_repmgr_schema_quoted(conn),
|
||||
node,
|
||||
upstream_node_id,
|
||||
cluster_name,
|
||||
node_name,
|
||||
conninfo,
|
||||
|
||||
4
repmgr.h
4
repmgr.h
@@ -38,7 +38,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#define MAXFILENAME 1024
|
||||
#define ERRBUFF_SIZE 512
|
||||
#define ERRBUFF_SIZE 512
|
||||
|
||||
#define DEFAULT_CONFIG_FILE "./repmgr.conf"
|
||||
#define DEFAULT_WAL_KEEP_SEGMENTS "5000"
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
#define MANUAL_FAILOVER 0
|
||||
#define AUTOMATIC_FAILOVER 1
|
||||
|
||||
#define NO_UPSTREAM_NODE -1
|
||||
|
||||
/* Run time options type */
|
||||
typedef struct
|
||||
|
||||
Reference in New Issue
Block a user