@@ -356,8 +356,7 @@ gistRedoPageDelete(XLogReaderState *record)
356
356
{
357
357
Page page = (Page ) BufferGetPage (leafBuffer );
358
358
359
- GistPageSetDeleteXid (page , xldata -> deleteXid );
360
- GistPageSetDeleted (page );
359
+ GistPageSetDeleted (page , xldata -> deleteXid );
361
360
362
361
PageSetLSN (page , lsn );
363
362
MarkBufferDirty (leafBuffer );
@@ -396,8 +395,27 @@ gistRedoPageReuse(XLogReaderState *record)
396
395
*/
397
396
if (InHotStandby )
398
397
{
399
- ResolveRecoveryConflictWithSnapshot (xlrec -> latestRemovedXid ,
400
- xlrec -> node );
398
+ FullTransactionId latestRemovedFullXid = xlrec -> latestRemovedFullXid ;
399
+ FullTransactionId nextFullXid = ReadNextFullTransactionId ();
400
+ uint64 diff ;
401
+
402
+ /*
403
+ * ResolveRecoveryConflictWithSnapshot operates on 32-bit
404
+ * TransactionIds, so truncate the logged FullTransactionId. If the
405
+ * logged value is very old, so that XID wrap-around already happened
406
+ * on it, there can't be any snapshots that still see it.
407
+ */
408
+ nextFullXid = ReadNextFullTransactionId ();
409
+ diff = U64FromFullTransactionId (nextFullXid ) -
410
+ U64FromFullTransactionId (latestRemovedFullXid );
411
+ if (diff < MaxTransactionId / 2 )
412
+ {
413
+ TransactionId latestRemovedXid ;
414
+
415
+ latestRemovedXid = XidFromFullTransactionId (latestRemovedFullXid );
416
+ ResolveRecoveryConflictWithSnapshot (latestRemovedXid ,
417
+ xlrec -> node );
418
+ }
401
419
}
402
420
}
403
421
@@ -554,7 +572,7 @@ gistXLogSplit(bool page_is_leaf,
554
572
* downlink from the parent page.
555
573
*/
556
574
XLogRecPtr
557
- gistXLogPageDelete (Buffer buffer , TransactionId xid ,
575
+ gistXLogPageDelete (Buffer buffer , FullTransactionId xid ,
558
576
Buffer parentBuffer , OffsetNumber downlinkOffset )
559
577
{
560
578
gistxlogPageDelete xlrec ;
@@ -578,7 +596,7 @@ gistXLogPageDelete(Buffer buffer, TransactionId xid,
578
596
* Write XLOG record about reuse of a deleted page.
579
597
*/
580
598
void
581
- gistXLogPageReuse (Relation rel , BlockNumber blkno , TransactionId latestRemovedXid )
599
+ gistXLogPageReuse (Relation rel , BlockNumber blkno , FullTransactionId latestRemovedXid )
582
600
{
583
601
gistxlogPageReuse xlrec_reuse ;
584
602
@@ -591,7 +609,7 @@ gistXLogPageReuse(Relation rel, BlockNumber blkno, TransactionId latestRemovedXi
591
609
/* XLOG stuff */
592
610
xlrec_reuse .node = rel -> rd_node ;
593
611
xlrec_reuse .block = blkno ;
594
- xlrec_reuse .latestRemovedXid = latestRemovedXid ;
612
+ xlrec_reuse .latestRemovedFullXid = latestRemovedXid ;
595
613
596
614
XLogBeginInsert ();
597
615
XLogRegisterData ((char * ) & xlrec_reuse , SizeOfGistxlogPageReuse );
0 commit comments