Skip to content

Commit 6eac4e6

Browse files
committed
Tweak BgBufferSync() so that a persistent write error on a dirty buffer
doesn't block the bgwriter from making progress writing out other buffers. This was a hard problem in the context of the ARC/2Q design, but it's trivial in the context of clock sweep ... just advance the sweep counter before we try to write not after.
1 parent 688784f commit 6eac4e6

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.17 2005/06/30 00:00:51 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.18 2005/08/02 20:52:08 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -256,8 +256,7 @@ BackgroundWriterMain(void)
256256
/*
257257
* Sleep at least 1 second after any error. A write error is
258258
* likely to be repeated, and we don't want to be filling the
259-
* error logs as fast as we can. (XXX think about ways to make
260-
* progress when the LRU dirty buffer cannot be written...)
259+
* error logs as fast as we can.
261260
*/
262261
pg_usleep(1000000L);
263262
}

src/backend/storage/buffer/bufmgr.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.189 2005/05/19 21:35:46 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.190 2005/08/02 20:52:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -903,6 +903,11 @@ BgBufferSync(void)
903903
/*
904904
* This loop runs over all buffers, including pinned ones. The
905905
* starting point advances through the buffer pool on successive calls.
906+
*
907+
* Note that we advance the static counter *before* trying to write.
908+
* This ensures that, if we have a persistent write failure on a dirty
909+
* buffer, we'll still be able to make progress writing other buffers.
910+
* (The bgwriter will catch the error and just call us again later.)
906911
*/
907912
if (bgwriter_all_percent > 0.0 && bgwriter_all_maxpages > 0)
908913
{
@@ -911,12 +916,13 @@ BgBufferSync(void)
911916

912917
while (num_to_scan-- > 0)
913918
{
914-
if (SyncOneBuffer(buf_id1, false))
915-
num_written++;
916919
if (++buf_id1 >= NBuffers)
917920
buf_id1 = 0;
918-
if (num_written >= bgwriter_all_maxpages)
919-
break;
921+
if (SyncOneBuffer(buf_id1, false))
922+
{
923+
if (++num_written >= bgwriter_all_maxpages)
924+
break;
925+
}
920926
}
921927
}
922928

@@ -934,11 +940,12 @@ BgBufferSync(void)
934940
while (num_to_scan-- > 0)
935941
{
936942
if (SyncOneBuffer(buf_id2, true))
937-
num_written++;
943+
{
944+
if (++num_written >= bgwriter_lru_maxpages)
945+
break;
946+
}
938947
if (++buf_id2 >= NBuffers)
939948
buf_id2 = 0;
940-
if (num_written >= bgwriter_lru_maxpages)
941-
break;
942949
}
943950
}
944951
}

0 commit comments

Comments
 (0)