@ -10,13 +10,13 @@
* fill WAL segments ; the checkpointer itself doesn ' t watch for the
* condition . )
*
* The checkpointer is started by the postmaster as soon as the startup subprocess
* finishes , or as soon as recovery begins if we are doing archive recovery .
* It remains alive until the postmaster commands it to terminate .
* Normal termination is by SIGUSR2 , which instructs the checkpointer to execute
* a shutdown checkpoint and then exit ( 0 ) . ( All backends must be stopped
* before SIGUSR2 is issued ! ) Emergency termination is by SIGQUIT ; like any
* backend , the checkpointer will simply abort and exit on SIGQUIT .
* The checkpointer is started by the postmaster as soon as the startup
* subprocess finishes , or as soon as recovery begins if we are doing archive
* recovery . It remains alive until the postmaster commands it to terminate .
* Normal termination is by SIGUSR2 , which instructs the checkpointer to
* execute a shutdown checkpoint and then exit ( 0 ) . ( All backends must be
* stopped before SIGUSR2 is issued ! ) Emergency termination is by SIGQUIT ;
* like any backend , the checkpointer will simply abort and exit on SIGQUIT .
*
* If the checkpointer exits unexpectedly , the postmaster treats that the same
* as a backend crash : shared memory may be corrupted , so remaining backends
@ -65,8 +65,8 @@
*
* The ckpt counters allow backends to watch for completion of a checkpoint
* request they send . Here ' s how it works :
* * At start of a checkpoint , checkpointer reads ( and clears ) the request flags
* and increments ckpt_started , while holding ckpt_lck .
* * At start of a checkpoint , checkpointer reads ( and clears ) the request
* flags and increments ckpt_started , while holding ckpt_lck .
* * On completion of a checkpoint , checkpointer sets ckpt_done to
* equal ckpt_started .
* * On failure of a checkpoint , checkpointer increments ckpt_failed
@ -95,7 +95,7 @@
* by user backend processes . This counter should be wide enough that it
* can ' t overflow during a single processing cycle . num_backend_fsync
* counts the subset of those writes that also had to do their own fsync ,
* because the background wri ter failed to absorb their request .
* because the checkpoin ter failed to absorb their request .
*
* The requests array holds fsync requests sent by backends and not yet
* absorbed by the checkpointer .
@ -200,8 +200,8 @@ CheckpointerMain(void)
/*
* If possible , make this process a group leader , so that the postmaster
* can signal any child processes too . ( checkpointer probably never has any
* child processes , but for consistency we make all postmaster child
* can signal any child processes too . ( checkpointer probably never has
* any child processes , but for consistency we make all postmaster child
* processes do this . )
*/
# ifdef HAVE_SETSID
@ -216,9 +216,6 @@ CheckpointerMain(void)
* system shutdown cycle , init will SIGTERM all processes at once . We
* want to wait for the backends to exit , whereupon the postmaster will
* tell us it ' s okay to shut down ( via SIGUSR2 ) .
*
* SIGUSR1 is presently unused ; keep it spare in case someday we want this
* process to participate in ProcSignal signalling .
*/
pqsignal ( SIGHUP , ChkptSigHupHandler ) ; /* set flag to read config file */
pqsignal ( SIGINT , ReqCheckpointHandler ) ; /* request checkpoint */
@ -302,12 +299,12 @@ CheckpointerMain(void)
if ( ckpt_active )
{
/* use volatile pointer to prevent code rearrangement */
volatile CheckpointerShmemStruct * bg s = CheckpointerShmem ;
volatile CheckpointerShmemStruct * cp s = CheckpointerShmem ;
SpinLockAcquire ( & bg s- > ckpt_lck ) ;
bg s- > ckpt_failed + + ;
bg s- > ckpt_done = bg s- > ckpt_started ;
SpinLockRelease ( & bg s- > ckpt_lck ) ;
SpinLockAcquire ( & cp s- > ckpt_lck ) ;
cp s- > ckpt_failed + + ;
cp s- > ckpt_done = cp s- > ckpt_started ;
SpinLockRelease ( & cp s- > ckpt_lck ) ;
ckpt_active = false ;
}
@ -455,7 +452,7 @@ CheckpointerMain(void)
bool do_restartpoint ;
/* use volatile pointer to prevent code rearrangement */
volatile CheckpointerShmemStruct * bg s = CheckpointerShmem ;
volatile CheckpointerShmemStruct * cp s = CheckpointerShmem ;
/*
* Check if we should perform a checkpoint or a restartpoint . As a
@ -469,11 +466,11 @@ CheckpointerMain(void)
* checkpoint we should perform , and increase the started - counter
* to acknowledge that we ' ve started a new checkpoint .
*/
SpinLockAcquire ( & bg s- > ckpt_lck ) ;
flags | = bg s- > ckpt_flags ;
bg s- > ckpt_flags = 0 ;
bg s- > ckpt_started + + ;
SpinLockRelease ( & bg s- > ckpt_lck ) ;
SpinLockAcquire ( & cp s- > ckpt_lck ) ;
flags | = cp s- > ckpt_flags ;
cp s- > ckpt_flags = 0 ;
cp s- > ckpt_started + + ;
SpinLockRelease ( & cp s- > ckpt_lck ) ;
/*
* The end - of - recovery checkpoint is a real checkpoint that ' s
@ -528,9 +525,9 @@ CheckpointerMain(void)
/*
* Indicate checkpoint completion to any waiting backends .
*/
SpinLockAcquire ( & bg s- > ckpt_lck ) ;
bg s- > ckpt_done = bg s- > ckpt_started ;
SpinLockRelease ( & bg s- > ckpt_lck ) ;
SpinLockAcquire ( & cp s- > ckpt_lck ) ;
cp s- > ckpt_done = cp s- > ckpt_started ;
SpinLockRelease ( & cp s- > ckpt_lck ) ;
if ( ckpt_performed )
{
@ -559,7 +556,11 @@ CheckpointerMain(void)
CheckArchiveTimeout ( ) ;
/*
* Send off activity statistics to the stats collector
* Send off activity statistics to the stats collector . ( The reason
* why we re - use bgwriter - related code for this is that the bgwriter
* and checkpointer used to be just one process . It ' s probably not
* worth the trouble to split the stats support into two independent
* stats message types . )
*/
pgstat_send_bgwriter ( ) ;
@ -651,13 +652,13 @@ ImmediateCheckpointRequested(void)
{
if ( checkpoint_requested )
{
volatile CheckpointerShmemStruct * bg s = CheckpointerShmem ;
volatile CheckpointerShmemStruct * cp s = CheckpointerShmem ;
/*
* We don ' t need to acquire the ckpt_lck in this case because we ' re
* only looking at a single flag bit .
*/
if ( bg s- > ckpt_flags & CHECKPOINT_IMMEDIATE )
if ( cp s- > ckpt_flags & CHECKPOINT_IMMEDIATE )
return true ;
}
return false ;
@ -698,7 +699,7 @@ CheckpointWriteDelay(int flags, double progress)
{
got_SIGHUP = false ;
ProcessConfigFile ( PGC_SIGHUP ) ;
/* update global shmem state for sync rep */
/* update shmem copies of config variables */
UpdateSharedMemoryConfig ( ) ;
}
@ -708,7 +709,7 @@ CheckpointWriteDelay(int flags, double progress)
CheckArchiveTimeout ( ) ;
/*
* Checkpoint sleep used to be connected to bgwriter_delay a t 200 ms .
* This sleep used to be connected to bgwriter_delay , typically 200 ms .
* That resulted in more frequent wakeups if not much work to do .
* Checkpointer and bgwriter are no longer related so take the Big Sleep .
*/
@ -894,7 +895,7 @@ ReqShutdownHandler(SIGNAL_ARGS)
/*
* CheckpointerShmemSize
* Compute space needed for bgwri ter- related shared memory
* Compute space needed for checkpoin ter- related shared memory
*/
Size
CheckpointerShmemSize ( void )
@ -913,7 +914,7 @@ CheckpointerShmemSize(void)
/*
* CheckpointerShmemInit
* Allocate and initialize bgwri ter- related shared memory
* Allocate and initialize checkpoin ter- related shared memory
*/
void
CheckpointerShmemInit ( void )
@ -921,7 +922,7 @@ CheckpointerShmemInit(void)
bool found ;
CheckpointerShmem = ( CheckpointerShmemStruct * )
ShmemInitStruct ( " Background Wri ter Data" ,
ShmemInitStruct ( " Checkpoin ter Data" ,
CheckpointerShmemSize ( ) ,
& found ) ;
@ -955,7 +956,7 @@ void
RequestCheckpoint ( int flags )
{
/* use volatile pointer to prevent code rearrangement */
volatile CheckpointerShmemStruct * bg s = CheckpointerShmem ;
volatile CheckpointerShmemStruct * cp s = CheckpointerShmem ;
int ntries ;
int old_failed ,
old_started ;
@ -989,13 +990,13 @@ RequestCheckpoint(int flags)
* a " stronger " request by another backend . The flag senses must be
* chosen to make this work !
*/
SpinLockAcquire ( & bg s- > ckpt_lck ) ;
SpinLockAcquire ( & cp s- > ckpt_lck ) ;
old_failed = bg s- > ckpt_failed ;
old_started = bg s- > ckpt_started ;
bg s- > ckpt_flags | = flags ;
old_failed = cp s- > ckpt_failed ;
old_started = cp s- > ckpt_started ;
cp s- > ckpt_flags | = flags ;
SpinLockRelease ( & bg s- > ckpt_lck ) ;
SpinLockRelease ( & cp s- > ckpt_lck ) ;
/*
* Send signal to request checkpoint . It ' s possible that the checkpointer
@ -1043,9 +1044,9 @@ RequestCheckpoint(int flags)
/* Wait for a new checkpoint to start. */
for ( ; ; )
{
SpinLockAcquire ( & bg s- > ckpt_lck ) ;
new_started = bg s- > ckpt_started ;
SpinLockRelease ( & bg s- > ckpt_lck ) ;
SpinLockAcquire ( & cp s- > ckpt_lck ) ;
new_started = cp s- > ckpt_started ;
SpinLockRelease ( & cp s- > ckpt_lck ) ;
if ( new_started ! = old_started )
break ;
@ -1061,10 +1062,10 @@ RequestCheckpoint(int flags)
{
int new_done ;
SpinLockAcquire ( & bg s- > ckpt_lck ) ;
new_done = bg s- > ckpt_done ;
new_failed = bg s- > ckpt_failed ;
SpinLockRelease ( & bg s- > ckpt_lck ) ;
SpinLockAcquire ( & cp s- > ckpt_lck ) ;
new_done = cp s- > ckpt_done ;
new_failed = cp s- > ckpt_failed ;
SpinLockRelease ( & cp s- > ckpt_lck ) ;
if ( new_done - new_started > = 0 )
break ;
@ -1178,7 +1179,7 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,
static bool
CompactCheckpointerRequestQueue ( void )
{
struct BgWri terSlotMapping
struct Checkpoin terSlotMapping
{
CheckpointerRequest request ;
int slot ;
@ -1197,7 +1198,7 @@ CompactCheckpointerRequestQueue(void)
/* Initialize temporary hash table */
MemSet ( & ctl , 0 , sizeof ( ctl ) ) ;
ctl . keysize = sizeof ( CheckpointerRequest ) ;
ctl . entrysize = sizeof ( struct BgWri terSlotMapping) ;
ctl . entrysize = sizeof ( struct Checkpoin terSlotMapping) ;
ctl . hash = tag_hash ;
htab = hash_create ( " CompactCheckpointerRequestQueue " ,
CheckpointerShmem - > num_requests ,
@ -1223,7 +1224,7 @@ CompactCheckpointerRequestQueue(void)
for ( n = 0 ; n < CheckpointerShmem - > num_requests ; + + n )
{
CheckpointerRequest * request ;
struct BgWri terSlotMapping * slotmap ;
struct Checkpoin terSlotMapping * slotmap ;
bool found ;
request = & CheckpointerShmem - > requests [ n ] ;