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

Commitbce7bac

Browse files
committed
Reduce the maximum sleep interval in the autovac launcher to 1 second,
so that it responds to SIGQUIT reasonably promptly even on machines whereSA_RESTART signals restart a sleep from scratch. (This whole area couldstand some rethinking, but for now make it work like the other processesdo.) Also some marginal stylistic cleanups.
1 parent421d502 commitbce7bac

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

‎src/backend/postmaster/autovacuum.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.54 2007/07/0102:20:59 tgl Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.55 2007/07/0118:30:54 tgl Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -99,10 +99,6 @@
9999
#include"utils/syscache.h"
100100

101101

102-
staticvolatilesig_atomic_tgot_SIGUSR1= false;
103-
staticvolatilesig_atomic_tgot_SIGHUP= false;
104-
staticvolatilesig_atomic_tavlauncher_shutdown_request= false;
105-
106102
/*
107103
* GUC parameters
108104
*/
@@ -121,13 +117,15 @@ intautovacuum_vac_cost_limit;
121117
intLog_autovacuum=-1;
122118

123119

124-
/* maximum sleep duration in the launcher, in seconds */
125-
#defineAV_SLEEP_QUANTUM 10
126-
127120
/* Flags to tell if we are in an autovacuum process */
128121
staticboolam_autovacuum_launcher= false;
129122
staticboolam_autovacuum_worker= false;
130123

124+
/* Flags set by signal handlers */
125+
staticvolatilesig_atomic_tgot_SIGHUP= false;
126+
staticvolatilesig_atomic_tgot_SIGUSR1= false;
127+
staticvolatilesig_atomic_tgot_SIGTERM= false;
128+
131129
/* Comparison point for determining whether freeze_max_age is exceeded */
132130
staticTransactionIdrecentXid;
133131

@@ -291,7 +289,7 @@ static PgStat_StatTabEntry *get_pgstat_tabentry_relid(Oid relid, bool isshared,
291289
staticvoidautovac_report_activity(VacuumStmt*vacstmt,Oidrelid);
292290
staticvoidavl_sighup_handler(SIGNAL_ARGS);
293291
staticvoidavl_sigusr1_handler(SIGNAL_ARGS);
294-
staticvoidavlauncher_shutdown(SIGNAL_ARGS);
292+
staticvoidavl_sigterm_handler(SIGNAL_ARGS);
295293
staticvoidavl_quickdie(SIGNAL_ARGS);
296294

297295

@@ -411,7 +409,7 @@ AutoVacLauncherMain(int argc, char *argv[])
411409
pqsignal(SIGHUP,avl_sighup_handler);
412410

413411
pqsignal(SIGINT,SIG_IGN);
414-
pqsignal(SIGTERM,avlauncher_shutdown);
412+
pqsignal(SIGTERM,avl_sigterm_handler);
415413
pqsignal(SIGQUIT,avl_quickdie);
416414
pqsignal(SIGALRM,SIG_IGN);
417415

@@ -544,23 +542,27 @@ AutoVacLauncherMain(int argc, char *argv[])
544542
INVALID_OFFSET, false,&nap);
545543

546544
/*
547-
* Sleep for a while according to schedule. We only sleep in
548-
* AV_SLEEP_QUANTUM second intervals, in order to promptly notice
549-
* postmaster death.
545+
* Sleep for a while according to schedule.
546+
*
547+
* On some platforms, signals won't interrupt the sleep. To ensure we
548+
* respond reasonably promptly when someone signals us, break down the
549+
* sleep into 1-second increments, and check for interrupts after each
550+
* nap.
550551
*/
551552
while (nap.tv_sec>0||nap.tv_usec>0)
552553
{
553554
uint32sleeptime;
554555

555-
sleeptime=nap.tv_usec;
556-
nap.tv_usec=0;
557-
558556
if (nap.tv_sec>0)
559557
{
560-
sleeptime+=Min(nap.tv_sec,AV_SLEEP_QUANTUM)*1000000;
561-
nap.tv_sec-=Min(nap.tv_sec,AV_SLEEP_QUANTUM);
558+
sleeptime=1000000;
559+
nap.tv_sec--;
560+
}
561+
else
562+
{
563+
sleeptime=nap.tv_usec;
564+
nap.tv_usec=0;
562565
}
563-
564566
pg_usleep(sleeptime);
565567

566568
/*
@@ -570,12 +572,12 @@ AutoVacLauncherMain(int argc, char *argv[])
570572
if (!PostmasterIsAlive(true))
571573
exit(1);
572574

573-
if (avlauncher_shutdown_request||got_SIGHUP||got_SIGUSR1)
575+
if (got_SIGTERM||got_SIGHUP||got_SIGUSR1)
574576
break;
575577
}
576578

577579
/* the normal shutdown case */
578-
if (avlauncher_shutdown_request)
580+
if (got_SIGTERM)
579581
break;
580582

581583
if (got_SIGHUP)
@@ -788,17 +790,17 @@ launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval *nap)
788790
* We only recurse once. rebuild_database_list should always return times
789791
* in the future, but it seems best not to trust too much on that.
790792
*/
791-
if (nap->tv_sec==0L&&nap->tv_usec==0&& !recursing)
793+
if (nap->tv_sec==0&&nap->tv_usec==0&& !recursing)
792794
{
793795
rebuild_database_list(InvalidOid);
794796
launcher_determine_sleep(canlaunch, true,nap);
795797
return;
796798
}
797799

798800
/* 100ms is the smallest time we'll allow the launcher to sleep */
799-
if (nap->tv_sec <=0L&&nap->tv_usec <=100000)
801+
if (nap->tv_sec <=0&&nap->tv_usec <=100000)
800802
{
801-
nap->tv_sec=0L;
803+
nap->tv_sec=0;
802804
nap->tv_usec=100000;/* 100 ms */
803805
}
804806
}
@@ -1276,10 +1278,11 @@ avl_sigusr1_handler(SIGNAL_ARGS)
12761278
got_SIGUSR1= true;
12771279
}
12781280

1281+
/* SIGTERM: time to die */
12791282
staticvoid
1280-
avlauncher_shutdown(SIGNAL_ARGS)
1283+
avl_sigterm_handler(SIGNAL_ARGS)
12811284
{
1282-
avlauncher_shutdown_request= true;
1285+
got_SIGTERM= true;
12831286
}
12841287

12851288
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp