mirror of
https://github.com/postgres/postgres.git
synced 2025-10-22 14:32:25 +03:00
Refactor how VACUUM passes around its XID cutoffs.
Use a dedicated struct for the XID/MXID cutoffs used by VACUUM, such as FreezeLimit and OldestXmin. This state is initialized in vacuum.c, and then passed around by code from vacuumlazy.c to heapam.c freezing related routines. The new convention is that everybody works off of the same cutoff state, which is passed around via pointers to const. Also simplify some of the logic for dealing with frozen xmin in heap_prepare_freeze_tuple: add dedicated "xmin_already_frozen" state to clearly distinguish xmin XIDs that we're going to freeze from those that were already frozen from before. That way the routine's xmin handling code is symmetrical with the existing xmax handling code. This is preparation for an upcoming commit that will add page level freezing. Also refactor the control flow within FreezeMultiXactId(), while adding stricter sanity checks. We now test OldestXmin directly, instead of using FreezeLimit as an inexact proxy for OldestXmin. This is further preparation for the page level freezing work, which will make the function's caller cede control of page level freezing to the function where appropriate (where heap_prepare_freeze_tuple sees a tuple that happens to contain a MultiXactId in its xmax). Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Jeff Davis <pgsql@j-davis.com> Discussion: https://postgr.es/m/CAH2-WznS9TxXmz2_=SY+SyJyDFbiOftKofM9=aDo68BbXNBUMA@mail.gmail.com
This commit is contained in:
@@ -235,6 +235,45 @@ typedef struct VacuumParams
|
||||
int nworkers;
|
||||
} VacuumParams;
|
||||
|
||||
/*
|
||||
* VacuumCutoffs is immutable state that describes the cutoffs used by VACUUM.
|
||||
* Established at the beginning of each VACUUM operation.
|
||||
*/
|
||||
struct VacuumCutoffs
|
||||
{
|
||||
/*
|
||||
* Existing pg_class fields at start of VACUUM
|
||||
*/
|
||||
TransactionId relfrozenxid;
|
||||
MultiXactId relminmxid;
|
||||
|
||||
/*
|
||||
* OldestXmin is the Xid below which tuples deleted by any xact (that
|
||||
* committed) should be considered DEAD, not just RECENTLY_DEAD.
|
||||
*
|
||||
* OldestMxact is the Mxid below which MultiXacts are definitely not seen
|
||||
* as visible by any running transaction.
|
||||
*
|
||||
* OldestXmin and OldestMxact are also the most recent values that can
|
||||
* ever be passed to vac_update_relstats() as frozenxid and minmulti
|
||||
* arguments at the end of VACUUM. These same values should be passed
|
||||
* when it turns out that VACUUM will leave no unfrozen XIDs/MXIDs behind
|
||||
* in the table.
|
||||
*/
|
||||
TransactionId OldestXmin;
|
||||
MultiXactId OldestMxact;
|
||||
|
||||
/*
|
||||
* FreezeLimit is the Xid below which all Xids are definitely frozen or
|
||||
* removed in pages VACUUM scans and cleanup locks.
|
||||
*
|
||||
* MultiXactCutoff is the value below which all MultiXactIds are
|
||||
* definitely removed from Xmax in pages VACUUM scans and cleanup locks.
|
||||
*/
|
||||
TransactionId FreezeLimit;
|
||||
MultiXactId MultiXactCutoff;
|
||||
};
|
||||
|
||||
/*
|
||||
* VacDeadItems stores TIDs whose index tuples are deleted by index vacuuming.
|
||||
*/
|
||||
@@ -286,13 +325,9 @@ extern void vac_update_relstats(Relation relation,
|
||||
bool *frozenxid_updated,
|
||||
bool *minmulti_updated,
|
||||
bool in_outer_xact);
|
||||
extern bool vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
|
||||
TransactionId *OldestXmin,
|
||||
MultiXactId *OldestMxact,
|
||||
TransactionId *FreezeLimit,
|
||||
MultiXactId *MultiXactCutoff);
|
||||
extern bool vacuum_xid_failsafe_check(TransactionId relfrozenxid,
|
||||
MultiXactId relminmxid);
|
||||
extern bool vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
|
||||
struct VacuumCutoffs *cutoffs);
|
||||
extern bool vacuum_xid_failsafe_check(const struct VacuumCutoffs *cutoffs);
|
||||
extern void vac_update_datfrozenxid(void);
|
||||
extern void vacuum_delay_point(void);
|
||||
extern bool vacuum_is_permitted_for_relation(Oid relid, Form_pg_class reltuple,
|
||||
|
Reference in New Issue
Block a user