mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
repmgrd: return predictable default values for get_primary_last_seen()
Return 0 if the node is not in recovery. In which case it's probably rather pointless calling this function anyway. Return -1 if the "last_seen" field has never been set (i.e. repmgrd hasn't started yet).
This commit is contained in:
18
repmgr.c
18
repmgr.c
@@ -225,8 +225,8 @@ repmgr_shmem_startup(void)
|
||||
memset(shared_state->repmgrd_pidfile, 0, MAXPGPATH);
|
||||
shared_state->repmgrd_paused = false;
|
||||
shared_state->current_electoral_term = 0;
|
||||
/* we should probably set this to an earlier value */
|
||||
shared_state->primary_last_seen = GetCurrentTimestamp();
|
||||
/* arbitrary "magic" date to indicate this field hasn't been updated */
|
||||
shared_state->primary_last_seen = POSTGRES_EPOCH_JDATE;
|
||||
shared_state->voting_status = VS_NO_VOTE;
|
||||
shared_state->candidate_node_id = UNKNOWN_NODE_ID;
|
||||
shared_state->follow_new_primary = false;
|
||||
@@ -391,12 +391,26 @@ get_primary_last_seen(PG_FUNCTION_ARGS)
|
||||
if (!shared_state)
|
||||
PG_RETURN_INT32(-1);
|
||||
|
||||
/* A primary is always visible */
|
||||
if (!RecoveryInProgress())
|
||||
PG_RETURN_INT32(0);
|
||||
|
||||
LWLockAcquire(shared_state->lock, LW_SHARED);
|
||||
|
||||
last_seen = shared_state->primary_last_seen;
|
||||
|
||||
LWLockRelease(shared_state->lock);
|
||||
|
||||
/*
|
||||
* "last_seen" is initialised with the PostgreSQL epoch as a
|
||||
* "magic" value to indicate the field hasn't ever been updated
|
||||
* by repmgrd. We return -1 instead, rather than imply that the
|
||||
* primary was last seen at the turn of the century.
|
||||
*/
|
||||
if (last_seen == POSTGRES_EPOCH_JDATE)
|
||||
PG_RETURN_INT32(-1);
|
||||
|
||||
|
||||
TimestampDifference(last_seen, GetCurrentTimestamp(),
|
||||
&secs, µsecs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user