Store slot name in repl_nodes table

This commit is contained in:
Ian Barwick
2015-02-02 17:57:15 +09:00
parent b4b5e6cd30
commit 7a760c32ff
2 changed files with 29 additions and 19 deletions

View File

@@ -2083,11 +2083,12 @@ create_schema(PGconn *conn)
" id INTEGER PRIMARY KEY, "
" type TEXT NOT NULL CHECK (type IN('primary','standby','witness')), "
" upstream_node_id INTEGER NULL REFERENCES %s.repl_nodes (id), "
" cluster TEXT NOT NULL, "
" name TEXT NOT NULL, "
" conninfo TEXT NOT NULL, "
" priority INTEGER NOT NULL, "
" active BOOLEAN NOT NULL DEFAULT TRUE) ",
" cluster TEXT NOT NULL, "
" name TEXT NOT NULL, "
" conninfo TEXT NOT NULL, "
" slot_name TEXT NULL, "
" priority INTEGER NOT NULL, "
" active BOOLEAN NOT NULL DEFAULT TRUE )",
get_repmgr_schema_quoted(conn),
get_repmgr_schema_quoted(conn));
@@ -2530,7 +2531,8 @@ static bool
create_node_record(PGconn *conn, char *action, int node, char *type, int upstream_node, char *cluster_name, char *node_name, char *conninfo, int priority)
{
char sqlquery[QUERY_STR_LEN];
char upstream_node_id[QUERY_STR_LEN];
char upstream_node_id[MAXLEN];
char slot_name[MAXLEN];
PGresult *res;
if(upstream_node == NO_UPSTREAM_NODE)
@@ -2542,23 +2544,32 @@ create_node_record(PGconn *conn, char *action, int node, char *type, int upstrea
if(strcmp(type, "standby") == 0)
{
int primary_node_id = get_primary_node_id(conn, cluster_name);
sqlquery_snprintf(upstream_node_id, "%i", primary_node_id);
maxlen_snprintf(upstream_node_id, "%i", primary_node_id);
}
else
{
sqlquery_snprintf(upstream_node_id, "%s", "NULL");
maxlen_snprintf(upstream_node_id, "%s", "NULL");
}
}
else
{
sqlquery_snprintf(upstream_node_id, "%i", upstream_node);
maxlen_snprintf(upstream_node_id, "%i", upstream_node);
}
if(options.use_replication_slots && strcmp(type, "standby") == 0)
{
maxlen_snprintf(slot_name, "'%s'", repmgr_slot_name);
}
else
{
maxlen_snprintf(slot_name, "%s", "NULL");
}
sqlquery_snprintf(sqlquery,
"INSERT INTO %s.repl_nodes "
" (id, type, upstream_node_id, cluster, "
" name, conninfo, priority) "
"VALUES (%i, '%s', %s, '%s', '%s', '%s', %i) ",
" name, conninfo, slot_name, priority) "
"VALUES (%i, '%s', %s, '%s', '%s', '%s', %s, %i) ",
get_repmgr_schema_quoted(conn),
node,
type,
@@ -2566,6 +2577,7 @@ create_node_record(PGconn *conn, char *action, int node, char *type, int upstrea
cluster_name,
node_name,
conninfo,
slot_name,
priority);
if(action != NULL)

View File

@@ -54,6 +54,7 @@ typedef struct s_node_info
t_server_type type;
bool is_ready;
bool is_visible;
char slot_name[MAXLEN];
} t_node_info;
@@ -1361,14 +1362,10 @@ do_primary_failover(void)
if(local_options.use_replication_slots)
{
// ZZZ store slot name in `repl_nodes`
char repmgr_slot_name[MAXLEN];
maxlen_snprintf(repmgr_slot_name, "repmgr_slot_%i", local_options.node);
if(create_replication_slot(new_primary_conn, repmgr_slot_name) == false)
if(create_replication_slot(new_primary_conn, local_options.slot_name) == false)
{
log_err(_("Unable to create slot '%s' on the primary node: %s\n"),
repmgr_slot_name,
local_options.slot_name,
PQerrorMessage(new_primary_conn));
PQfinish(new_primary_conn);
terminate(ERR_DB_QUERY);
@@ -2038,7 +2035,7 @@ check_and_create_pid_file(const char *pid_file)
t_node_info
get_node_info(PGconn *conn,char *cluster, int node_id)
get_node_info(PGconn *conn, char *cluster, int node_id)
{
char sqlquery[QUERY_STR_LEN];
PGresult *res;
@@ -2046,7 +2043,7 @@ get_node_info(PGconn *conn,char *cluster, int node_id)
t_node_info node_info = {-1, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false};
sprintf(sqlquery,
"SELECT id, upstream_node_id, conninfo, type "
"SELECT id, upstream_node_id, conninfo, type, slot_name "
" FROM %s.repl_nodes "
" WHERE cluster = '%s' "
" AND id = %i",
@@ -2068,6 +2065,7 @@ get_node_info(PGconn *conn,char *cluster, int node_id)
node_info.upstream_node_id = atoi(PQgetvalue(res, 0, 1));
strncpy(node_info.conninfo_str, PQgetvalue(res, 0, 2), MAXLEN);
node_info.type = parse_node_type(PQgetvalue(res, 0, 3));
strncpy(node_info.slot_name, PQgetvalue(res, 0, 4), MAXLEN);
PQclear(res);