From c6043fcbb23875926f3b674b2e22dfaa9c6cf300 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Sun, 11 Jun 2023 10:33:46 +0900 Subject: [PATCH] Fix missing initializations of MyProc.delayChkptEnd 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 (mengjuan.cmj@alibaba-inc.com) Reviewed-by: Kyotaro Horiguchi, Michael Paquier Discussion: https://postgr.es/m/9c3d2a49-db5f-43cb-840b-d58f9a684295.mengjuan.cmj@alibaba-inc.com Backpatch-through: 11 --- src/backend/storage/ipc/procarray.c | 1 + src/backend/storage/lmgr/proc.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 4e7e0934cb..b8b4ec00f0 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -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 diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 55716ccaf5..4cefa306f6 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -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;