Skip to content

Commit e51c469

Browse files
committed
Move InitXLogInsert() call from InitXLOGAccess() to BaseInit().
At present, there is an undocumented coding rule that you must call RecoveryInProgress(), or do something else that results in a call to InitXLogInsert(), before trying to write WAL. Otherwise, the WAL construction buffers won't be initialized, resulting in failures. Since it's not good to rely on a status inquiry function like RecoveryInProgress() having the side effect of initializing critical data structures, instead do the initialization eariler, when the backend first starts up. Patch by me. Reviewed by Nathan Bossart and Michael Paquier. Discussion: http://postgr.es/m/CA+TgmoY7b65qRjzHN_tWUk8B4sJqk1vj1d31uepVzmgPnZKeLg@mail.gmail.com
1 parent 354a1f8 commit e51c469

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/backend/access/transam/xlog.c

-13
Original file line numberDiff line numberDiff line change
@@ -8677,9 +8677,6 @@ InitXLOGAccess(void)
86778677
(void) GetRedoRecPtr();
86788678
/* Also update our copy of doPageWrites. */
86798679
doPageWrites = (Insert->fullPageWrites || Insert->forcePageWrites);
8680-
8681-
/* Also initialize the working areas for constructing WAL records */
8682-
InitXLogInsert();
86838680
}
86848681

86858682
/*
@@ -9129,16 +9126,6 @@ CreateCheckPoint(int flags)
91299126
if (RecoveryInProgress() && (flags & CHECKPOINT_END_OF_RECOVERY) == 0)
91309127
elog(ERROR, "can't create a checkpoint during recovery");
91319128

9132-
/*
9133-
* Initialize InitXLogInsert working areas before entering the critical
9134-
* section. Normally, this is done by the first call to
9135-
* RecoveryInProgress() or LocalSetXLogInsertAllowed(), but when creating
9136-
* an end-of-recovery checkpoint, the LocalSetXLogInsertAllowed call is
9137-
* done below in a critical section, and InitXLogInsert cannot be called
9138-
* in a critical section.
9139-
*/
9140-
InitXLogInsert();
9141-
91429129
/*
91439130
* Prepare to accumulate statistics.
91449131
*

src/backend/utils/init/postinit.c

+6
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@ BaseInit(void)
541541
* file shutdown hook can report temporary file statistics.
542542
*/
543543
InitTemporaryFileAccess();
544+
545+
/*
546+
* Initialize local buffers for WAL record construction, in case we
547+
* ever try to insert XLOG.
548+
*/
549+
InitXLogInsert();
544550
}
545551

546552

0 commit comments

Comments
 (0)