Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0188bb8

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" inpg_replication slot. Prior to this change, the state value was reportedas 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.comDiscussion:https://postgr.es/m/20200407.120905.1507671100168805403.horikyota.ntt@gmail.com
1 parent368d7f3 commit0188bb8

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
boolnulls[PG_GET_REPLICATION_SLOTS_COLS];
284284
WALAvailabilitywalstate;
285285
XLogSegNolast_removed_seg;
286+
XLogRecPtrtargetLSN;
286287
inti;
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
externvoidInitXLOGAccess(void);
327327
externvoidCreateCheckPoint(intflags);
328328
externboolCreateRestartPoint(intflags);
329-
externWALAvailabilityGetWALAvailability(XLogRecPtrrestart_lsn);
329+
externWALAvailabilityGetWALAvailability(XLogRecPtrtargetLSN);
330330
externXLogRecPtrCalculateMaxmumSafeLSN(void);
331331
externvoidXLogPutNextOid(OidnextOid);
332332
externXLogRecPtrXLogRestorePoint(constchar*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
XLogRecPtrrestart_lsn;
8181

82+
/* restart_lsn is copied here when the slot is invalidated */
83+
XLogRecPtrinvalidated_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)

[8]ページ先頭

©2009-2025 Movatter.jp