Store upstream node ID if set

Required to manage cascaded standbys
This commit is contained in:
Ian Barwick
2015-01-16 00:29:43 +09:00
parent a20afe28ec
commit 3dfa33d01d
4 changed files with 29 additions and 7 deletions

View File

@@ -85,6 +85,8 @@ parse_config(const char *config_file, t_configuration_options * options)
strncpy(options->cluster_name, value, MAXLEN); strncpy(options->cluster_name, value, MAXLEN);
else if (strcmp(name, "node") == 0) else if (strcmp(name, "node") == 0)
options->node = atoi(value); options->node = atoi(value);
else if (strcmp(name, "upstream_node") == 0)
options->upstream_node = atoi(value);
else if (strcmp(name, "conninfo") == 0) else if (strcmp(name, "conninfo") == 0)
strncpy(options->conninfo, value, MAXLEN); strncpy(options->conninfo, value, MAXLEN);
else if (strcmp(name, "rsync_options") == 0) else if (strcmp(name, "rsync_options") == 0)

View File

@@ -23,10 +23,13 @@
#include "repmgr.h" #include "repmgr.h"
#include "strutil.h" #include "strutil.h"
typedef struct typedef struct
{ {
char cluster_name[MAXLEN]; char cluster_name[MAXLEN];
int node; int node;
int upstream_node;
char conninfo[MAXLEN]; char conninfo[MAXLEN];
int failover; int failover;
int priority; int priority;
@@ -47,7 +50,8 @@ typedef struct
int retry_promote_interval_secs; int retry_promote_interval_secs;
} t_configuration_options; } 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_config(const char *config_file, t_configuration_options * options);
void parse_line(char *buff, char *name, char *value); void parse_line(char *buff, char *name, char *value);

View File

@@ -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 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 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_master_register(void);
static void do_standby_register(void); static void do_standby_register(void);
@@ -632,6 +632,7 @@ do_master_register(void)
node_record_created = create_node_record(conn, node_record_created = create_node_record(conn,
"master register", "master register",
options.node, options.node,
NO_UPSTREAM_NODE,
options.cluster_name, options.cluster_name,
options.node_name, options.node_name,
options.conninfo, options.conninfo,
@@ -753,6 +754,7 @@ do_standby_register(void)
node_record_created = create_node_record(master_conn, node_record_created = create_node_record(master_conn,
"standby register", "standby register",
options.node, options.node,
options.upstream_node,
options.cluster_name, options.cluster_name,
options.node_name, options.node_name,
options.conninfo, options.conninfo,
@@ -1555,6 +1557,7 @@ do_witness_create(void)
node_record_created = create_node_record(masterconn, node_record_created = create_node_record(masterconn,
"witness create", "witness create",
options.node, options.node,
NO_UPSTREAM_NODE,
options.cluster_name, options.cluster_name,
options.node_name, options.node_name,
options.conninfo, options.conninfo,
@@ -2229,6 +2232,7 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
node_record_created = create_node_record(witnessconn, node_record_created = create_node_record(witnessconn,
"copy_configuration", "copy_configuration",
atoi(PQgetvalue(res, i, 0)), atoi(PQgetvalue(res, i, 0)),
NO_UPSTREAM_NODE,
options.cluster_name, options.cluster_name,
PQgetvalue(res, i, 1), PQgetvalue(res, i, 1),
PQgetvalue(res, i, 2), PQgetvalue(res, i, 2),
@@ -2480,17 +2484,29 @@ do_check_upstream_config(void)
static bool 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 sqlquery[QUERY_STR_LEN];
char upstream_node_id[QUERY_STR_LEN];
PGresult *res; 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, sqlquery_snprintf(sqlquery,
"INSERT INTO %s.repl_nodes " "INSERT INTO %s.repl_nodes "
" (id, cluster, name, conninfo, priority, witness) " " (id, upstream_node_id, cluster, "
"VALUES (%d, '%s', '%s', '%s', %d, %s) ", " name, conninfo, priority, witness) "
"VALUES (%d, %s, '%s', '%s', '%s', %d, %s) ",
get_repmgr_schema_quoted(conn), get_repmgr_schema_quoted(conn),
node, node,
upstream_node_id,
cluster_name, cluster_name,
node_name, node_name,
conninfo, conninfo,

View File

@@ -38,7 +38,7 @@
#include "config.h" #include "config.h"
#define MAXFILENAME 1024 #define MAXFILENAME 1024
#define ERRBUFF_SIZE 512 #define ERRBUFF_SIZE 512
#define DEFAULT_CONFIG_FILE "./repmgr.conf" #define DEFAULT_CONFIG_FILE "./repmgr.conf"
#define DEFAULT_WAL_KEEP_SEGMENTS "5000" #define DEFAULT_WAL_KEEP_SEGMENTS "5000"
@@ -51,7 +51,7 @@
#define MANUAL_FAILOVER 0 #define MANUAL_FAILOVER 0
#define AUTOMATIC_FAILOVER 1 #define AUTOMATIC_FAILOVER 1
#define NO_UPSTREAM_NODE -1
/* Run time options type */ /* Run time options type */
typedef struct typedef struct