have new primary communicate to standbys

This commit is contained in:
Ian Barwick
2017-06-30 21:45:25 +09:00
parent 1857e23fef
commit debe5a18c5
5 changed files with 178 additions and 9 deletions

View File

@@ -2429,6 +2429,60 @@ announce_candidature(PGconn *conn, t_node_info *this_node, t_node_info *other_no
return retval;
}
void
notify_follow_primary(PGconn *conn, int primary_node_id)
{
PQExpBufferData query;
PGresult *res;
initPQExpBuffer(&query);
appendPQExpBuffer(&query,
"SELECT repmgr.notify_follow_primary(%i)",
primary_node_id);
// XXX handle failure
res = PQexec(conn, query.data);
termPQExpBuffer(&query);
PQclear(res);
return;
}
bool
get_new_primary(PGconn *conn, int *primary_node_id)
{
PQExpBufferData query;
PGresult *res;
int new_primary_node_id;
initPQExpBuffer(&query);
appendPQExpBuffer(&query,
"SELECT repmgr.get_new_primary()");
res = PQexec(conn, query.data);
termPQExpBuffer(&query);
// XXX handle error
new_primary_node_id = atoi(PQgetvalue(res, 0, 0));
if (new_primary_node_id == UNKNOWN_NODE_ID)
{
PQclear(res);
return false;
}
PQclear(res);
*primary_node_id = new_primary_node_id;
return true;
}
/* ============================ */
/* replication status functions */
/* ============================ */