Skip to content

Commit d9e7873

Browse files
committed
In checkpoint, move the check for in-progress xacts out of critical section.
GetVirtualXIDsDelayingChkpt calls palloc, which isn't safe in a critical section. I thought I covered this case with the exemption for the checkpointer, but CreateCheckPoint is also called from the startup process.
1 parent 4a170ee commit d9e7873

File tree

1 file changed

+36
-36
lines changed
  • src/backend/access/transam

1 file changed

+36
-36
lines changed

src/backend/access/transam/xlog.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8076,6 +8076,42 @@ CreateCheckPoint(int flags)
80768076

80778077
TRACE_POSTGRESQL_CHECKPOINT_START(flags);
80788078

8079+
/*
8080+
* Get the other info we need for the checkpoint record.
8081+
*/
8082+
LWLockAcquire(XidGenLock, LW_SHARED);
8083+
checkPoint.nextXid = ShmemVariableCache->nextXid;
8084+
checkPoint.oldestXid = ShmemVariableCache->oldestXid;
8085+
checkPoint.oldestXidDB = ShmemVariableCache->oldestXidDB;
8086+
LWLockRelease(XidGenLock);
8087+
8088+
/* Increase XID epoch if we've wrapped around since last checkpoint */
8089+
checkPoint.nextXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
8090+
if (checkPoint.nextXid < ControlFile->checkPointCopy.nextXid)
8091+
checkPoint.nextXidEpoch++;
8092+
8093+
LWLockAcquire(OidGenLock, LW_SHARED);
8094+
checkPoint.nextOid = ShmemVariableCache->nextOid;
8095+
if (!shutdown)
8096+
checkPoint.nextOid += ShmemVariableCache->oidCount;
8097+
LWLockRelease(OidGenLock);
8098+
8099+
MultiXactGetCheckptMulti(shutdown,
8100+
&checkPoint.nextMulti,
8101+
&checkPoint.nextMultiOffset,
8102+
&checkPoint.oldestMulti,
8103+
&checkPoint.oldestMultiDB);
8104+
8105+
/*
8106+
* Having constructed the checkpoint record, ensure all shmem disk buffers
8107+
* and commit-log buffers are flushed to disk.
8108+
*
8109+
* This I/O could fail for various reasons. If so, we will fail to
8110+
* complete the checkpoint, but there is no reason to force a system
8111+
* panic. Accordingly, exit critical section while doing it.
8112+
*/
8113+
END_CRIT_SECTION();
8114+
80798115
/*
80808116
* In some cases there are groups of actions that must all occur on one
80818117
* side or the other of a checkpoint record. Before flushing the
@@ -8116,42 +8152,6 @@ CreateCheckPoint(int flags)
81168152
}
81178153
pfree(vxids);
81188154

8119-
/*
8120-
* Get the other info we need for the checkpoint record.
8121-
*/
8122-
LWLockAcquire(XidGenLock, LW_SHARED);
8123-
checkPoint.nextXid = ShmemVariableCache->nextXid;
8124-
checkPoint.oldestXid = ShmemVariableCache->oldestXid;
8125-
checkPoint.oldestXidDB = ShmemVariableCache->oldestXidDB;
8126-
LWLockRelease(XidGenLock);
8127-
8128-
/* Increase XID epoch if we've wrapped around since last checkpoint */
8129-
checkPoint.nextXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
8130-
if (checkPoint.nextXid < ControlFile->checkPointCopy.nextXid)
8131-
checkPoint.nextXidEpoch++;
8132-
8133-
LWLockAcquire(OidGenLock, LW_SHARED);
8134-
checkPoint.nextOid = ShmemVariableCache->nextOid;
8135-
if (!shutdown)
8136-
checkPoint.nextOid += ShmemVariableCache->oidCount;
8137-
LWLockRelease(OidGenLock);
8138-
8139-
MultiXactGetCheckptMulti(shutdown,
8140-
&checkPoint.nextMulti,
8141-
&checkPoint.nextMultiOffset,
8142-
&checkPoint.oldestMulti,
8143-
&checkPoint.oldestMultiDB);
8144-
8145-
/*
8146-
* Having constructed the checkpoint record, ensure all shmem disk buffers
8147-
* and commit-log buffers are flushed to disk.
8148-
*
8149-
* This I/O could fail for various reasons. If so, we will fail to
8150-
* complete the checkpoint, but there is no reason to force a system
8151-
* panic. Accordingly, exit critical section while doing it.
8152-
*/
8153-
END_CRIT_SECTION();
8154-
81558155
CheckPointGuts(checkPoint.redo, flags);
81568156

81578157
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy