Rename delayChkpt to delayChkptFlags.

Before commit 412ad7a55639516f284cd0ef9757d6ae5c7abd43, delayChkpt
was a Boolean. Now it's an integer. Extensions using it need to be
appropriately updated, so let's rename the field to make sure that
a hard compilation failure occurs.

Replacing delayChkpt with delayChkptFlags made a few comments extend
past 80 characters, so I reflowed them and changed some wording very
slightly.

The back-branches will need a different change to restore compatibility
with existing minor releases; this is just for master.

Per suggestion from Tom Lane.

Discussion: http://postgr.es/m/a7880f4d-1d74-582a-ada7-dad168d046d1@enterprisedb.com
This commit is contained in:
Robert Haas 2022-04-08 11:44:17 -04:00
parent 891624f0ec
commit f37015a161
10 changed files with 57 additions and 56 deletions

View File

@ -3088,8 +3088,8 @@ TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB)
* crash/basebackup, even though the state of the data directory would * crash/basebackup, even though the state of the data directory would
* require it. * require it.
*/ */
Assert((MyProc->delayChkpt & DELAY_CHKPT_START) == 0); Assert((MyProc->delayChkptFlags & DELAY_CHKPT_START) == 0);
MyProc->delayChkpt |= DELAY_CHKPT_START; MyProc->delayChkptFlags |= DELAY_CHKPT_START;
/* WAL log truncation */ /* WAL log truncation */
WriteMTruncateXlogRec(newOldestMultiDB, WriteMTruncateXlogRec(newOldestMultiDB,
@ -3115,7 +3115,7 @@ TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB)
/* Then offsets */ /* Then offsets */
PerformOffsetsTruncation(oldestMulti, newOldestMulti); PerformOffsetsTruncation(oldestMulti, newOldestMulti);
MyProc->delayChkpt &= ~DELAY_CHKPT_START; MyProc->delayChkptFlags &= ~DELAY_CHKPT_START;
END_CRIT_SECTION(); END_CRIT_SECTION();
LWLockRelease(MultiXactTruncationLock); LWLockRelease(MultiXactTruncationLock);

View File

@ -479,7 +479,7 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid,
} }
proc->xid = xid; proc->xid = xid;
Assert(proc->xmin == InvalidTransactionId); Assert(proc->xmin == InvalidTransactionId);
proc->delayChkpt = 0; proc->delayChkptFlags = 0;
proc->statusFlags = 0; proc->statusFlags = 0;
proc->pid = 0; proc->pid = 0;
proc->databaseId = databaseid; proc->databaseId = databaseid;
@ -1173,11 +1173,11 @@ EndPrepare(GlobalTransaction gxact)
* Now writing 2PC state data to WAL. We let the WAL's CRC protection * Now writing 2PC state data to WAL. We let the WAL's CRC protection
* cover us, so no need to calculate a separate CRC. * cover us, so no need to calculate a separate CRC.
* *
* We have to set delayChkpt here, too; otherwise a checkpoint starting * We have to set DELAY_CHKPT_START here, too; otherwise a checkpoint
* immediately after the WAL record is inserted could complete without * starting immediately after the WAL record is inserted could complete
* fsync'ing our state file. (This is essentially the same kind of race * without fsync'ing our state file. (This is essentially the same kind
* condition as the COMMIT-to-clog-write case that RecordTransactionCommit * of race condition as the COMMIT-to-clog-write case that
* uses delayChkpt for; see notes there.) * RecordTransactionCommit uses DELAY_CHKPT_START for; see notes there.)
* *
* We save the PREPARE record's location in the gxact for later use by * We save the PREPARE record's location in the gxact for later use by
* CheckPointTwoPhase. * CheckPointTwoPhase.
@ -1186,8 +1186,8 @@ EndPrepare(GlobalTransaction gxact)
START_CRIT_SECTION(); START_CRIT_SECTION();
Assert((MyProc->delayChkpt & DELAY_CHKPT_START) == 0); Assert((MyProc->delayChkptFlags & DELAY_CHKPT_START) == 0);
MyProc->delayChkpt |= DELAY_CHKPT_START; MyProc->delayChkptFlags |= DELAY_CHKPT_START;
XLogBeginInsert(); XLogBeginInsert();
for (record = records.head; record != NULL; record = record->next) for (record = records.head; record != NULL; record = record->next)
@ -1230,7 +1230,7 @@ EndPrepare(GlobalTransaction gxact)
* checkpoint starting after this will certainly see the gxact as a * checkpoint starting after this will certainly see the gxact as a
* candidate for fsyncing. * candidate for fsyncing.
*/ */
MyProc->delayChkpt &= ~DELAY_CHKPT_START; MyProc->delayChkptFlags &= ~DELAY_CHKPT_START;
/* /*
* Remember that we have this GlobalTransaction entry locked for us. If * Remember that we have this GlobalTransaction entry locked for us. If
@ -1817,7 +1817,7 @@ CheckPointTwoPhase(XLogRecPtr redo_horizon)
* *
* Note that it isn't possible for there to be a GXACT with a * Note that it isn't possible for there to be a GXACT with a
* prepare_end_lsn set prior to the last checkpoint yet is marked invalid, * prepare_end_lsn set prior to the last checkpoint yet is marked invalid,
* because of the efforts with delayChkpt. * because of the efforts with delayChkptFlags.
*/ */
LWLockAcquire(TwoPhaseStateLock, LW_SHARED); LWLockAcquire(TwoPhaseStateLock, LW_SHARED);
for (i = 0; i < TwoPhaseState->numPrepXacts; i++) for (i = 0; i < TwoPhaseState->numPrepXacts; i++)
@ -2275,7 +2275,7 @@ ProcessTwoPhaseBuffer(TransactionId xid,
* RecordTransactionCommitPrepared * RecordTransactionCommitPrepared
* *
* This is basically the same as RecordTransactionCommit (q.v. if you change * This is basically the same as RecordTransactionCommit (q.v. if you change
* this function): in particular, we must set the delayChkpt flag to avoid a * this function): in particular, we must set DELAY_CHKPT_START to avoid a
* race condition. * race condition.
* *
* We know the transaction made at least one XLOG entry (its PREPARE), * We know the transaction made at least one XLOG entry (its PREPARE),
@ -2308,8 +2308,8 @@ RecordTransactionCommitPrepared(TransactionId xid,
START_CRIT_SECTION(); START_CRIT_SECTION();
/* See notes in RecordTransactionCommit */ /* See notes in RecordTransactionCommit */
Assert((MyProc->delayChkpt & DELAY_CHKPT_START) == 0); Assert((MyProc->delayChkptFlags & DELAY_CHKPT_START) == 0);
MyProc->delayChkpt |= DELAY_CHKPT_START; MyProc->delayChkptFlags |= DELAY_CHKPT_START;
/* /*
* Emit the XLOG commit record. Note that we mark 2PC commits as * Emit the XLOG commit record. Note that we mark 2PC commits as
@ -2358,7 +2358,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
TransactionIdCommitTree(xid, nchildren, children); TransactionIdCommitTree(xid, nchildren, children);
/* Checkpoint can proceed now */ /* Checkpoint can proceed now */
MyProc->delayChkpt &= ~DELAY_CHKPT_START; MyProc->delayChkptFlags &= ~DELAY_CHKPT_START;
END_CRIT_SECTION(); END_CRIT_SECTION();

View File

@ -1387,14 +1387,14 @@ RecordTransactionCommit(void)
* RecordTransactionAbort. That's because loss of a transaction abort * RecordTransactionAbort. That's because loss of a transaction abort
* is noncritical; the presumption would be that it aborted, anyway. * is noncritical; the presumption would be that it aborted, anyway.
* *
* It's safe to change the delayChkpt flag of our own backend without * It's safe to change the delayChkptFlags flag of our own backend
* holding the ProcArrayLock, since we're the only one modifying it. * without holding the ProcArrayLock, since we're the only one
* This makes checkpoint's determination of which xacts are delayChkpt * modifying it. This makes checkpoint's determination of which xacts
* a bit fuzzy, but it doesn't matter. * are delaying the checkpoint a bit fuzzy, but it doesn't matter.
*/ */
Assert((MyProc->delayChkpt & DELAY_CHKPT_START) == 0); Assert((MyProc->delayChkptFlags & DELAY_CHKPT_START) == 0);
START_CRIT_SECTION(); START_CRIT_SECTION();
MyProc->delayChkpt |= DELAY_CHKPT_START; MyProc->delayChkptFlags |= DELAY_CHKPT_START;
SetCurrentTransactionStopTimestamp(); SetCurrentTransactionStopTimestamp();
@ -1496,7 +1496,7 @@ RecordTransactionCommit(void)
*/ */
if (markXidCommitted) if (markXidCommitted)
{ {
MyProc->delayChkpt &= ~DELAY_CHKPT_START; MyProc->delayChkptFlags &= ~DELAY_CHKPT_START;
END_CRIT_SECTION(); END_CRIT_SECTION();
} }

View File

@ -6505,11 +6505,11 @@ CreateCheckPoint(int flags)
* protected by different locks, but again that seems best on grounds of * protected by different locks, but again that seems best on grounds of
* minimizing lock contention.) * minimizing lock contention.)
* *
* A transaction that has not yet set delayChkpt when we look cannot be at * A transaction that has not yet set delayChkptFlags when we look cannot
* risk, since he's not inserted his commit record yet; and one that's * be at risk, since it has not inserted its commit record yet; and one
* already cleared it is not at risk either, since he's done fixing clog * that's already cleared it is not at risk either, since it's done fixing
* and we will correctly flush the update below. So we cannot miss any * clog and we will correctly flush the update below. So we cannot miss
* xacts we need to wait for. * any xacts we need to wait for.
*/ */
vxids = GetVirtualXIDsDelayingChkpt(&nvxids, DELAY_CHKPT_START); vxids = GetVirtualXIDsDelayingChkpt(&nvxids, DELAY_CHKPT_START);
if (nvxids > 0) if (nvxids > 0)

View File

@ -1011,7 +1011,7 @@ XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
/* /*
* Ensure no checkpoint can change our view of RedoRecPtr. * Ensure no checkpoint can change our view of RedoRecPtr.
*/ */
Assert((MyProc->delayChkpt & DELAY_CHKPT_START) != 0); Assert((MyProc->delayChkptFlags & DELAY_CHKPT_START) != 0);
/* /*
* Update RedoRecPtr so that we can make the right decision * Update RedoRecPtr so that we can make the right decision

View File

@ -348,8 +348,8 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
* the blocks to not exist on disk at all, but not for them to have the * the blocks to not exist on disk at all, but not for them to have the
* wrong contents. * wrong contents.
*/ */
Assert((MyProc->delayChkpt & DELAY_CHKPT_COMPLETE) == 0); Assert((MyProc->delayChkptFlags & DELAY_CHKPT_COMPLETE) == 0);
MyProc->delayChkpt |= DELAY_CHKPT_COMPLETE; MyProc->delayChkptFlags |= DELAY_CHKPT_COMPLETE;
/* /*
* We WAL-log the truncation before actually truncating, which means * We WAL-log the truncation before actually truncating, which means
@ -397,7 +397,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
smgrtruncate(RelationGetSmgr(rel), forks, nforks, blocks); smgrtruncate(RelationGetSmgr(rel), forks, nforks, blocks);
/* We've done all the critical work, so checkpoints are OK now. */ /* We've done all the critical work, so checkpoints are OK now. */
MyProc->delayChkpt &= ~DELAY_CHKPT_COMPLETE; MyProc->delayChkptFlags &= ~DELAY_CHKPT_COMPLETE;
/* /*
* Update upper-level FSM pages to account for the truncation. This is * Update upper-level FSM pages to account for the truncation. This is

View File

@ -4021,7 +4021,7 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
{ {
XLogRecPtr lsn = InvalidXLogRecPtr; XLogRecPtr lsn = InvalidXLogRecPtr;
bool dirtied = false; bool dirtied = false;
bool delayChkpt = false; bool delayChkptFlags = false;
uint32 buf_state; uint32 buf_state;
/* /*
@ -4071,9 +4071,9 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
* essential that CreateCheckPoint waits for virtual transactions * essential that CreateCheckPoint waits for virtual transactions
* rather than full transactionids. * rather than full transactionids.
*/ */
Assert((MyProc->delayChkpt & DELAY_CHKPT_START) == 0); Assert((MyProc->delayChkptFlags & DELAY_CHKPT_START) == 0);
MyProc->delayChkpt |= DELAY_CHKPT_START; MyProc->delayChkptFlags |= DELAY_CHKPT_START;
delayChkpt = true; delayChkptFlags = true;
lsn = XLogSaveBufferForHint(buffer, buffer_std); lsn = XLogSaveBufferForHint(buffer, buffer_std);
} }
@ -4105,8 +4105,8 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
buf_state |= BM_DIRTY | BM_JUST_DIRTIED; buf_state |= BM_DIRTY | BM_JUST_DIRTIED;
UnlockBufHdr(bufHdr, buf_state); UnlockBufHdr(bufHdr, buf_state);
if (delayChkpt) if (delayChkptFlags)
MyProc->delayChkpt &= ~DELAY_CHKPT_START; MyProc->delayChkptFlags &= ~DELAY_CHKPT_START;
if (dirtied) if (dirtied)
{ {

View File

@ -700,7 +700,7 @@ ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid)
proc->xmin = InvalidTransactionId; proc->xmin = InvalidTransactionId;
/* be sure this is cleared in abort */ /* be sure this is cleared in abort */
proc->delayChkpt = 0; proc->delayChkptFlags = 0;
proc->recoveryConflictPending = false; proc->recoveryConflictPending = false;
@ -742,7 +742,7 @@ ProcArrayEndTransactionInternal(PGPROC *proc, TransactionId latestXid)
proc->xmin = InvalidTransactionId; proc->xmin = InvalidTransactionId;
/* be sure this is cleared in abort */ /* be sure this is cleared in abort */
proc->delayChkpt = 0; proc->delayChkptFlags = 0;
proc->recoveryConflictPending = false; proc->recoveryConflictPending = false;
@ -929,7 +929,7 @@ ProcArrayClearTransaction(PGPROC *proc)
proc->recoveryConflictPending = false; proc->recoveryConflictPending = false;
Assert(!(proc->statusFlags & PROC_VACUUM_STATE_MASK)); Assert(!(proc->statusFlags & PROC_VACUUM_STATE_MASK));
Assert(!proc->delayChkpt); Assert(!proc->delayChkptFlags);
/* /*
* Need to increment completion count even though transaction hasn't * Need to increment completion count even though transaction hasn't
@ -3059,19 +3059,20 @@ GetOldestSafeDecodingTransactionId(bool catalogOnly)
* delaying checkpoint because they have critical actions in progress. * delaying checkpoint because they have critical actions in progress.
* *
* Constructs an array of VXIDs of transactions that are currently in commit * Constructs an array of VXIDs of transactions that are currently in commit
* critical sections, as shown by having specified delayChkpt bits set in their * critical sections, as shown by having specified delayChkptFlags bits set
* PGPROC. * in their PGPROC.
* *
* Returns a palloc'd array that should be freed by the caller. * Returns a palloc'd array that should be freed by the caller.
* *nvxids is the number of valid entries. * *nvxids is the number of valid entries.
* *
* Note that because backends set or clear delayChkpt without holding any lock, * Note that because backends set or clear delayChkptFlags without holding any
* the result is somewhat indeterminate, but we don't really care. Even in * lock, the result is somewhat indeterminate, but we don't really care. Even
* a multiprocessor with delayed writes to shared memory, it should be certain * in a multiprocessor with delayed writes to shared memory, it should be
* that setting of delayChkpt will propagate to shared memory when the backend * certain that setting of delayChkptFlags will propagate to shared memory
* takes a lock, so we cannot fail to see a virtual xact as delayChkpt if * when the backend takes a lock, so we cannot fail to see a virtual xact as
* it's already inserted its commit record. Whether it takes a little while * delayChkptFlags if it's already inserted its commit record. Whether it
* for clearing of delayChkpt to propagate is unimportant for correctness. * takes a little while for clearing of delayChkptFlags to propagate is
* unimportant for correctness.
*/ */
VirtualTransactionId * VirtualTransactionId *
GetVirtualXIDsDelayingChkpt(int *nvxids, int type) GetVirtualXIDsDelayingChkpt(int *nvxids, int type)
@ -3094,7 +3095,7 @@ GetVirtualXIDsDelayingChkpt(int *nvxids, int type)
int pgprocno = arrayP->pgprocnos[index]; int pgprocno = arrayP->pgprocnos[index];
PGPROC *proc = &allProcs[pgprocno]; PGPROC *proc = &allProcs[pgprocno];
if ((proc->delayChkpt & type) != 0) if ((proc->delayChkptFlags & type) != 0)
{ {
VirtualTransactionId vxid; VirtualTransactionId vxid;
@ -3138,7 +3139,7 @@ HaveVirtualXIDsDelayingChkpt(VirtualTransactionId *vxids, int nvxids, int type)
GET_VXID_FROM_PGPROC(vxid, *proc); GET_VXID_FROM_PGPROC(vxid, *proc);
if ((proc->delayChkpt & type) != 0 && if ((proc->delayChkptFlags & type) != 0 &&
VirtualTransactionIdIsValid(vxid)) VirtualTransactionIdIsValid(vxid))
{ {
int i; int i;

View File

@ -393,7 +393,7 @@ InitProcess(void)
MyProc->roleId = InvalidOid; MyProc->roleId = InvalidOid;
MyProc->tempNamespaceId = InvalidOid; MyProc->tempNamespaceId = InvalidOid;
MyProc->isBackgroundWorker = IsBackgroundWorker; MyProc->isBackgroundWorker = IsBackgroundWorker;
MyProc->delayChkpt = 0; MyProc->delayChkptFlags = 0;
MyProc->statusFlags = 0; MyProc->statusFlags = 0;
/* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */ /* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
if (IsAutoVacuumWorkerProcess()) if (IsAutoVacuumWorkerProcess())
@ -578,7 +578,7 @@ InitAuxiliaryProcess(void)
MyProc->roleId = InvalidOid; MyProc->roleId = InvalidOid;
MyProc->tempNamespaceId = InvalidOid; MyProc->tempNamespaceId = InvalidOid;
MyProc->isBackgroundWorker = IsBackgroundWorker; MyProc->isBackgroundWorker = IsBackgroundWorker;
MyProc->delayChkpt = 0; MyProc->delayChkptFlags = 0;
MyProc->statusFlags = 0; MyProc->statusFlags = 0;
MyProc->lwWaiting = false; MyProc->lwWaiting = false;
MyProc->lwWaitMode = 0; MyProc->lwWaitMode = 0;

View File

@ -226,7 +226,7 @@ struct PGPROC
pg_atomic_uint64 waitStart; /* time at which wait for lock acquisition pg_atomic_uint64 waitStart; /* time at which wait for lock acquisition
* started */ * started */
int delayChkpt; /* for DELAY_CHKPT_* flags */ int delayChkptFlags; /* for DELAY_CHKPT_* flags */
uint8 statusFlags; /* this backend's status flags, see PROC_* uint8 statusFlags; /* this backend's status flags, see PROC_*
* above. mirrored in * above. mirrored in