Skip to content

Commit 823dbae

Browse files
akorotkovpashkinelfe
authored andcommitted
Add VacuumHorizonHook instead of just hint bits horizon
1 parent 1d3ad7c commit 823dbae

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
@@ -1119,6 +1119,14 @@ vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
11191119
* any time, and that each vacuum is always an independent transaction.
11201120
*/
11211121
cutoffs->OldestXmin = GetOldestNonRemovableTransactionId(rel);
1122+
if (VacuumHorizonHook)
1123+
{
1124+
TransactionId horizon = VacuumHorizonHook();
1125+
1126+
if (TransactionIdIsValid(horizon) &&
1127+
TransactionIdFollows(cutoffs->OldestXmin, horizon))
1128+
cutoffs->OldestXmin = horizon;
1129+
}
11221130

11231131
if (OldSnapshotThresholdActive())
11241132
{
@@ -1635,6 +1643,14 @@ vac_update_datfrozenxid(void)
16351643
* cannot produce a wrong minimum by starting with this.
16361644
*/
16371645
newFrozenXid = GetOldestNonRemovableTransactionId(NULL);
1646+
if (VacuumHorizonHook)
1647+
{
1648+
TransactionId horizon = VacuumHorizonHook();
1649+
1650+
if (TransactionIdIsValid(horizon) &&
1651+
TransactionIdFollows(newFrozenXid, horizon))
1652+
newFrozenXid = horizon;
1653+
}
16381654

16391655
/*
16401656
* 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
@@ -314,6 +314,10 @@ extern void heap_vacuum_rel(Relation rel,
314314
struct VacuumParams *params, BufferAccessStrategy bstrategy);
315315

316316
/* in heap/heapam_visibility.c */
317+
typedef TransactionId (*VacuumHorizonHookType) (void);
318+
319+
extern VacuumHorizonHookType VacuumHorizonHook;
320+
317321
extern bool HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot,
318322
Buffer buffer);
319323
extern TM_Result HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
@@ -328,8 +332,6 @@ extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
328332
extern bool HeapTupleIsSurelyDead(HeapTuple htup,
329333
struct GlobalVisState *vistest);
330334

331-
extern void SetHintBitsHorizon(TransactionId new_horizon);
332-
333335
/*
334336
* To avoid leaking too much knowledge about reorderbuffer implementation
335337
* details this is implemented in reorderbuffer.c not heapam_visibility.c

0 commit comments

Comments
 (0)