Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d18e756

Browse files
committed
Remove CheckpointLock.
Up until now, we've held this lock when performing a checkpoint or restartpoint, but commit 076a055 back in 2004 and commit 7e48b77 from 2009, taken together, have removed all need for this. In the present code, there's only ever one process entitled to attempt a checkpoint: either the checkpointer, during normal operation, or the postmaster, during single-user operation. So, we don't need the lock. One possible concern in making this change is that it means that a substantial amount of code where HOLD_INTERRUPTS() was previously in effect due to the preceding LWLockAcquire() will now be running without that. This could mean that ProcessInterrupts() gets called in places from which it didn't before. However, this seems unlikely to do very much, because the checkpointer doesn't have any signal mapped to die(), so it's not clear how, for example, ProcDiePending = true could happen in the first place. Similarly with ClientConnectionLost and recovery conflicts. Also, if there are any such problems, we might want to fix them rather than reverting this, since running lots of code with interrupt handling suspended is generally bad. Patch by me, per an inquiry by Amul Sul. Review by Tom Lane and Michael Paquier. Discussion: http://postgr.es/m/CAAJ_b97XnBBfYeSREDJorFsyoD1sHgqnNuCi=02mNQBUMnA=FA@mail.gmail.com
1 parent 951862e commit d18e756

File tree

5 files changed

+6
-36
lines changed

5 files changed

+6
-36
lines changed

doc/src/sgml/monitoring.sgml

-4
Original file line numberDiff line numberDiff line change
@@ -1880,10 +1880,6 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
18801880
<entry>Waiting to associate a data block with a buffer in the buffer
18811881
pool.</entry>
18821882
</row>
1883-
<row>
1884-
<entry><literal>Checkpoint</literal></entry>
1885-
<entry>Waiting to begin a checkpoint.</entry>
1886-
</row>
18871883
<row>
18881884
<entry><literal>CheckpointerComm</literal></entry>
18891885
<entry>Waiting to manage fsync requests.</entry>

src/backend/access/heap/rewriteheap.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,8 @@ CheckPointLogicalRewriteHeap(void)
12561256

12571257
/*
12581258
* The file cannot vanish due to concurrency since this function
1259-
* is the only one removing logical mappings and it's run while
1260-
* CheckpointLock is held exclusively.
1259+
* is the only one removing logical mappings and only one
1260+
* checkpoint can be in progress at a time.
12611261
*/
12621262
if (fd < 0)
12631263
ereport(ERROR,

src/backend/access/transam/xlog.c

+1-27
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,6 @@ static XLogRecPtr RedoStartLSN = InvalidXLogRecPtr;
430430
* ControlFileLock: must be held to read/update control file or create
431431
* new log file.
432432
*
433-
* CheckpointLock: must be held to do a checkpoint or restartpoint (ensures
434-
* only one checkpointer at a time; currently, with all checkpoints done by
435-
* the checkpointer, this is just pro forma).
436-
*
437433
*----------
438434
*/
439435

@@ -8864,14 +8860,6 @@ CreateCheckPoint(int flags)
88648860
*/
88658861
InitXLogInsert();
88668862

8867-
/*
8868-
* Acquire CheckpointLock to ensure only one checkpoint happens at a time.
8869-
* (This is just pro forma, since in the present system structure there is
8870-
* only one process that is allowed to issue checkpoints at any given
8871-
* time.)
8872-
*/
8873-
LWLockAcquire(CheckpointLock, LW_EXCLUSIVE);
8874-
88758863
/*
88768864
* Prepare to accumulate statistics.
88778865
*
@@ -8941,7 +8929,6 @@ CreateCheckPoint(int flags)
89418929
if (last_important_lsn == ControlFile->checkPoint)
89428930
{
89438931
WALInsertLockRelease();
8944-
LWLockRelease(CheckpointLock);
89458932
END_CRIT_SECTION();
89468933
ereport(DEBUG1,
89478934
(errmsg("checkpoint skipped because system is idle")));
@@ -9241,15 +9228,12 @@ CreateCheckPoint(int flags)
92419228
CheckpointStats.ckpt_segs_added,
92429229
CheckpointStats.ckpt_segs_removed,
92439230
CheckpointStats.ckpt_segs_recycled);
9244-
9245-
LWLockRelease(CheckpointLock);
92469231
}
92479232

92489233
/*
92499234
* Mark the end of recovery in WAL though without running a full checkpoint.
92509235
* We can expect that a restartpoint is likely to be in progress as we
9251-
* do this, though we are unwilling to wait for it to complete. So be
9252-
* careful to avoid taking the CheckpointLock anywhere here.
9236+
* do this, though we are unwilling to wait for it to complete.
92539237
*
92549238
* CreateRestartPoint() allows for the case where recovery may end before
92559239
* the restartpoint completes so there is no concern of concurrent behaviour.
@@ -9399,12 +9383,6 @@ CreateRestartPoint(int flags)
93999383
XLogSegNo _logSegNo;
94009384
TimestampTz xtime;
94019385

9402-
/*
9403-
* Acquire CheckpointLock to ensure only one restartpoint or checkpoint
9404-
* happens at a time.
9405-
*/
9406-
LWLockAcquire(CheckpointLock, LW_EXCLUSIVE);
9407-
94089386
/* Get a local copy of the last safe checkpoint record. */
94099387
SpinLockAcquire(&XLogCtl->info_lck);
94109388
lastCheckPointRecPtr = XLogCtl->lastCheckPointRecPtr;
@@ -9420,7 +9398,6 @@ CreateRestartPoint(int flags)
94209398
{
94219399
ereport(DEBUG2,
94229400
(errmsg("skipping restartpoint, recovery has already ended")));
9423-
LWLockRelease(CheckpointLock);
94249401
return false;
94259402
}
94269403

@@ -9455,7 +9432,6 @@ CreateRestartPoint(int flags)
94559432
UpdateControlFile();
94569433
LWLockRelease(ControlFileLock);
94579434
}
9458-
LWLockRelease(CheckpointLock);
94599435
return false;
94609436
}
94619437

@@ -9621,8 +9597,6 @@ CreateRestartPoint(int flags)
96219597
xtime ? errdetail("Last completed transaction was at log time %s.",
96229598
timestamptz_to_str(xtime)) : 0));
96239599

9624-
LWLockRelease(CheckpointLock);
9625-
96269600
/*
96279601
* Finally, execute archive_cleanup_command, if any.
96289602
*/

src/backend/replication/logical/origin.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ CheckPointReplicationOrigin(void)
559559
tmppath)));
560560

561561
/*
562-
* no other backend can perform this at the same time, we're protected by
563-
* CheckpointLock.
562+
* no other backend can perform this at the same time; only one
563+
* checkpoint can happen at a time.
564564
*/
565565
tmpfd = OpenTransientFile(tmppath,
566566
O_CREAT | O_EXCL | O_WRONLY | PG_BINARY);

src/backend/storage/lmgr/lwlocknames.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SInvalWriteLock 6
1515
WALBufMappingLock 7
1616
WALWriteLock 8
1717
ControlFileLock 9
18-
CheckpointLock 10
18+
# 10 was CheckpointLock
1919
XactSLRULock 11
2020
SubtransSLRULock 12
2121
MultiXactGenLock 13

0 commit comments

Comments
 (0)