Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0188bb8

Browse files
committed
Save slot's restart_lsn when invalidated due to size
We put it aside as invalidated_at, which let us show "lost" in pg_replication slot. Prior to this change, the state value was reported as NULL. Backpatch to 13. Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/20200617.101707.1735599255100002667.horikyota.ntt@gmail.com Discussion: https://postgr.es/m/20200407.120905.1507671100168805403.horikyota.ntt@gmail.com
1 parent 368d7f3 commit 0188bb8

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

src/backend/replication/slot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ InvalidateObsoleteReplicationSlots(XLogSegNo oldestSegno)
12261226
(uint32) restart_lsn)));
12271227

12281228
SpinLockAcquire(&s->mutex);
1229+
s->data.invalidated_at = s->data.restart_lsn;
12291230
s->data.restart_lsn = InvalidXLogRecPtr;
12301231
SpinLockRelease(&s->mutex);
12311232
ReplicationSlotRelease();

src/backend/replication/slotfuncs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
283283
bool nulls[PG_GET_REPLICATION_SLOTS_COLS];
284284
WALAvailability walstate;
285285
XLogSegNo last_removed_seg;
286+
XLogRecPtr targetLSN;
286287
int i;
287288

288289
if (!slot->in_use)
@@ -342,7 +343,15 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
342343
else
343344
nulls[i++] = true;
344345

345-
walstate = GetWALAvailability(slot_contents.data.restart_lsn);
346+
/*
347+
* Report availability from invalidated_at when the slot has been
348+
* invalidated; otherwise slots would appear as invalid without any
349+
* more clues as to what happened.
350+
*/
351+
targetLSN = XLogRecPtrIsInvalid(slot_contents.data.restart_lsn) ?
352+
slot_contents.data.invalidated_at :
353+
slot_contents.data.restart_lsn;
354+
walstate = GetWALAvailability(targetLSN);
346355

347356
switch (walstate)
348357
{

src/include/access/xlog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ extern void ShutdownXLOG(int code, Datum arg);
326326
extern void InitXLOGAccess(void);
327327
extern void CreateCheckPoint(int flags);
328328
extern bool CreateRestartPoint(int flags);
329-
extern WALAvailability GetWALAvailability(XLogRecPtr restart_lsn);
329+
extern WALAvailability GetWALAvailability(XLogRecPtr targetLSN);
330330
extern XLogRecPtr CalculateMaxmumSafeLSN(void);
331331
extern void XLogPutNextOid(Oid nextOid);
332332
extern XLogRecPtr XLogRestorePoint(const char *rpName);

src/include/replication/slot.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ typedef struct ReplicationSlotPersistentData
7979
/* oldest LSN that might be required by this replication slot */
8080
XLogRecPtr restart_lsn;
8181

82+
/* restart_lsn is copied here when the slot is invalidated */
83+
XLogRecPtr invalidated_at;
84+
8285
/*
8386
* Oldest LSN that the client has acked receipt for. This is used as the
8487
* start_lsn point in case the client doesn't specify one, and also as a

src/test/recovery/t/019_replslot_limit.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
$result = $node_master->safe_psql('postgres',
187187
"SELECT slot_name, active, restart_lsn IS NULL, wal_status, min_safe_lsn FROM pg_replication_slots WHERE slot_name = 'rep1'"
188188
);
189-
is($result, "rep1|f|t||", 'check that the slot became inactive');
189+
is($result, "rep1|f|t|lost|", 'check that the slot became inactive');
190190

191191
# The standby no longer can connect to the master
192192
$logstart = get_log_size($node_standby);

0 commit comments

Comments
 (0)