Fix missing initializations of MyProc.delayChkptEnd
authorMichael Paquier
Sun, 11 Jun 2023 01:33:46 +0000 (10:33 +0900)
committerMichael Paquier
Sun, 11 Jun 2023 01:33:46 +0000 (10:33 +0900)
This commit fixes an oversight introduced in 10520f4, that has added
delayChkptEnd to PGPROC to avoid ABI breakages on stable branches, where
two spots have missed to initialize this variable (delayChkpt was
switched back from int to bool, and it was initialized as 0 so there was
no consequences for it):
- InitProcess(), where the per-process data structures of a backend are
initialized.
- InitAuxiliaryProcess(), same but for auxiliary processes.

An interruption during relation truncation while this flag is set could
cause an assertion failure when a follow-up process does a relation
truncation while reusing the same PGPROC entry.  A second effect could
be incorrect checkpoint end delays.

While on it, add an assertion in ProcArrayClearTransaction() for
delayChkptEnd to be in line with 5788e25.  This is needed only for v14.

This issue affects v11~v14, but not v15~, as we use a single field
called delayChkptFlags to delay checkpoints there.

Author: suyu.cmj ([email protected])
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/9c3d2a49-db5f-43cb-840b-d58f9a684295[email protected]
Backpatch-through: 11

src/backend/storage/ipc/procarray.c
src/backend/storage/lmgr/proc.c

index 4e7e0934cbd5d6f1b535f9c49f96f1596e62ccd3..b8b4ec00f003bd7b4ae729c5888decda5adf8782 100644 (file)
@@ -947,6 +947,7 @@ ProcArrayClearTransaction(PGPROC *proc)
 
    Assert(!(proc->statusFlags & PROC_VACUUM_STATE_MASK));
    Assert(!proc->delayChkpt);
+   Assert(!proc->delayChkptEnd);
 
    /*
     * Need to increment completion count even though transaction hasn't
index 55716ccaf54b43e40c4860bd2b210386e372a7c8..4cefa306f6d00a9486b900bef3cb82f01751b23e 100644 (file)
@@ -394,7 +394,8 @@ InitProcess(void)
    MyProc->roleId = InvalidOid;
    MyProc->tempNamespaceId = InvalidOid;
    MyProc->isBackgroundWorker = IsBackgroundWorker;
-   MyProc->delayChkpt = 0;
+   MyProc->delayChkpt = false;
+   MyProc->delayChkptEnd = false;
    MyProc->statusFlags = 0;
    /* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
    if (IsAutoVacuumWorkerProcess())
@@ -579,7 +580,8 @@ InitAuxiliaryProcess(void)
    MyProc->roleId = InvalidOid;
    MyProc->tempNamespaceId = InvalidOid;
    MyProc->isBackgroundWorker = IsBackgroundWorker;
-   MyProc->delayChkpt = 0;
+   MyProc->delayChkpt = false;
+   MyProc->delayChkptEnd = false;
    MyProc->statusFlags = 0;
    MyProc->lwWaiting = false;
    MyProc->lwWaitMode = 0;