Skip to content

Commit 38e2652

Browse files
committed
Add VacuumHorizonHook instead of just hint bits horizon
1 parent c322b24 commit 38e2652

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
@@ -80,7 +80,7 @@
8080
#include "utils/combocid.h"
8181
#include "utils/snapmgr.h"
8282

83-
static TransactionId hint_bit_horizon = InvalidTransactionId;
83+
VacuumHorizonHookType VacuumHorizonHook = NULL;
8484

8585
/*
8686
* SetHintBits()
@@ -130,10 +130,14 @@ SetHintBits(HeapTupleHeader tuple, Buffer buffer,
130130
}
131131
}
132132

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

138142
tuple->t_infomask |= infomask;
139143
MarkBufferDirtyHint(buffer, true);
@@ -1794,9 +1798,3 @@ HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot, Buffer buffer)
17941798

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

src/backend/commands/vacuum.c

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

11131121
if (OldSnapshotThresholdActive())
11141122
{
@@ -1615,6 +1623,14 @@ vac_update_datfrozenxid(void)
16151623
* cannot produce a wrong minimum by starting with this.
16161624
*/
16171625
newFrozenXid = GetOldestNonRemovableTransactionId(NULL);
1626+
if (VacuumHorizonHook)
1627+
{
1628+
TransactionId horizon = VacuumHorizonHook();
1629+
1630+
if (TransactionIdIsValid(horizon) &&
1631+
TransactionIdFollows(newFrozenXid, horizon))
1632+
newFrozenXid = horizon;
1633+
}
16181634

16191635
/*
16201636
* 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
@@ -306,6 +306,10 @@ extern void heap_vacuum_rel(Relation rel,
306306
struct VacuumParams *params, BufferAccessStrategy bstrategy);
307307

308308
/* in heap/heapam_visibility.c */
309+
typedef TransactionId (*VacuumHorizonHookType) (void);
310+
311+
extern VacuumHorizonHookType VacuumHorizonHook;
312+
309313
extern bool HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot,
310314
Buffer buffer);
311315
extern TM_Result HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
@@ -320,8 +324,6 @@ extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
320324
extern bool HeapTupleIsSurelyDead(HeapTuple htup,
321325
struct GlobalVisState *vistest);
322326

323-
extern void SetHintBitsHorizon(TransactionId new_horizon);
324-
325327
/*
326328
* To avoid leaking too much knowledge about reorderbuffer implementation
327329
* details this is implemented in reorderbuffer.c not heapam_visibility.c

0 commit comments

Comments
 (0)