From 83aaebba63a51cf2207b69e89ead767f3a82ce88 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 3 Jul 2007 14:51:24 +0000
Subject: [PATCH] Fix incorrect comment about the timing of
 AbsorbFsyncRequests() during checkpoint.  The comment claimed that we could
 do this anytime after setting the checkpoint REDO point, but actually
 BufferSync is relying on the assumption that buffers dumped by other backends
 will be fsync'd too.  So we really could not do it any sooner than we are
 doing it.

---
 src/backend/postmaster/bgwriter.c |  8 ++++----
 src/backend/storage/smgr/md.c     | 11 +++++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c
index a4d758d536a..d8c7c3aa13b 100644
--- a/src/backend/postmaster/bgwriter.c
+++ b/src/backend/postmaster/bgwriter.c
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.40 2007/06/30 19:12:01 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.41 2007/07/03 14:51:24 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1007,9 +1007,9 @@ ForwardFsyncRequest(RelFileNode rnode, BlockNumber segno)
  *		Retrieve queued fsync requests and pass them to local smgr.
  *
  * This is exported because it must be called during CreateCheckPoint;
- * we have to be sure we have accepted all pending requests *after* we
- * establish the checkpoint REDO pointer.  Since CreateCheckPoint
- * sometimes runs in non-bgwriter processes, do nothing if not bgwriter.
+ * we have to be sure we have accepted all pending requests just before
+ * we start fsync'ing.  Since CreateCheckPoint sometimes runs in
+ * non-bgwriter processes, do nothing if not bgwriter.
  */
 void
 AbsorbFsyncRequests(void)
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 3ac3e8f4e73..251811421e0 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.128 2007/04/12 17:10:55 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.129 2007/07/03 14:51:24 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -880,9 +880,12 @@ mdsync(void)
 
 	/*
 	 * If we are in the bgwriter, the sync had better include all fsync
-	 * requests that were queued by backends before the checkpoint REDO
-	 * point was determined.  We go that a little better by accepting all
-	 * requests queued up to the point where we start fsync'ing.
+	 * requests that were queued by backends up to this point.  The tightest
+	 * race condition that could occur is that a buffer that must be written
+	 * and fsync'd for the checkpoint could have been dumped by a backend
+	 * just before it was visited by BufferSync().  We know the backend will
+	 * have queued an fsync request before clearing the buffer's dirtybit,
+	 * so we are safe as long as we do an Absorb after completing BufferSync().
 	 */
 	AbsorbFsyncRequests();
 
-- 
GitLab