Skip to content

Commit fcb88ae

Browse files
committed
Add VacuumHorizonHook instead of just hint bits horizon
1 parent 2d8d8c5 commit fcb88ae

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/backend/access/heap/heapam_visibility.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
#include "utils/builtins.h"
7979
#include "utils/snapmgr.h"
8080

81-
static TransactionId hint_bit_horizon = InvalidTransactionId;
81+
VacuumHorizonHookType VacuumHorizonHook = NULL;
8282

8383

8484
/*
@@ -129,10 +129,14 @@ SetHintBits(HeapTupleHeader tuple, Buffer buffer,
129129
}
130130
}
131131

132-
if (TransactionIdIsValid(hint_bit_horizon) &&
133-
TransactionIdIsValid(xid) &&
134-
TransactionIdFollows(xid, hint_bit_horizon))
135-
return;
132+
if (TransactionIdIsValid(xid) && VacuumHorizonHook)
133+
{
134+
TransactionId horizon = VacuumHorizonHook();
135+
136+
if (TransactionIdIsValid(horizon) &&
137+
TransactionIdFollows(xid, horizon))
138+
return;
139+
}
136140

137141
tuple->t_infomask |= infomask;
138142
MarkBufferDirtyHint(buffer, true);
@@ -1793,9 +1797,3 @@ HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot, Buffer buffer)
17931797

17941798
return false; /* keep compiler quiet */
17951799
}
1796-
1797-
void
1798-
SetHintBitsHorizon(TransactionId new_horizon)
1799-
{
1800-
hint_bit_horizon = new_horizon;
1801-
}

src/backend/commands/vacuum.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,14 @@ vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
11061106
* any time, and that each vacuum is always an independent transaction.
11071107
*/
11081108
cutoffs->OldestXmin = GetOldestNonRemovableTransactionId(rel);
1109+
if (VacuumHorizonHook)
1110+
{
1111+
TransactionId horizon = VacuumHorizonHook();
1112+
1113+
if (TransactionIdIsValid(horizon) &&
1114+
TransactionIdFollows(cutoffs->OldestXmin, horizon))
1115+
cutoffs->OldestXmin = horizon;
1116+
}
11091117

11101118
Assert(TransactionIdIsNormal(cutoffs->OldestXmin));
11111119

@@ -1593,6 +1601,14 @@ vac_update_datfrozenxid(void)
15931601
* cannot produce a wrong minimum by starting with this.
15941602
*/
15951603
newFrozenXid = GetOldestNonRemovableTransactionId(NULL);
1604+
if (VacuumHorizonHook)
1605+
{
1606+
TransactionId horizon = VacuumHorizonHook();
1607+
1608+
if (TransactionIdIsValid(horizon) &&
1609+
TransactionIdFollows(newFrozenXid, horizon))
1610+
newFrozenXid = horizon;
1611+
}
15961612

15971613
/*
15981614
* Similarly, initialize the MultiXact "min" with the value that would be

src/include/access/heapam.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ extern void heap_vacuum_rel(Relation rel,
398398
struct VacuumParams *params, BufferAccessStrategy bstrategy);
399399

400400
/* in heap/heapam_visibility.c */
401+
typedef TransactionId (*VacuumHorizonHookType) (void);
402+
403+
extern VacuumHorizonHookType VacuumHorizonHook;
404+
401405
extern bool HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot,
402406
Buffer buffer);
403407
extern TM_Result HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
@@ -412,8 +416,6 @@ extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
412416
extern bool HeapTupleIsSurelyDead(HeapTuple htup,
413417
struct GlobalVisState *vistest);
414418

415-
extern void SetHintBitsHorizon(TransactionId new_horizon);
416-
417419
/*
418420
* To avoid leaking too much knowledge about reorderbuffer implementation
419421
* details this is implemented in reorderbuffer.c not heapam_visibility.c

0 commit comments

Comments
 (0)