From a48695251e145e2691a1217d971ab7e9bbcb6de3 Mon Sep 17 00:00:00 2001 From: Takashi Menjo Date: Mon, 16 Mar 2020 11:13:59 +0900 Subject: [PATCH v3 02/10] Preallocate more WAL segments --- src/backend/access/transam/xlog.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 43fe60405e..5bf79e1d8c 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -926,7 +926,7 @@ static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, bool fetching_ckpt, XLogRecPtr tliRecPtr); static int emode_for_corrupt_record(int emode, XLogRecPtr RecPtr); static void XLogFileClose(void); -static void PreallocXlogFiles(XLogRecPtr endptr); +static void PreallocXlogFiles(XLogRecPtr RedoRecPtr, XLogRecPtr endptr); static void RemoveTempXlogFiles(void); static void RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr lastredoptr, XLogRecPtr endptr); static void RemoveXlogFile(const char *segname, XLogSegNo recycleSegNo, @@ -3895,27 +3895,20 @@ XLogFileClose(void) /* * Preallocate log files beyond the specified log endpoint. - * - * XXX this is currently extremely conservative, since it forces only one - * future log segment to exist, and even that only if we are 75% done with - * the current one. This is only appropriate for very low-WAL-volume systems. - * High-volume systems will be OK once they've built up a sufficient set of - * recycled log segments, but the startup transient is likely to include - * a lot of segment creations by foreground processes, which is not so good. */ static void -PreallocXlogFiles(XLogRecPtr endptr) +PreallocXlogFiles(XLogRecPtr RedoRecPtr, XLogRecPtr endptr) { XLogSegNo _logSegNo; + XLogSegNo endSegNo; + XLogSegNo recycleSegNo; int lf; bool use_existent; - uint64 offset; - XLByteToPrevSeg(endptr, _logSegNo, wal_segment_size); - offset = XLogSegmentOffset(endptr - 1, wal_segment_size); - if (offset >= (uint32) (0.75 * wal_segment_size)) + XLByteToPrevSeg(endptr, endSegNo, wal_segment_size); + recycleSegNo = XLOGfileslop(RedoRecPtr); + for (_logSegNo = endSegNo + 1; _logSegNo <= recycleSegNo; _logSegNo++) { - _logSegNo++; use_existent = true; lf = XLogFileInit(_logSegNo, &use_existent, true); close(lf); @@ -7915,7 +7908,7 @@ StartupXLOG(void) /* * Preallocate additional log files, if wanted. */ - PreallocXlogFiles(EndOfLog); + PreallocXlogFiles(RedoRecPtr, EndOfLog); /* * Okay, we're officially UP. @@ -9202,7 +9195,7 @@ CreateCheckPoint(int flags) * segments, since that may supply some of the needed files.) */ if (!shutdown) - PreallocXlogFiles(recptr); + PreallocXlogFiles(RedoRecPtr, recptr); /* * Truncate pg_subtrans if possible. We can throw away all data before @@ -9571,7 +9564,7 @@ CreateRestartPoint(int flags) * Make more log segments if needed. (Do this after recycling old log * segments, since that may supply some of the needed files.) */ - PreallocXlogFiles(endptr); + PreallocXlogFiles(RedoRecPtr, endptr); /* * ThisTimeLineID is normally not set when we're still in recovery. -- 2.25.1