Skip to content

Commit cd9c1b3

Browse files
committed
Rename PGPROC->vacuumFlags to statusFlags
With more flags associated to a PGPROC entry that are not related to vacuum (currently existing or planned), the name "statusFlags" describes its purpose better. (The same is done to the mirroring PROC_HDR->vacuumFlags.) No functional changes in this commit. This was suggested first by Hari Babu Kommi in [1] and then by Michael Paquier at [2]. [1] https://postgr.es/m/CAJrrPGcsDC-oy1AhqH0JkXYa0Z2AgbuXzHPpByLoBGMxfOZMEQ@mail.gmail.com [2] https://postgr.es/m/20200820060929.GB3730@paquier.xyz Author: Dmitry Dolgov <9erthalion6@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/20201116182446.qcg3o6szo2zookyr@localhost
1 parent 4025e6c commit cd9c1b3

File tree

9 files changed

+57
-56
lines changed

9 files changed

+57
-56
lines changed

src/backend/access/transam/twophase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid,
464464
proc->xid = xid;
465465
Assert(proc->xmin == InvalidTransactionId);
466466
proc->delayChkpt = false;
467-
proc->vacuumFlags = 0;
467+
proc->statusFlags = 0;
468468
proc->pid = 0;
469469
proc->backendId = InvalidBackendId;
470470
proc->databaseId = databaseid;

src/backend/commands/vacuum.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,10 +1742,10 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params)
17421742
* might appear to go backwards, which is probably Not Good.
17431743
*/
17441744
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
1745-
MyProc->vacuumFlags |= PROC_IN_VACUUM;
1745+
MyProc->statusFlags |= PROC_IN_VACUUM;
17461746
if (params->is_wraparound)
1747-
MyProc->vacuumFlags |= PROC_VACUUM_FOR_WRAPAROUND;
1748-
ProcGlobal->vacuumFlags[MyProc->pgxactoff] = MyProc->vacuumFlags;
1747+
MyProc->statusFlags |= PROC_VACUUM_FOR_WRAPAROUND;
1748+
ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;
17491749
LWLockRelease(ProcArrayLock);
17501750
}
17511751

src/backend/postmaster/autovacuum.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,7 @@ do_autovacuum(void)
25092509
tab->at_datname, tab->at_nspname, tab->at_relname);
25102510
EmitErrorReport();
25112511

2512-
/* this resets ProcGlobal->vacuumFlags[i] too */
2512+
/* this resets ProcGlobal->statusFlags[i] too */
25132513
AbortOutOfAnyTransaction();
25142514
FlushErrorState();
25152515
MemoryContextResetAndDeleteChildren(PortalContext);
@@ -2525,7 +2525,7 @@ do_autovacuum(void)
25252525

25262526
did_vacuum = true;
25272527

2528-
/* ProcGlobal->vacuumFlags[i] are reset at the next end of xact */
2528+
/* ProcGlobal->statusFlags[i] are reset at the next end of xact */
25292529

25302530
/* be tidy */
25312531
deleted:
@@ -2702,7 +2702,7 @@ perform_work_item(AutoVacuumWorkItem *workitem)
27022702
cur_datname, cur_nspname, cur_relname);
27032703
EmitErrorReport();
27042704

2705-
/* this resets ProcGlobal->vacuumFlags[i] too */
2705+
/* this resets ProcGlobal->statusFlags[i] too */
27062706
AbortOutOfAnyTransaction();
27072707
FlushErrorState();
27082708
MemoryContextResetAndDeleteChildren(PortalContext);

src/backend/replication/logical/logical.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ StartupDecodingContext(List *output_plugin_options,
182182
if (!IsTransactionOrTransactionBlock())
183183
{
184184
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
185-
MyProc->vacuumFlags |= PROC_IN_LOGICAL_DECODING;
186-
ProcGlobal->vacuumFlags[MyProc->pgxactoff] = MyProc->vacuumFlags;
185+
MyProc->statusFlags |= PROC_IN_LOGICAL_DECODING;
186+
ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;
187187
LWLockRelease(ProcArrayLock);
188188
}
189189

src/backend/replication/slot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ ReplicationSlotRelease(void)
528528

529529
/* might not have been set when we've been a plain slot */
530530
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
531-
MyProc->vacuumFlags &= ~PROC_IN_LOGICAL_DECODING;
532-
ProcGlobal->vacuumFlags[MyProc->pgxactoff] = MyProc->vacuumFlags;
531+
MyProc->statusFlags &= ~PROC_IN_LOGICAL_DECODING;
532+
ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;
533533
LWLockRelease(ProcArrayLock);
534534
}
535535

src/backend/storage/ipc/procarray.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,13 @@ ProcArrayAdd(PGPROC *proc)
488488
(arrayP->numProcs - index) * sizeof(*ProcGlobal->xids));
489489
memmove(&ProcGlobal->subxidStates[index + 1], &ProcGlobal->subxidStates[index],
490490
(arrayP->numProcs - index) * sizeof(*ProcGlobal->subxidStates));
491-
memmove(&ProcGlobal->vacuumFlags[index + 1], &ProcGlobal->vacuumFlags[index],
492-
(arrayP->numProcs - index) * sizeof(*ProcGlobal->vacuumFlags));
491+
memmove(&ProcGlobal->statusFlags[index + 1], &ProcGlobal->statusFlags[index],
492+
(arrayP->numProcs - index) * sizeof(*ProcGlobal->statusFlags));
493493

494494
arrayP->pgprocnos[index] = proc->pgprocno;
495495
ProcGlobal->xids[index] = proc->xid;
496496
ProcGlobal->subxidStates[index] = proc->subxidStatus;
497-
ProcGlobal->vacuumFlags[index] = proc->vacuumFlags;
497+
ProcGlobal->statusFlags[index] = proc->statusFlags;
498498

499499
arrayP->numProcs++;
500500

@@ -562,7 +562,7 @@ ProcArrayRemove(PGPROC *proc, TransactionId latestXid)
562562
Assert(TransactionIdIsValid(ProcGlobal->xids[proc->pgxactoff] == 0));
563563
Assert(TransactionIdIsValid(ProcGlobal->subxidStates[proc->pgxactoff].count == 0));
564564
Assert(TransactionIdIsValid(ProcGlobal->subxidStates[proc->pgxactoff].overflowed == false));
565-
ProcGlobal->vacuumFlags[proc->pgxactoff] = 0;
565+
ProcGlobal->statusFlags[proc->pgxactoff] = 0;
566566

567567
for (index = 0; index < arrayP->numProcs; index++)
568568
{
@@ -575,8 +575,8 @@ ProcArrayRemove(PGPROC *proc, TransactionId latestXid)
575575
(arrayP->numProcs - index - 1) * sizeof(*ProcGlobal->xids));
576576
memmove(&ProcGlobal->subxidStates[index], &ProcGlobal->subxidStates[index + 1],
577577
(arrayP->numProcs - index - 1) * sizeof(*ProcGlobal->subxidStates));
578-
memmove(&ProcGlobal->vacuumFlags[index], &ProcGlobal->vacuumFlags[index + 1],
579-
(arrayP->numProcs - index - 1) * sizeof(*ProcGlobal->vacuumFlags));
578+
memmove(&ProcGlobal->statusFlags[index], &ProcGlobal->statusFlags[index + 1],
579+
(arrayP->numProcs - index - 1) * sizeof(*ProcGlobal->statusFlags));
580580

581581
arrayP->pgprocnos[arrayP->numProcs - 1] = -1; /* for debugging */
582582
arrayP->numProcs--;
@@ -660,13 +660,13 @@ ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid)
660660

661661
/* must be cleared with xid/xmin: */
662662
/* avoid unnecessarily dirtying shared cachelines */
663-
if (proc->vacuumFlags & PROC_VACUUM_STATE_MASK)
663+
if (proc->statusFlags & PROC_VACUUM_STATE_MASK)
664664
{
665665
Assert(!LWLockHeldByMe(ProcArrayLock));
666666
LWLockAcquire(ProcArrayLock, LW_SHARED);
667-
Assert(proc->vacuumFlags == ProcGlobal->vacuumFlags[proc->pgxactoff]);
668-
proc->vacuumFlags &= ~PROC_VACUUM_STATE_MASK;
669-
ProcGlobal->vacuumFlags[proc->pgxactoff] = proc->vacuumFlags;
667+
Assert(proc->statusFlags == ProcGlobal->statusFlags[proc->pgxactoff]);
668+
proc->statusFlags &= ~PROC_VACUUM_STATE_MASK;
669+
ProcGlobal->statusFlags[proc->pgxactoff] = proc->statusFlags;
670670
LWLockRelease(ProcArrayLock);
671671
}
672672
}
@@ -695,10 +695,10 @@ ProcArrayEndTransactionInternal(PGPROC *proc, TransactionId latestXid)
695695

696696
/* must be cleared with xid/xmin: */
697697
/* avoid unnecessarily dirtying shared cachelines */
698-
if (proc->vacuumFlags & PROC_VACUUM_STATE_MASK)
698+
if (proc->statusFlags & PROC_VACUUM_STATE_MASK)
699699
{
700-
proc->vacuumFlags &= ~PROC_VACUUM_STATE_MASK;
701-
ProcGlobal->vacuumFlags[proc->pgxactoff] = proc->vacuumFlags;
700+
proc->statusFlags &= ~PROC_VACUUM_STATE_MASK;
701+
ProcGlobal->statusFlags[proc->pgxactoff] = proc->statusFlags;
702702
}
703703

704704
/* Clear the subtransaction-XID cache too while holding the lock */
@@ -875,7 +875,7 @@ ProcArrayClearTransaction(PGPROC *proc)
875875
proc->xmin = InvalidTransactionId;
876876
proc->recoveryConflictPending = false;
877877

878-
Assert(!(proc->vacuumFlags & PROC_VACUUM_STATE_MASK));
878+
Assert(!(proc->statusFlags & PROC_VACUUM_STATE_MASK));
879879
Assert(!proc->delayChkpt);
880880

881881
/*
@@ -1710,7 +1710,7 @@ ComputeXidHorizons(ComputeXidHorizonsResult *h)
17101710
{
17111711
int pgprocno = arrayP->pgprocnos[index];
17121712
PGPROC *proc = &allProcs[pgprocno];
1713-
int8 vacuumFlags = ProcGlobal->vacuumFlags[index];
1713+
int8 statusFlags = ProcGlobal->statusFlags[index];
17141714
TransactionId xid;
17151715
TransactionId xmin;
17161716

@@ -1745,7 +1745,7 @@ ComputeXidHorizons(ComputeXidHorizonsResult *h)
17451745
* removed, as long as pg_subtrans is not truncated) or doing logical
17461746
* decoding (which manages xmin separately, check below).
17471747
*/
1748-
if (vacuumFlags & (PROC_IN_VACUUM | PROC_IN_LOGICAL_DECODING))
1748+
if (statusFlags & (PROC_IN_VACUUM | PROC_IN_LOGICAL_DECODING))
17491749
continue;
17501750

17511751
/* shared tables need to take backends in all database into account */
@@ -2194,7 +2194,7 @@ GetSnapshotData(Snapshot snapshot)
21942194
TransactionId *xip = snapshot->xip;
21952195
int *pgprocnos = arrayP->pgprocnos;
21962196
XidCacheStatus *subxidStates = ProcGlobal->subxidStates;
2197-
uint8 *allVacuumFlags = ProcGlobal->vacuumFlags;
2197+
uint8 *allStatusFlags = ProcGlobal->statusFlags;
21982198

21992199
/*
22002200
* First collect set of pgxactoff/xids that need to be included in the
@@ -2204,7 +2204,7 @@ GetSnapshotData(Snapshot snapshot)
22042204
{
22052205
/* Fetch xid just once - see GetNewTransactionId */
22062206
TransactionId xid = UINT32_ACCESS_ONCE(other_xids[pgxactoff]);
2207-
uint8 vacuumFlags;
2207+
uint8 statusFlags;
22082208

22092209
Assert(allProcs[arrayP->pgprocnos[pgxactoff]].pgxactoff == pgxactoff);
22102210

@@ -2243,8 +2243,8 @@ GetSnapshotData(Snapshot snapshot)
22432243
* Skip over backends doing logical decoding which manages xmin
22442244
* separately (check below) and ones running LAZY VACUUM.
22452245
*/
2246-
vacuumFlags = allVacuumFlags[pgxactoff];
2247-
if (vacuumFlags & (PROC_IN_LOGICAL_DECODING | PROC_IN_VACUUM))
2246+
statusFlags = allStatusFlags[pgxactoff];
2247+
if (statusFlags & (PROC_IN_LOGICAL_DECODING | PROC_IN_VACUUM))
22482248
continue;
22492249

22502250
if (NormalTransactionIdPrecedes(xid, xmin))
@@ -2483,11 +2483,11 @@ ProcArrayInstallImportedXmin(TransactionId xmin,
24832483
{
24842484
int pgprocno = arrayP->pgprocnos[index];
24852485
PGPROC *proc = &allProcs[pgprocno];
2486-
int vacuumFlags = ProcGlobal->vacuumFlags[index];
2486+
int statusFlags = ProcGlobal->statusFlags[index];
24872487
TransactionId xid;
24882488

24892489
/* Ignore procs running LAZY VACUUM */
2490-
if (vacuumFlags & PROC_IN_VACUUM)
2490+
if (statusFlags & PROC_IN_VACUUM)
24912491
continue;
24922492

24932493
/* We are only interested in the specific virtual transaction. */
@@ -3142,7 +3142,7 @@ IsBackendPid(int pid)
31423142
* If excludeXmin0 is true, skip processes with xmin = 0.
31433143
* If allDbs is false, skip processes attached to other databases.
31443144
* If excludeVacuum isn't zero, skip processes for which
3145-
* (vacuumFlags & excludeVacuum) is not zero.
3145+
* (statusFlags & excludeVacuum) is not zero.
31463146
*
31473147
* Note: the purpose of the limitXmin and excludeXmin0 parameters is to
31483148
* allow skipping backends whose oldest live snapshot is no older than
@@ -3176,12 +3176,12 @@ GetCurrentVirtualXIDs(TransactionId limitXmin, bool excludeXmin0,
31763176
{
31773177
int pgprocno = arrayP->pgprocnos[index];
31783178
PGPROC *proc = &allProcs[pgprocno];
3179-
uint8 vacuumFlags = ProcGlobal->vacuumFlags[index];
3179+
uint8 statusFlags = ProcGlobal->statusFlags[index];
31803180

31813181
if (proc == MyProc)
31823182
continue;
31833183

3184-
if (excludeVacuum & vacuumFlags)
3184+
if (excludeVacuum & statusFlags)
31853185
continue;
31863186

31873187
if (allDbs || proc->databaseId == MyDatabaseId)
@@ -3596,7 +3596,7 @@ CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared)
35963596
{
35973597
int pgprocno = arrayP->pgprocnos[index];
35983598
PGPROC *proc = &allProcs[pgprocno];
3599-
uint8 vacuumFlags = ProcGlobal->vacuumFlags[index];
3599+
uint8 statusFlags = ProcGlobal->statusFlags[index];
36003600

36013601
if (proc->databaseId != databaseId)
36023602
continue;
@@ -3610,7 +3610,7 @@ CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared)
36103610
else
36113611
{
36123612
(*nbackends)++;
3613-
if ((vacuumFlags & PROC_IS_AUTOVACUUM) &&
3613+
if ((statusFlags & PROC_IS_AUTOVACUUM) &&
36143614
nautovacs < MAXAUTOVACPIDS)
36153615
autovac_pids[nautovacs++] = proc->pid;
36163616
}

src/backend/storage/lmgr/deadlock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
618618
* that an autovacuum won't be canceled with less than
619619
* deadlock_timeout grace period.
620620
*
621-
* Note we read vacuumFlags without any locking. This is
621+
* Note we read statusFlags without any locking. This is
622622
* OK only for checking the PROC_IS_AUTOVACUUM flag,
623623
* because that flag is set at process start and never
624624
* reset. There is logic elsewhere to avoid canceling an
@@ -628,7 +628,7 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
628628
* ProcArrayLock.
629629
*/
630630
if (checkProc == MyProc &&
631-
proc->vacuumFlags & PROC_IS_AUTOVACUUM)
631+
proc->statusFlags & PROC_IS_AUTOVACUUM)
632632
blocking_autovacuum_proc = proc;
633633

634634
/* We're done looking at this proclock */

src/backend/storage/lmgr/proc.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ ProcGlobalShmemSize(void)
111111

112112
size = add_size(size, mul_size(TotalProcs, sizeof(*ProcGlobal->xids)));
113113
size = add_size(size, mul_size(TotalProcs, sizeof(*ProcGlobal->subxidStates)));
114-
size = add_size(size, mul_size(TotalProcs, sizeof(*ProcGlobal->vacuumFlags)));
114+
size = add_size(size, mul_size(TotalProcs, sizeof(*ProcGlobal->statusFlags)));
115115

116116
return size;
117117
}
@@ -210,8 +210,8 @@ InitProcGlobal(void)
210210
MemSet(ProcGlobal->xids, 0, TotalProcs * sizeof(*ProcGlobal->xids));
211211
ProcGlobal->subxidStates = (XidCacheStatus *) ShmemAlloc(TotalProcs * sizeof(*ProcGlobal->subxidStates));
212212
MemSet(ProcGlobal->subxidStates, 0, TotalProcs * sizeof(*ProcGlobal->subxidStates));
213-
ProcGlobal->vacuumFlags = (uint8 *) ShmemAlloc(TotalProcs * sizeof(*ProcGlobal->vacuumFlags));
214-
MemSet(ProcGlobal->vacuumFlags, 0, TotalProcs * sizeof(*ProcGlobal->vacuumFlags));
213+
ProcGlobal->statusFlags = (uint8 *) ShmemAlloc(TotalProcs * sizeof(*ProcGlobal->statusFlags));
214+
MemSet(ProcGlobal->statusFlags, 0, TotalProcs * sizeof(*ProcGlobal->statusFlags));
215215

216216
for (i = 0; i < TotalProcs; i++)
217217
{
@@ -393,10 +393,10 @@ InitProcess(void)
393393
MyProc->tempNamespaceId = InvalidOid;
394394
MyProc->isBackgroundWorker = IsBackgroundWorker;
395395
MyProc->delayChkpt = false;
396-
MyProc->vacuumFlags = 0;
396+
MyProc->statusFlags = 0;
397397
/* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
398398
if (IsAutoVacuumWorkerProcess())
399-
MyProc->vacuumFlags |= PROC_IS_AUTOVACUUM;
399+
MyProc->statusFlags |= PROC_IS_AUTOVACUUM;
400400
MyProc->lwWaiting = false;
401401
MyProc->lwWaitMode = 0;
402402
MyProc->waitLock = NULL;
@@ -574,7 +574,7 @@ InitAuxiliaryProcess(void)
574574
MyProc->tempNamespaceId = InvalidOid;
575575
MyProc->isBackgroundWorker = IsBackgroundWorker;
576576
MyProc->delayChkpt = false;
577-
MyProc->vacuumFlags = 0;
577+
MyProc->statusFlags = 0;
578578
MyProc->lwWaiting = false;
579579
MyProc->lwWaitMode = 0;
580580
MyProc->waitLock = NULL;
@@ -1310,17 +1310,17 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
13101310
if (deadlock_state == DS_BLOCKED_BY_AUTOVACUUM && allow_autovacuum_cancel)
13111311
{
13121312
PGPROC *autovac = GetBlockingAutoVacuumPgproc();
1313-
uint8 vacuumFlags;
1313+
uint8 statusFlags;
13141314

13151315
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
13161316

13171317
/*
13181318
* Only do it if the worker is not working to protect against Xid
13191319
* wraparound.
13201320
*/
1321-
vacuumFlags = ProcGlobal->vacuumFlags[autovac->pgxactoff];
1322-
if ((vacuumFlags & PROC_IS_AUTOVACUUM) &&
1323-
!(vacuumFlags & PROC_VACUUM_FOR_WRAPAROUND))
1321+
statusFlags = ProcGlobal->statusFlags[autovac->pgxactoff];
1322+
if ((statusFlags & PROC_IS_AUTOVACUUM) &&
1323+
!(statusFlags & PROC_VACUUM_FOR_WRAPAROUND))
13241324
{
13251325
int pid = autovac->pid;
13261326
StringInfoData locktagbuf;

src/include/storage/proc.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct XidCache
4949
};
5050

5151
/*
52-
* Flags for ProcGlobal->vacuumFlags[]
52+
* Flags for PGPROC->statusFlags and PROC_HDR->statusFlags[]
5353
*/
5454
#define PROC_IS_AUTOVACUUM 0x01 /* is it an autovac worker? */
5555
#define PROC_IN_VACUUM 0x02 /* currently running lazy vacuum */
@@ -175,9 +175,10 @@ struct PGPROC
175175

176176
bool delayChkpt; /* true if this proc delays checkpoint start */
177177

178-
uint8 vacuumFlags; /* this backend's vacuum flags, see PROC_*
178+
uint8 statusFlags; /* this backend's status flags, see PROC_*
179179
* above. mirrored in
180-
* ProcGlobal->vacuumFlags[pgxactoff] */
180+
* ProcGlobal->statusFlags[pgxactoff] */
181+
181182
/*
182183
* Info to allow us to wait for synchronous replication, if needed.
183184
* waitLSN is InvalidXLogRecPtr if not waiting; set only by user backend.
@@ -273,7 +274,7 @@ extern PGDLLIMPORT PGPROC *MyProc;
273274
* allow for as tight loops accessing the data as possible. Second, to prevent
274275
* updates of frequently changing data (e.g. xmin) from invalidating
275276
* cachelines also containing less frequently changing data (e.g. xid,
276-
* vacuumFlags). Third to condense frequently accessed data into as few
277+
* statusFlags). Third to condense frequently accessed data into as few
277278
* cachelines as possible.
278279
*
279280
* There are two main reasons to have the data mirrored between these dense
@@ -315,10 +316,10 @@ typedef struct PROC_HDR
315316
XidCacheStatus *subxidStates;
316317

317318
/*
318-
* Array mirroring PGPROC.vacuumFlags for each PGPROC currently in the
319+
* Array mirroring PGPROC.statusFlags for each PGPROC currently in the
319320
* procarray.
320321
*/
321-
uint8 *vacuumFlags;
322+
uint8 *statusFlags;
322323

323324
/* Length of allProcs array */
324325
uint32 allProcCount;

0 commit comments

Comments
 (0)