mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16: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;
|
PQExpBufferData query;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
int vote;
|
int lsn_diff;
|
||||||
|
|
||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
appendPQExpBuffer(&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_id,
|
||||||
this_node_priority,
|
|
||||||
(uint32) (last_wal_receive_lsn >> 32),
|
(uint32) (last_wal_receive_lsn >> 32),
|
||||||
(uint32) last_wal_receive_lsn);
|
(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);
|
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);
|
PQclear(res);
|
||||||
return vote;
|
return lsn_diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,11 +34,15 @@ CREATE VIEW show_nodes AS
|
|||||||
LEFT JOIN nodes un
|
LEFT JOIN nodes un
|
||||||
ON un.node_id = n.upstream_node_id;
|
ON un.node_id = n.upstream_node_id;
|
||||||
|
|
||||||
CREATE FUNCTION request_vote(int) RETURNS boolean
|
/* repmgrd functions */
|
||||||
AS '$libdir/repmgr', 'request_vote'
|
|
||||||
LANGUAGE C STRICT;
|
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()
|
||||||
AS '$libdir/repmgr', 'get_voting_status'
|
RETURNS INT
|
||||||
LANGUAGE C STRICT;
|
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/shmem.h"
|
||||||
#include "storage/spin.h"
|
#include "storage/spin.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "utils/pg_lsn.h"
|
||||||
#include "utils/timestamp.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"
|
#include "voting.h"
|
||||||
|
|
||||||
#define MAXFNAMELEN 64
|
#define MAXFNAMELEN 64
|
||||||
@@ -137,11 +145,42 @@ repmgr_shmem_startup(void)
|
|||||||
Datum
|
Datum
|
||||||
request_vote(PG_FUNCTION_ARGS)
|
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
|
// check result
|
||||||
(void) get_node_record(local_conn, local_node_info.upstream_node_id, &upstream_node_info);
|
(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)
|
// handle failure - do we want to loop here?
|
||||||
upstream_conn = establish_db_connection(config_file_options.conninfo, false);
|
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||||
|
|
||||||
// fix for cascaded standbys
|
// fix for cascaded standbys
|
||||||
primary_conn = upstream_conn;
|
primary_conn = upstream_conn;
|
||||||
@@ -635,8 +635,13 @@ do_election(void)
|
|||||||
local_node_info.node_id,
|
local_node_info.node_id,
|
||||||
local_node_info.priority,
|
local_node_info.priority,
|
||||||
last_wal_receive_lsn);
|
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;
|
return VS_VOTE_WON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user