mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +00:00
Merge pull request #23 from wamonite/fix_witness
fix: witness creation and monitoring. On copy_configuration() we are using the res variable when is still used on the loop.
This commit is contained in:
33
repmgr.c
33
repmgr.c
@@ -2374,13 +2374,14 @@ static bool
|
|||||||
copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
||||||
{
|
{
|
||||||
char sqlquery[MAXLEN];
|
char sqlquery[MAXLEN];
|
||||||
PGresult *res;
|
PGresult *res1;
|
||||||
|
PGresult *res2;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", repmgr_schema);
|
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", repmgr_schema);
|
||||||
log_debug("copy_configuration: %s\n", sqlquery);
|
log_debug("copy_configuration: %s\n", sqlquery);
|
||||||
res = PQexec(witnessconn, sqlquery);
|
res1 = PQexec(witnessconn, sqlquery);
|
||||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (!res1 || PQresultStatus(res1) != PGRES_COMMAND_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot clean node details in the witness, %s\n",
|
fprintf(stderr, "Cannot clean node details in the witness, %s\n",
|
||||||
PQerrorMessage(witnessconn));
|
PQerrorMessage(witnessconn));
|
||||||
@@ -2389,33 +2390,35 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
|||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "SELECT id, name, conninfo, priority, witness FROM %s.repl_nodes",
|
sqlquery_snprintf(sqlquery, "SELECT id, name, conninfo, priority, witness FROM %s.repl_nodes",
|
||||||
repmgr_schema);
|
repmgr_schema);
|
||||||
res = PQexec(masterconn, sqlquery);
|
res1 = PQexec(masterconn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res1) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get configuration from master: %s\n",
|
fprintf(stderr, "Can't get configuration from master: %s\n",
|
||||||
PQerrorMessage(masterconn));
|
PQerrorMessage(masterconn));
|
||||||
PQclear(res);
|
PQclear(res1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res1); i++)
|
||||||
{
|
{
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
|
||||||
"VALUES (%d, '%s', '%s', '%s', %d, '%s')",
|
"VALUES (%d, '%s', '%s', '%s', %d, '%s')",
|
||||||
repmgr_schema, atoi(PQgetvalue(res, i, 0)),
|
repmgr_schema, atoi(PQgetvalue(res1, i, 0)),
|
||||||
options.cluster_name, PQgetvalue(res, i, 1),
|
options.cluster_name, PQgetvalue(res1, i, 1),
|
||||||
PQgetvalue(res, i, 2),
|
PQgetvalue(res1, i, 2),
|
||||||
atoi(PQgetvalue(res, i, 3)),
|
atoi(PQgetvalue(res1, i, 3)),
|
||||||
PQgetvalue(res, i, 4));
|
PQgetvalue(res1, i, 4));
|
||||||
|
|
||||||
res = PQexec(witnessconn, sqlquery);
|
res2 = PQexec(witnessconn, sqlquery);
|
||||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (!res2 || PQresultStatus(res2) != PGRES_COMMAND_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot copy configuration to witness, %s\n",
|
fprintf(stderr, "Cannot copy configuration to witness, %s\n",
|
||||||
PQerrorMessage(witnessconn));
|
PQerrorMessage(witnessconn));
|
||||||
PQclear(res);
|
PQclear(res2);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
PQclear(res2);
|
||||||
}
|
}
|
||||||
|
PQclear(res1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -551,7 +551,7 @@ witness_monitor(void)
|
|||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"INSERT INTO %s.repl_monitor "
|
"INSERT INTO %s.repl_monitor "
|
||||||
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
||||||
" pg_current_xlog_location(), null, "
|
" null, pg_current_xlog_location(), null, "
|
||||||
" 0, 0)",
|
" 0, 0)",
|
||||||
repmgr_schema, primary_options.node, local_options.node,
|
repmgr_schema, primary_options.node, local_options.node,
|
||||||
monitor_witness_timestamp);
|
monitor_witness_timestamp);
|
||||||
|
|||||||
Reference in New Issue
Block a user