mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
repmgr: initialise "voting_term" in "repmgr primary register"
This previously happened in the extension SQL code, which could potentially cause replay problems if installing on a BDR cluster. As this table is only required for streaming replication failover, move the initialisation to "repmgr primary register". Addresses GitHub #344 .
This commit is contained in:
36
dbutils.c
36
dbutils.c
@@ -3735,7 +3735,7 @@ int
|
||||
get_current_term(PGconn *conn)
|
||||
{
|
||||
PGresult *res = NULL;
|
||||
int term = -1;
|
||||
int term = VOTING_TERM_NOT_SET;
|
||||
|
||||
res = PQexec(conn, "SELECT term FROM repmgr.voting_term");
|
||||
|
||||
@@ -3747,13 +3747,43 @@ get_current_term(PGconn *conn)
|
||||
return -1;
|
||||
}
|
||||
|
||||
term = atoi(PQgetvalue(res, 0, 0));
|
||||
if (PQntuples(res) > 0)
|
||||
{
|
||||
term = atoi(PQgetvalue(res, 0, 0));
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
return term;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
initialize_voting_term(PGconn *conn)
|
||||
{
|
||||
PGresult *res = NULL;
|
||||
|
||||
int current_term = get_current_term(conn);
|
||||
|
||||
if (current_term == VOTING_TERM_NOT_SET)
|
||||
{
|
||||
res = PQexec(conn, "INSERT INTO repmgr.voting_term (term) VALUES (1)");
|
||||
}
|
||||
else
|
||||
{
|
||||
res = PQexec(conn, "UPDATE repmgr.voting_term SET term = 1");
|
||||
}
|
||||
|
||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
log_error(_("unable to initialize repmgr.voting_term:\n %s"),
|
||||
PQerrorMessage(conn));
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
increment_current_term(PGconn *conn)
|
||||
{
|
||||
@@ -3765,8 +3795,6 @@ increment_current_term(PGconn *conn)
|
||||
{
|
||||
log_error(_("unable to increment repmgr.voting_term:\n %s"),
|
||||
PQerrorMessage(conn));
|
||||
PQclear(res);
|
||||
return;
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
|
||||
Reference in New Issue
Block a user