Commit af4b1a08 authored by Simon Riggs's avatar Simon Riggs

Refactor GetOldestXmin() to use flags

Replace ignoreVacuum parameter with more flexible flags.

Author: Eiji Seki
Review: Haribabu Kommi
parent 49bff530
...@@ -557,7 +557,7 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen) ...@@ -557,7 +557,7 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
if (all_visible) if (all_visible)
{ {
/* Don't pass rel; that will fail in recovery. */ /* Don't pass rel; that will fail in recovery. */
OldestXmin = GetOldestXmin(NULL, true); OldestXmin = GetOldestXmin(NULL, PROCARRAY_FLAGS_VACUUM);
} }
rel = relation_open(relid, AccessShareLock); rel = relation_open(relid, AccessShareLock);
...@@ -674,7 +674,7 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen) ...@@ -674,7 +674,7 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
* a buffer lock. And this shouldn't happen often, so it's * a buffer lock. And this shouldn't happen often, so it's
* worth being careful so as to avoid false positives. * worth being careful so as to avoid false positives.
*/ */
RecomputedOldestXmin = GetOldestXmin(NULL, true); RecomputedOldestXmin = GetOldestXmin(NULL, PROCARRAY_FLAGS_VACUUM);
if (!TransactionIdPrecedes(OldestXmin, RecomputedOldestXmin)) if (!TransactionIdPrecedes(OldestXmin, RecomputedOldestXmin))
record_corrupt_item(items, &tuple.t_self); record_corrupt_item(items, &tuple.t_self);
......
...@@ -70,7 +70,7 @@ statapprox_heap(Relation rel, output_type *stat) ...@@ -70,7 +70,7 @@ statapprox_heap(Relation rel, output_type *stat)
TransactionId OldestXmin; TransactionId OldestXmin;
uint64 misc_count = 0; uint64 misc_count = 0;
OldestXmin = GetOldestXmin(rel, true); OldestXmin = GetOldestXmin(rel, PROCARRAY_FLAGS_VACUUM);
bstrategy = GetAccessStrategy(BAS_BULKREAD); bstrategy = GetAccessStrategy(BAS_BULKREAD);
nblocks = RelationGetNumberOfBlocks(rel); nblocks = RelationGetNumberOfBlocks(rel);
......
...@@ -8895,7 +8895,7 @@ CreateCheckPoint(int flags) ...@@ -8895,7 +8895,7 @@ CreateCheckPoint(int flags)
* StartupSUBTRANS hasn't been called yet. * StartupSUBTRANS hasn't been called yet.
*/ */
if (!RecoveryInProgress()) if (!RecoveryInProgress())
TruncateSUBTRANS(GetOldestXmin(NULL, false)); TruncateSUBTRANS(GetOldestXmin(NULL, PROCARRAY_FLAGS_DEFAULT));
/* Real work is done, but log and update stats before releasing lock. */ /* Real work is done, but log and update stats before releasing lock. */
LogCheckpointEnd(false); LogCheckpointEnd(false);
...@@ -9258,7 +9258,7 @@ CreateRestartPoint(int flags) ...@@ -9258,7 +9258,7 @@ CreateRestartPoint(int flags)
* this because StartupSUBTRANS hasn't been called yet. * this because StartupSUBTRANS hasn't been called yet.
*/ */
if (EnableHotStandby) if (EnableHotStandby)
TruncateSUBTRANS(GetOldestXmin(NULL, false)); TruncateSUBTRANS(GetOldestXmin(NULL, PROCARRAY_FLAGS_DEFAULT));
/* Real work is done, but log and update before releasing lock. */ /* Real work is done, but log and update before releasing lock. */
LogCheckpointEnd(true); LogCheckpointEnd(true);
......
...@@ -2270,7 +2270,7 @@ IndexBuildHeapRangeScan(Relation heapRelation, ...@@ -2270,7 +2270,7 @@ IndexBuildHeapRangeScan(Relation heapRelation,
{ {
snapshot = SnapshotAny; snapshot = SnapshotAny;
/* okay to ignore lazy VACUUMs here */ /* okay to ignore lazy VACUUMs here */
OldestXmin = GetOldestXmin(heapRelation, true); OldestXmin = GetOldestXmin(heapRelation, PROCARRAY_FLAGS_VACUUM);
} }
scan = heap_beginscan_strat(heapRelation, /* relation */ scan = heap_beginscan_strat(heapRelation, /* relation */
......
...@@ -1000,7 +1000,7 @@ acquire_sample_rows(Relation onerel, int elevel, ...@@ -1000,7 +1000,7 @@ acquire_sample_rows(Relation onerel, int elevel,
totalblocks = RelationGetNumberOfBlocks(onerel); totalblocks = RelationGetNumberOfBlocks(onerel);
/* Need a cutoff xmin for HeapTupleSatisfiesVacuum */ /* Need a cutoff xmin for HeapTupleSatisfiesVacuum */
OldestXmin = GetOldestXmin(onerel, true); OldestXmin = GetOldestXmin(onerel, PROCARRAY_FLAGS_VACUUM);
/* Prepare for sampling block numbers */ /* Prepare for sampling block numbers */
BlockSampler_Init(&bs, totalblocks, targrows, random()); BlockSampler_Init(&bs, totalblocks, targrows, random());
......
...@@ -527,7 +527,7 @@ vacuum_set_xid_limits(Relation rel, ...@@ -527,7 +527,7 @@ vacuum_set_xid_limits(Relation rel,
* always an independent transaction. * always an independent transaction.
*/ */
*oldestXmin = *oldestXmin =
TransactionIdLimitedForOldSnapshots(GetOldestXmin(rel, true), rel); TransactionIdLimitedForOldSnapshots(GetOldestXmin(rel, PROCARRAY_FLAGS_VACUUM), rel);
Assert(TransactionIdIsNormal(*oldestXmin)); Assert(TransactionIdIsNormal(*oldestXmin));
...@@ -939,7 +939,7 @@ vac_update_datfrozenxid(void) ...@@ -939,7 +939,7 @@ vac_update_datfrozenxid(void)
* committed pg_class entries for new tables; see AddNewRelationTuple(). * committed pg_class entries for new tables; see AddNewRelationTuple().
* So we cannot produce a wrong minimum by starting with this. * So we cannot produce a wrong minimum by starting with this.
*/ */
newFrozenXid = GetOldestXmin(NULL, true); newFrozenXid = GetOldestXmin(NULL, PROCARRAY_FLAGS_VACUUM);
/* /*
* Similarly, initialize the MultiXact "min" with the value that would be * Similarly, initialize the MultiXact "min" with the value that would be
......
...@@ -1221,7 +1221,7 @@ XLogWalRcvSendHSFeedback(bool immed) ...@@ -1221,7 +1221,7 @@ XLogWalRcvSendHSFeedback(bool immed)
* everything else has been checked. * everything else has been checked.
*/ */
if (hot_standby_feedback) if (hot_standby_feedback)
xmin = GetOldestXmin(NULL, false); xmin = GetOldestXmin(NULL, PROCARRAY_FLAGS_DEFAULT);
else else
xmin = InvalidTransactionId; xmin = InvalidTransactionId;
......
...@@ -1260,8 +1260,9 @@ TransactionIdIsActive(TransactionId xid) ...@@ -1260,8 +1260,9 @@ TransactionIdIsActive(TransactionId xid)
* If rel is NULL or a shared relation, all backends are considered, otherwise * If rel is NULL or a shared relation, all backends are considered, otherwise
* only backends running in this database are considered. * only backends running in this database are considered.
* *
* If ignoreVacuum is TRUE then backends with the PROC_IN_VACUUM flag set are * The flags are used to ignore the backends in calculation when any of the
* ignored. * corresponding flags is set. Typically, if you want to ignore ones with
* PROC_IN_VACUUM flag, you can use PROCARRAY_FLAGS_VACUUM.
* *
* This is used by VACUUM to decide which deleted tuples must be preserved in * This is used by VACUUM to decide which deleted tuples must be preserved in
* the passed in table. For shared relations backends in all databases must be * the passed in table. For shared relations backends in all databases must be
...@@ -1302,7 +1303,7 @@ TransactionIdIsActive(TransactionId xid) ...@@ -1302,7 +1303,7 @@ TransactionIdIsActive(TransactionId xid)
* GetOldestXmin() move backwards, with no consequences for data integrity. * GetOldestXmin() move backwards, with no consequences for data integrity.
*/ */
TransactionId TransactionId
GetOldestXmin(Relation rel, bool ignoreVacuum) GetOldestXmin(Relation rel, int flags)
{ {
ProcArrayStruct *arrayP = procArray; ProcArrayStruct *arrayP = procArray;
TransactionId result; TransactionId result;
...@@ -1340,14 +1341,7 @@ GetOldestXmin(Relation rel, bool ignoreVacuum) ...@@ -1340,14 +1341,7 @@ GetOldestXmin(Relation rel, bool ignoreVacuum)
volatile PGPROC *proc = &allProcs[pgprocno]; volatile PGPROC *proc = &allProcs[pgprocno];
volatile PGXACT *pgxact = &allPgXact[pgprocno]; volatile PGXACT *pgxact = &allPgXact[pgprocno];
/* if (pgxact->vacuumFlags & flags)
* Backend is doing logical decoding which manages xmin separately,
* check below.
*/
if (pgxact->vacuumFlags & PROC_IN_LOGICAL_DECODING)
continue;
if (ignoreVacuum && (pgxact->vacuumFlags & PROC_IN_VACUUM))
continue; continue;
if (allDbs || if (allDbs ||
......
...@@ -39,7 +39,12 @@ struct XidCache ...@@ -39,7 +39,12 @@ struct XidCache
TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS]; TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS];
}; };
/* Flags for PGXACT->vacuumFlags */ /*
* Flags for PGXACT->vacuumFlags
*
* Note: If you modify these flags, you need to modify PROCARRAY_XXX flags
* in src/include/storage/procarray.h.
*/
#define PROC_IS_AUTOVACUUM 0x01 /* is it an autovac worker? */ #define PROC_IS_AUTOVACUUM 0x01 /* is it an autovac worker? */
#define PROC_IN_VACUUM 0x02 /* currently running lazy vacuum */ #define PROC_IN_VACUUM 0x02 /* currently running lazy vacuum */
#define PROC_IN_ANALYZE 0x04 /* currently running analyze */ #define PROC_IN_ANALYZE 0x04 /* currently running analyze */
......
...@@ -20,6 +20,28 @@ ...@@ -20,6 +20,28 @@
#include "utils/snapshot.h" #include "utils/snapshot.h"
/*
* These are to implement PROCARRAY_FLAGS_XXX
*
* Note: These flags are cloned from PROC_XXX flags in src/include/storage/proc.h
* to avoid forcing to include proc.h when including procarray.h. So if you modify
* PROC_XXX flags, you need to modify these flags.
*/
#define PROCARRAY_VACUUM_FLAG 0x02 /* currently running lazy vacuum */
#define PROCARRAY_ANALYZE_FLAG 0x04 /* currently running analyze */
#define PROCARRAY_LOGICAL_DECODING_FLAG 0x10 /* currently doing logical
* decoding outside xact */
/* Use the following flags as an input "flags" to GetOldestXmin function */
/* Consider all backends except for logical decoding ones which manage xmin separately */
#define PROCARRAY_FLAGS_DEFAULT PROCARRAY_LOGICAL_DECODING_FLAG
/* Ignore vacuum backends */
#define PROCARRAY_FLAGS_VACUUM PROCARRAY_FLAGS_DEFAULT | PROCARRAY_VACUUM_FLAG
/* Ignore analyze backends */
#define PROCARRAY_FLAGS_ANALYZE PROCARRAY_FLAGS_DEFAULT | PROCARRAY_ANALYZE_FLAG
/* Ignore both vacuum and analyze backends */
#define PROCARRAY_FLAGS_VACUUM_ANALYZE PROCARRAY_FLAGS_DEFAULT | PROCARRAY_VACUUM_FLAG | PROCARRAY_ANALYZE_FLAG
extern Size ProcArrayShmemSize(void); extern Size ProcArrayShmemSize(void);
extern void CreateSharedProcArray(void); extern void CreateSharedProcArray(void);
extern void ProcArrayAdd(PGPROC *proc); extern void ProcArrayAdd(PGPROC *proc);
...@@ -53,7 +75,7 @@ extern RunningTransactions GetRunningTransactionData(void); ...@@ -53,7 +75,7 @@ extern RunningTransactions GetRunningTransactionData(void);
extern bool TransactionIdIsInProgress(TransactionId xid); extern bool TransactionIdIsInProgress(TransactionId xid);
extern bool TransactionIdIsActive(TransactionId xid); extern bool TransactionIdIsActive(TransactionId xid);
extern TransactionId GetOldestXmin(Relation rel, bool ignoreVacuum); extern TransactionId GetOldestXmin(Relation rel, int flags);
extern TransactionId GetOldestActiveTransactionId(void); extern TransactionId GetOldestActiveTransactionId(void);
extern TransactionId GetOldestSafeDecodingTransactionId(void); extern TransactionId GetOldestSafeDecodingTransactionId(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment