aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-08-11 04:08:02 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-08-11 04:08:02 +0000
commitd508e0ddd23a35b9cb30ec1a769de40e98d5561f (patch)
tree1880529858bde1f01601074dd3767dc6879cb562 /src/backend/access/transam/xlog.c
parenta1dd58e50990b5a1740371b16a1bd1ccb0721b3e (diff)
downloadpostgresql-d508e0ddd23a35b9cb30ec1a769de40e98d5561f.tar.gz
postgresql-d508e0ddd23a35b9cb30ec1a769de40e98d5561f.zip
Fix failure to guarantee that a checkpoint will write out pg_clog updates
for transaction commits that occurred just before the checkpoint. This is an EXTREMELY serious bug --- kudos to Satoshi Okada for creating a reproducible test case to prove its existence.
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 8eb154f7bab..a8acf758a8c 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.125.2.1 2004/02/23 23:03:43 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.125.2.2 2004/08/11 04:08:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3159,6 +3159,15 @@ CreateCheckPoint(bool shutdown, bool force)
checkPoint.ThisStartUpID = ThisStartUpID;
checkPoint.time = time(NULL);
+ /*
+ * We must hold CheckpointStartLock while determining the checkpoint
+ * REDO pointer. This ensures that any concurrent transaction commits
+ * will be either not yet logged, or logged and recorded in pg_clog.
+ * See notes in RecordTransactionCommit().
+ */
+ LWLockAcquire(CheckpointStartLock, LW_EXCLUSIVE);
+
+ /* And we need WALInsertLock too */
LWLockAcquire(WALInsertLock, LW_EXCLUSIVE);
/*
@@ -3191,6 +3200,7 @@ CreateCheckPoint(bool shutdown, bool force)
ControlFile->checkPointCopy.redo.xrecoff)
{
LWLockRelease(WALInsertLock);
+ LWLockRelease(CheckpointStartLock);
LWLockRelease(CheckpointLock);
END_CRIT_SECTION();
return;
@@ -3258,11 +3268,13 @@ CreateCheckPoint(bool shutdown, bool force)
#endif
/*
- * Now we can release insert lock, allowing other xacts to proceed
- * even while we are flushing disk buffers.
+ * Now we can release insert lock and checkpoint start lock, allowing
+ * other xacts to proceed even while we are flushing disk buffers.
*/
LWLockRelease(WALInsertLock);
+ LWLockRelease(CheckpointStartLock);
+
/*
* Get the other info we need for the checkpoint record.
*/