mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
interim commit
This commit is contained in:
11
dbutils.c
11
dbutils.c
@@ -2292,14 +2292,13 @@ int request_vote(PGconn *conn, int this_node_id, int this_node_priority, XLogRec
|
||||
{
|
||||
PQExpBufferData query;
|
||||
PGresult *res;
|
||||
int vote;
|
||||
int lsn_diff;
|
||||
|
||||
initPQExpBuffer(&query);
|
||||
|
||||
appendPQExpBuffer(&query,
|
||||
"SELECT repmgr.request_vote(%i, %i, '%X/%X'::pg_lsn)",
|
||||
"SELECT repmgr.request_vote(%i, '%X/%X'::pg_lsn)",
|
||||
this_node_id,
|
||||
this_node_priority,
|
||||
(uint32) (last_wal_receive_lsn >> 32),
|
||||
(uint32) last_wal_receive_lsn);
|
||||
|
||||
@@ -2307,10 +2306,12 @@ int request_vote(PGconn *conn, int this_node_id, int this_node_priority, XLogRec
|
||||
|
||||
termPQExpBuffer(&query);
|
||||
|
||||
vote = (strcmp(PQgetvalue(res, 0, 0), "t") == 0) ? 1 : 0;
|
||||
lsn_diff = atoi(PQgetvalue(res, 0, 0));
|
||||
|
||||
log_debug("XXX lsn_diff %i", lsn_diff);
|
||||
|
||||
PQclear(res);
|
||||
return vote;
|
||||
return lsn_diff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,11 +34,15 @@ CREATE VIEW show_nodes AS
|
||||
LEFT JOIN nodes un
|
||||
ON un.node_id = n.upstream_node_id;
|
||||
|
||||
CREATE FUNCTION request_vote(int) RETURNS boolean
|
||||
/* repmgrd functions */
|
||||
|
||||
CREATE FUNCTION request_vote(INT, pg_lsn)
|
||||
RETURNS INT
|
||||
AS '$libdir/repmgr', 'request_vote'
|
||||
LANGUAGE C STRICT;
|
||||
|
||||
|
||||
CREATE FUNCTION get_voting_status() RETURNS int
|
||||
CREATE FUNCTION get_voting_status()
|
||||
RETURNS INT
|
||||
AS '$libdir/repmgr', 'get_voting_status'
|
||||
LANGUAGE C STRICT;
|
||||
|
||||
45
repmgr.c
45
repmgr.c
@@ -18,8 +18,16 @@
|
||||
#include "storage/shmem.h"
|
||||
#include "storage/spin.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/pg_lsn.h"
|
||||
#include "utils/timestamp.h"
|
||||
|
||||
#include "executor/spi.h"
|
||||
#include "lib/stringinfo.h"
|
||||
#include "access/xact.h"
|
||||
#include "utils/snapmgr.h"
|
||||
#include "pgstat.h"
|
||||
|
||||
|
||||
#include "voting.h"
|
||||
|
||||
#define MAXFNAMELEN 64
|
||||
@@ -137,11 +145,42 @@ repmgr_shmem_startup(void)
|
||||
Datum
|
||||
request_vote(PG_FUNCTION_ARGS)
|
||||
{
|
||||
uint32 node_id = PG_GETARG_INT32(0);
|
||||
/* node_id used for logging purposes */
|
||||
int requesting_node_id = PG_GETARG_INT32(0);
|
||||
XLogRecPtr requesting_node_last_lsn = PG_GETARG_LSN(1);
|
||||
StringInfoData query;
|
||||
|
||||
elog(INFO, "id is %i", node_id);
|
||||
int ret;
|
||||
bool isnull;
|
||||
|
||||
PG_RETURN_BOOL(true);
|
||||
int lsn_diff;
|
||||
|
||||
elog(INFO, "id is %i, lsn: %X/%X",
|
||||
requesting_node_id,
|
||||
(uint32) (requesting_node_last_lsn >> 32),
|
||||
(uint32) requesting_node_last_lsn);
|
||||
|
||||
SPI_connect();
|
||||
|
||||
initStringInfo(&query);
|
||||
appendStringInfo(
|
||||
&query,
|
||||
"SELECT '%X/%X'::pg_lsn - pg_catalog.pg_last_wal_receive_lsn()::pg_lsn",
|
||||
(uint32) (requesting_node_last_lsn >> 32),
|
||||
(uint32) requesting_node_last_lsn);
|
||||
|
||||
ret = SPI_execute(query.data, false, 0);
|
||||
|
||||
lsn_diff = DatumGetInt32(SPI_getbinval(SPI_tuptable->vals[0],
|
||||
SPI_tuptable->tupdesc,
|
||||
1, &isnull));
|
||||
|
||||
elog(INFO, "XXX diff is %i",
|
||||
lsn_diff);
|
||||
|
||||
SPI_finish();
|
||||
|
||||
PG_RETURN_INT32(lsn_diff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -483,8 +483,8 @@ monitor_streaming_standby(void)
|
||||
// check result
|
||||
(void) get_node_record(local_conn, local_node_info.upstream_node_id, &upstream_node_info);
|
||||
|
||||
// check result, fail if not up (must start on running node)
|
||||
upstream_conn = establish_db_connection(config_file_options.conninfo, false);
|
||||
// handle failure - do we want to loop here?
|
||||
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||
|
||||
// fix for cascaded standbys
|
||||
primary_conn = upstream_conn;
|
||||
@@ -635,8 +635,13 @@ do_election(void)
|
||||
local_node_info.node_id,
|
||||
local_node_info.priority,
|
||||
last_wal_receive_lsn);
|
||||
|
||||
PQfinish(cell->node_info->conn);
|
||||
cell->node_info->conn = NULL;
|
||||
}
|
||||
|
||||
log_notice(_("%i of of %i votes"), votes_for_me, visible_nodes);
|
||||
|
||||
return VS_VOTE_WON;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user