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

Commitebdf5bf

Browse files
committed
Delay updating control file to "in production"
Move the updating of the control file to "in production" status untilthe point where WAL writes are allowed. Before, there could be asignificant gap between the control file update and write transactionsactually being allowed. This makes it more reliable to use the controlstatus to verify the end of a promotion.From: Michael Paquier <michael.paquier@gmail.com>
1 parentc1dc51d commitebdf5bf

File tree

1 file changed

+21
-10
lines changed
  • src/backend/access/transam

1 file changed

+21
-10
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7431,12 +7431,6 @@ StartupXLOG(void)
74317431
*/
74327432
InRecovery= false;
74337433

7434-
LWLockAcquire(ControlFileLock,LW_EXCLUSIVE);
7435-
ControlFile->state=DB_IN_PRODUCTION;
7436-
ControlFile->time= (pg_time_t)time(NULL);
7437-
UpdateControlFile();
7438-
LWLockRelease(ControlFileLock);
7439-
74407434
/* start the archive_timeout timer running */
74417435
XLogCtl->lastSegSwitchTime= (pg_time_t)time(NULL);
74427436

@@ -7494,15 +7488,32 @@ StartupXLOG(void)
74947488
CompleteCommitTsInitialization();
74957489

74967490
/*
7497-
* All done. Allow backends to write WAL. (Although the bool flag is
7498-
* probably atomic in itself, we use the info_lck here to ensure that
7499-
* there are no race conditions concerning visibility of other recent
7500-
* updates to shared memory.)
7491+
* All done with end-of-recovery actions.
7492+
*
7493+
* Now allow backends to write WAL and update the control file status in
7494+
* consequence. The boolean flag allowing backends to write WAL is
7495+
* updated while holding ControlFileLock to prevent other backends to look
7496+
* at an inconsistent state of the control file in shared memory. There
7497+
* is still a small window during which backends can write WAL and the
7498+
* control file is still referring to a system not in DB_IN_PRODUCTION
7499+
* state while looking at the on-disk control file.
7500+
*
7501+
* Also, although the boolean flag to allow WAL is probably atomic in
7502+
* itself, we use the info_lck here to ensure that there are no race
7503+
* conditions concerning visibility of other recent updates to shared
7504+
* memory.
75017505
*/
7506+
LWLockAcquire(ControlFileLock,LW_EXCLUSIVE);
7507+
ControlFile->state=DB_IN_PRODUCTION;
7508+
ControlFile->time= (pg_time_t)time(NULL);
7509+
75027510
SpinLockAcquire(&XLogCtl->info_lck);
75037511
XLogCtl->SharedRecoveryInProgress= false;
75047512
SpinLockRelease(&XLogCtl->info_lck);
75057513

7514+
UpdateControlFile();
7515+
LWLockRelease(ControlFileLock);
7516+
75067517
/*
75077518
* If there were cascading standby servers connected to us, nudge any wal
75087519
* sender processes to notice that we've been promoted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp