Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4d271e3

Browse files
committed
checkpointer: Request checkpoint via latch instead of signal
The motivation for this change is that a future commit will use SIGINT foranother purpose (postmaster requesting WAL access to be shut down) and thatthere no other signals that we could readily use (see code comment for thereason why SIGTERM shouldn't be used). But it's also a tad nicer / moreefficient to use SetLatch(), as it avoids sending signals when checkpointeralready is busy.Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>Discussion:https://postgr.es/m/kgng5nrvnlv335evmsuvpnh354rw7qyazl73kdysev2cr2v5zu@m3cfzxicm5kp
1 parenta5579a9 commit4d271e3

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

‎src/backend/postmaster/checkpointer.c

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ static bool ImmediateCheckpointRequested(void);
159159
staticboolCompactCheckpointerRequestQueue(void);
160160
staticvoidUpdateSharedMemoryConfig(void);
161161

162-
/* Signal handlers */
163-
staticvoidReqCheckpointHandler(SIGNAL_ARGS);
164-
165162

166163
/*
167164
* Main entry point for checkpointer process
@@ -191,7 +188,7 @@ CheckpointerMain(char *startup_data, size_t startup_data_len)
191188
* tell us it's okay to shut down (via SIGUSR2).
192189
*/
193190
pqsignal(SIGHUP,SignalHandlerForConfigReload);
194-
pqsignal(SIGINT,ReqCheckpointHandler);/* request checkpoint */
191+
pqsignal(SIGINT,SIG_IGN);
195192
pqsignal(SIGTERM,SIG_IGN);/* ignore SIGTERM */
196193
/* SIGQUIT handler was already set up by InitPostmasterChild */
197194
pqsignal(SIGALRM,SIG_IGN);
@@ -860,23 +857,6 @@ IsCheckpointOnSchedule(double progress)
860857
}
861858

862859

863-
/* --------------------------------
864-
*signal handler routines
865-
* --------------------------------
866-
*/
867-
868-
/* SIGINT: set flag to run a normal checkpoint right away */
869-
staticvoid
870-
ReqCheckpointHandler(SIGNAL_ARGS)
871-
{
872-
/*
873-
* The signaling process should have set ckpt_flags nonzero, so all we
874-
* need do is ensure that our main loop gets kicked out of any wait.
875-
*/
876-
SetLatch(MyLatch);
877-
}
878-
879-
880860
/* --------------------------------
881861
*communication with backends
882862
* --------------------------------
@@ -990,38 +970,36 @@ RequestCheckpoint(int flags)
990970
SpinLockRelease(&CheckpointerShmem->ckpt_lck);
991971

992972
/*
993-
*Send signalto request checkpoint. It's possible that the checkpointer
994-
* hasn't started yet,or is in process of restarting,so we will retry a
995-
*few times ifneeded. (Actually, more than a few times, since on slow
996-
*or overloadedbuildfarm machines, it's been observed that the
997-
*checkpointer can takeseveral seconds to start.) However, if not told
998-
*to wait for thecheckpoint to occur, we consider failure tosend the
999-
*signal to benonfatal and merely LOG it. The checkpointer should see
1000-
*the requestwhen it does start, with or withoutgetting a signal.
973+
*Set checkpointer's latchto request checkpoint. It's possible that the
974+
*checkpointerhasn't started yet, so we will retry a few times if
975+
* needed. (Actually, more than a few times, since on slow or overloaded
976+
* buildfarm machines, it's been observed that the checkpointer can take
977+
* several seconds to start.) However, if not told to wait for the
978+
* checkpoint to occur, we consider failure toset the latch to be
979+
* nonfatal and merely LOG it. The checkpointer should see the request
980+
* when it does start, with or withoutthe SetLatch().
1001981
*/
1002982
#defineMAX_SIGNAL_TRIES 600/* max wait 60.0 sec */
1003983
for (ntries=0;;ntries++)
1004984
{
1005-
if (CheckpointerShmem->checkpointer_pid==0)
985+
volatilePROC_HDR*procglobal=ProcGlobal;
986+
ProcNumbercheckpointerProc=procglobal->checkpointerProc;
987+
988+
if (checkpointerProc==INVALID_PROC_NUMBER)
1006989
{
1007990
if (ntries >=MAX_SIGNAL_TRIES|| !(flags&CHECKPOINT_WAIT))
1008991
{
1009992
elog((flags&CHECKPOINT_WAIT) ?ERROR :LOG,
1010-
"could notsignal for checkpoint: checkpointer is not running");
993+
"could notnotify checkpoint: checkpointer is not running");
1011994
break;
1012995
}
1013996
}
1014-
elseif (kill(CheckpointerShmem->checkpointer_pid,SIGINT)!=0)
997+
else
1015998
{
1016-
if (ntries >=MAX_SIGNAL_TRIES|| !(flags&CHECKPOINT_WAIT))
1017-
{
1018-
elog((flags&CHECKPOINT_WAIT) ?ERROR :LOG,
1019-
"could not signal for checkpoint: %m");
1020-
break;
1021-
}
999+
SetLatch(&GetPGProcByNumber(checkpointerProc)->procLatch);
1000+
/* notified successfully */
1001+
break;
10221002
}
1023-
else
1024-
break;/* signal sent successfully */
10251003

10261004
CHECK_FOR_INTERRUPTS();
10271005
pg_usleep(100000L);/* wait 0.1 sec, then retry */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp