Skip to content

Commit 6f6a6d8

Browse files
committed
Teach RequestCheckpoint() to wait and retry a few times if it can't signal
the bgwriter immediately. This covers the case where the bgwriter is still starting up, as seen in a recent buildfarm failure. In future it might also assist with clean recovery after a bgwriter termination and restart --- right now the postmaster treats early bgwriter exit as a system crash, but that might not always be so.
1 parent 8309d00 commit 6f6a6d8

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 33 additions & 9 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.53 2008/10/14 08:06:39 heikki Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.54 2008/11/23 01:40:19 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -864,6 +864,7 @@ RequestCheckpoint(int flags)
864864
{
865865
/* use volatile pointer to prevent code rearrangement */
866866
volatile BgWriterShmemStruct *bgs = BgWriterShmem;
867+
int ntries;
867868
int old_failed,
868869
old_started;
869870

@@ -905,15 +906,38 @@ RequestCheckpoint(int flags)
905906
SpinLockRelease(&bgs->ckpt_lck);
906907

907908
/*
908-
* Send signal to request checkpoint. When not waiting, we consider
909-
* failure to send the signal to be nonfatal.
909+
* Send signal to request checkpoint. It's possible that the bgwriter
910+
* hasn't started yet, or is in process of restarting, so we will retry
911+
* a few times if needed. Also, if not told to wait for the checkpoint
912+
* to occur, we consider failure to send the signal to be nonfatal and
913+
* merely LOG it.
910914
*/
911-
if (BgWriterShmem->bgwriter_pid == 0)
912-
elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG,
913-
"could not request checkpoint because bgwriter not running");
914-
if (kill(BgWriterShmem->bgwriter_pid, SIGINT) != 0)
915-
elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG,
916-
"could not signal for checkpoint: %m");
915+
for (ntries = 0; ; ntries++)
916+
{
917+
if (BgWriterShmem->bgwriter_pid == 0)
918+
{
919+
if (ntries >= 20) /* max wait 2.0 sec */
920+
{
921+
elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG,
922+
"could not request checkpoint because bgwriter not running");
923+
break;
924+
}
925+
}
926+
else if (kill(BgWriterShmem->bgwriter_pid, SIGINT) != 0)
927+
{
928+
if (ntries >= 20) /* max wait 2.0 sec */
929+
{
930+
elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG,
931+
"could not signal for checkpoint: %m");
932+
break;
933+
}
934+
}
935+
else
936+
break; /* signal sent successfully */
937+
938+
CHECK_FOR_INTERRUPTS();
939+
pg_usleep(100000L); /* wait 0.1 sec, then retry */
940+
}
917941

918942
/*
919943
* If requested, wait for completion. We detect completion according to

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