fix: witness creation and monitoring

While reading node entries from master use a separate PGresult when inserting into witness.
Witness monitoring supplies a null value for 'last_apply_time'.
This commit is contained in:
Warren Moore
2014-03-24 14:19:29 +00:00
parent 7c89a4d762
commit d93d42fadb
2 changed files with 7 additions and 5 deletions

View File

@@ -2368,7 +2368,7 @@ static bool
copy_configuration(PGconn *masterconn, PGconn *witnessconn) copy_configuration(PGconn *masterconn, PGconn *witnessconn)
{ {
char sqlquery[MAXLEN]; char sqlquery[MAXLEN];
PGresult *res; PGresult *res, *res_witness;
int i; int i;
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", repmgr_schema); sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", repmgr_schema);
@@ -2401,15 +2401,17 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
atoi(PQgetvalue(res, i, 3)), atoi(PQgetvalue(res, i, 3)),
PQgetvalue(res, i, 4)); PQgetvalue(res, i, 4));
res = PQexec(witnessconn, sqlquery); res_witness = PQexec(witnessconn, sqlquery);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) if (!res_witness || PQresultStatus(res_witness) != 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(res_witness);
return false; return false;
} }
PQclear(res_witness);
} }
PQclear(res);
return true; return true;
} }

View File

@@ -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);