Skip to content

Commit 076a055

Browse files
committed
Separate out bgwriter code into a logically separate module, rather
than being random pieces of other files. Give bgwriter responsibility for all checkpoint activity (other than a post-recovery checkpoint); so this child process absorbs the functionality of the former transient checkpoint and shutdown subprocesses. While at it, create an actual include file for postmaster.c, which for some reason never had its own file before.
1 parent d531fd2 commit 076a055

File tree

28 files changed

+1126
-895
lines changed

28 files changed

+1126
-895
lines changed

src/backend/access/transam/slru.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.14 2004/05/28 05:12:42 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.15 2004/05/29 22:48:18 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,6 +17,7 @@
1717
#include <unistd.h>
1818

1919
#include "access/slru.h"
20+
#include "postmaster/bgwriter.h"
2021
#include "storage/fd.h"
2122
#include "storage/lwlock.h"
2223
#include "miscadmin.h"
@@ -795,8 +796,8 @@ SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
795796
if (!SlruScanDirectory(ctl, cutoffPage, false))
796797
return; /* nothing to remove */
797798

798-
/* Perform a forced CHECKPOINT */
799-
CreateCheckPoint(false, true);
799+
/* Perform a CHECKPOINT */
800+
RequestCheckpoint(true);
800801

801802
/*
802803
* Scan shared memory and remove any pages preceding the cutoff page,

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.144 2004/05/28 05:12:42 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.145 2004/05/29 22:48:18 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,10 +27,10 @@
2727
#include "access/xlogutils.h"
2828
#include "catalog/catversion.h"
2929
#include "catalog/pg_control.h"
30+
#include "postmaster/bgwriter.h"
3031
#include "storage/bufpage.h"
3132
#include "storage/fd.h"
3233
#include "storage/lwlock.h"
33-
#include "storage/pmsignal.h"
3434
#include "storage/proc.h"
3535
#include "storage/sinval.h"
3636
#include "storage/spin.h"
@@ -1206,9 +1206,9 @@ XLogWrite(XLogwrtRqst WriteRqst)
12061206
{
12071207
#ifdef WAL_DEBUG
12081208
if (XLOG_DEBUG)
1209-
elog(LOG, "time for a checkpoint, signaling postmaster");
1209+
elog(LOG, "time for a checkpoint, signaling bgwriter");
12101210
#endif
1211-
SendPostmasterSignal(PMSIGNAL_DO_CHECKPOINT);
1211+
RequestCheckpoint(false);
12121212
}
12131213
}
12141214
LWLockRelease(ControlFileLock);
@@ -3087,11 +3087,6 @@ StartupXLOG(void)
30873087
RmgrTable[rmid].rm_cleanup();
30883088
}
30893089

3090-
/* suppress in-transaction check in CreateCheckPoint */
3091-
MyLastRecPtr.xrecoff = 0;
3092-
MyXactMadeXLogEntry = false;
3093-
MyXactMadeTempRelUpdate = false;
3094-
30953090
/*
30963091
* At this point, ThisStartUpID is the largest SUI that we could
30973092
* find evidence for in the WAL entries. But check it against
@@ -3293,11 +3288,6 @@ ShutdownXLOG(int code, Datum arg)
32933288
ereport(LOG,
32943289
(errmsg("shutting down")));
32953290

3296-
/* suppress in-transaction check in CreateCheckPoint */
3297-
MyLastRecPtr.xrecoff = 0;
3298-
MyXactMadeXLogEntry = false;
3299-
MyXactMadeTempRelUpdate = false;
3300-
33013291
CritSectionCount++;
33023292
CreateCheckPoint(true, true);
33033293
ShutdownCLOG();
@@ -3324,27 +3314,13 @@ CreateCheckPoint(bool shutdown, bool force)
33243314
uint32 _logId;
33253315
uint32 _logSeg;
33263316

3327-
if (MyXactMadeXLogEntry)
3328-
ereport(ERROR,
3329-
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3330-
errmsg("checkpoint cannot be made inside transaction block")));
3331-
33323317
/*
33333318
* Acquire CheckpointLock to ensure only one checkpoint happens at a
3334-
* time.
3335-
*
3336-
* The CheckpointLock can be held for quite a while, which is not good
3337-
* because we won't respond to a cancel/die request while waiting for
3338-
* an LWLock. (But the alternative of using a regular lock won't work
3339-
* for background checkpoint processes, which are not regular
3340-
* backends.) So, rather than use a plain LWLockAcquire, use this
3341-
* kluge to allow an interrupt to be accepted while we are waiting:
3319+
* time. (This is just pro forma, since in the present system
3320+
* structure there is only one process that is allowed to issue
3321+
* checkpoints at any given time.)
33423322
*/
3343-
while (!LWLockConditionalAcquire(CheckpointLock, LW_EXCLUSIVE))
3344-
{
3345-
CHECK_FOR_INTERRUPTS();
3346-
pg_usleep(1000000L);
3347-
}
3323+
LWLockAcquire(CheckpointLock, LW_EXCLUSIVE);
33483324

33493325
/*
33503326
* Use a critical section to force system panic if we have trouble.

0 commit comments

Comments
 (0)