提交 8d86a960 编写于 作者: T Tom Lane

Adjust CreateCheckpoint so that buffer dumping activities and cleanup of

dead xlog segments are not considered part of a critical section.  It is
not necessary to force a database-wide panic if we get a failure in these
operations.  Per recent trouble reports.
上级 199f24e1
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.114 2003/04/25 19:45:08 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.115 2003/05/10 18:01:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2973,11 +2973,13 @@ CreateCheckPoint(bool shutdown, bool force) ...@@ -2973,11 +2973,13 @@ CreateCheckPoint(bool shutdown, bool force)
elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block"); elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block");
/* /*
* Acquire CheckpointLock to ensure only one checkpoint happens at a time.
*
* The CheckpointLock can be held for quite a while, which is not good * The CheckpointLock can be held for quite a while, which is not good
* because we won't respond to a cancel/die request while waiting for * because we won't respond to a cancel/die request while waiting for
* an LWLock. (But the alternative of using a regular lock won't work * an LWLock. (But the alternative of using a regular lock won't work
* for background checkpoint processes, which are not regular * for background checkpoint processes, which are not regular
* backends.) So, rather than use a plain LWLockAcquire, use this * backends.) So, rather than use a plain LWLockAcquire, use this
* kluge to allow an interrupt to be accepted while we are waiting: * kluge to allow an interrupt to be accepted while we are waiting:
*/ */
while (!LWLockConditionalAcquire(CheckpointLock, LW_EXCLUSIVE)) while (!LWLockConditionalAcquire(CheckpointLock, LW_EXCLUSIVE))
...@@ -2986,6 +2988,9 @@ CreateCheckPoint(bool shutdown, bool force) ...@@ -2986,6 +2988,9 @@ CreateCheckPoint(bool shutdown, bool force)
sleep(1); sleep(1);
} }
/*
* Use a critical section to force system panic if we have trouble.
*/
START_CRIT_SECTION(); START_CRIT_SECTION();
if (shutdown) if (shutdown)
...@@ -3056,6 +3061,13 @@ CreateCheckPoint(bool shutdown, bool force) ...@@ -3056,6 +3061,13 @@ CreateCheckPoint(bool shutdown, bool force)
/* /*
* Here we update the shared RedoRecPtr for future XLogInsert calls; * Here we update the shared RedoRecPtr for future XLogInsert calls;
* this must be done while holding the insert lock AND the info_lck. * this must be done while holding the insert lock AND the info_lck.
*
* Note: if we fail to complete the checkpoint, RedoRecPtr will be
* left pointing past where it really needs to point. This is okay;
* the only consequence is that XLogInsert might back up whole buffers
* that it didn't really need to. We can't postpone advancing RedoRecPtr
* because XLogInserts that happen while we are dumping buffers must
* assume that their buffer changes are not included in the checkpoint.
*/ */
{ {
/* use volatile pointer to prevent code rearrangement */ /* use volatile pointer to prevent code rearrangement */
...@@ -3094,6 +3106,9 @@ CreateCheckPoint(bool shutdown, bool force) ...@@ -3094,6 +3106,9 @@ CreateCheckPoint(bool shutdown, bool force)
*/ */
LWLockRelease(WALInsertLock); LWLockRelease(WALInsertLock);
/*
* Get the other info we need for the checkpoint record.
*/
LWLockAcquire(XidGenLock, LW_SHARED); LWLockAcquire(XidGenLock, LW_SHARED);
checkPoint.nextXid = ShmemVariableCache->nextXid; checkPoint.nextXid = ShmemVariableCache->nextXid;
LWLockRelease(XidGenLock); LWLockRelease(XidGenLock);
...@@ -3107,10 +3122,18 @@ CreateCheckPoint(bool shutdown, bool force) ...@@ -3107,10 +3122,18 @@ CreateCheckPoint(bool shutdown, bool force)
/* /*
* Having constructed the checkpoint record, ensure all shmem disk * Having constructed the checkpoint record, ensure all shmem disk
* buffers and commit-log buffers are flushed to disk. * buffers and commit-log buffers are flushed to disk.
*
* This I/O could fail for various reasons. If so, we will fail to
* complete the checkpoint, but there is no reason to force a system
* panic. Accordingly, exit critical section while doing it.
*/ */
END_CRIT_SECTION();
CheckPointCLOG(); CheckPointCLOG();
FlushBufferPool(); FlushBufferPool();
START_CRIT_SECTION();
/* /*
* Now insert the checkpoint record into XLOG. * Now insert the checkpoint record into XLOG.
*/ */
...@@ -3166,6 +3189,12 @@ CreateCheckPoint(bool shutdown, bool force) ...@@ -3166,6 +3189,12 @@ CreateCheckPoint(bool shutdown, bool force)
UpdateControlFile(); UpdateControlFile();
LWLockRelease(ControlFileLock); LWLockRelease(ControlFileLock);
/*
* We are now done with critical updates; no need for system panic if
* we have trouble while fooling with offline log segments.
*/
END_CRIT_SECTION();
/* /*
* Delete offline log files (those no longer needed even for previous * Delete offline log files (those no longer needed even for previous
* checkpoint). * checkpoint).
...@@ -3185,8 +3214,6 @@ CreateCheckPoint(bool shutdown, bool force) ...@@ -3185,8 +3214,6 @@ CreateCheckPoint(bool shutdown, bool force)
PreallocXlogFiles(recptr); PreallocXlogFiles(recptr);
LWLockRelease(CheckpointLock); LWLockRelease(CheckpointLock);
END_CRIT_SECTION();
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册