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

Commit f946069

Browse files
committed
Use TransactionXmin instead of RecentGlobalXmin in heap_abort_speculative().
There's a very low risk that RecentGlobalXmin could be far enough in the past to be older than relfrozenxid, or even wrapped around. Luckily the consequences of that having happened wouldn't be too bad - the page wouldn't be pruned for a while. Avoid that risk by using TransactionXmin instead. As that's announced via MyPgXact->xmin, it is protected against wrapping around (see code comments for details around relfrozenxid). Author: Andres Freund Discussion: https://postgr.es/m/20200328213023.s4eyijhdosuc4vcj@alap3.anarazel.de Backpatch: 9.5-
1 parent 549a3e2 commit f946069

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/backend/access/heap/heapam.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -5581,6 +5581,7 @@ heap_abort_speculative(Relation relation, ItemPointer tid)
55815581
Page page;
55825582
BlockNumber block;
55835583
Buffer buffer;
5584+
TransactionId prune_xid;
55845585

55855586
Assert(ItemPointerIsValid(tid));
55865587

@@ -5623,13 +5624,21 @@ heap_abort_speculative(Relation relation, ItemPointer tid)
56235624
START_CRIT_SECTION();
56245625

56255626
/*
5626-
* The tuple will become DEAD immediately. Flag that this page
5627-
* immediately is a candidate for pruning by setting xmin to
5628-
* RecentGlobalXmin. That's not pretty, but it doesn't seem worth
5629-
* inventing a nicer API for this.
5627+
* The tuple will become DEAD immediately. Flag that this page is a
5628+
* candidate for pruning by setting xmin to TransactionXmin. While not
5629+
* immediately prunable, it is the oldest xid we can cheaply determine
5630+
* that's safe against wraparound / being older than the table's
5631+
* relfrozenxid. To defend against the unlikely case of a new relation
5632+
* having a newer relfrozenxid than our TransactionXmin, use relfrozenxid
5633+
* if so (vacuum can't subsequently move relfrozenxid to beyond
5634+
* TransactionXmin, so there's no race here).
56305635
*/
5631-
Assert(TransactionIdIsValid(RecentGlobalXmin));
5632-
PageSetPrunable(page, RecentGlobalXmin);
5636+
Assert(TransactionIdIsValid(TransactionXmin));
5637+
if (TransactionIdPrecedes(TransactionXmin, relation->rd_rel->relfrozenxid))
5638+
prune_xid = relation->rd_rel->relfrozenxid;
5639+
else
5640+
prune_xid = TransactionXmin;
5641+
PageSetPrunable(page, prune_xid);
56335642

56345643
/* store transaction information of xact deleting the tuple */
56355644
tp.t_data->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED);

0 commit comments

Comments
 (0)