diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 2c2be96c3..08ed674aa 100755 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -2647,6 +2647,7 @@ static void XLogWrite(const XLogwrtRqst &WriteRqst, bool flexible) bool last_iteration = false; bool finishing_seg = false; bool use_existent = false; + bool segs_enough = true; int curridx = 0; int npages = 0; int startidx = 0; @@ -2716,12 +2717,19 @@ static void XLogWrite(const XLogwrtRqst &WriteRqst, bool flexible) t_thrd.xlog_cxt.openLogFile = XLogFileInit(t_thrd.xlog_cxt.openLogSegNo, &use_existent, true); t_thrd.xlog_cxt.openLogOff = 0; + segs_enough = true; + if (g_instance.attr.attr_storage.wal_file_init_num > 0 && g_instance.wal_cxt.globalEndPosSegNo != InvalidXLogSegPtr && + g_instance.wal_cxt.globalEndPosSegNo >= t_thrd.xlog_cxt.openLogSegNo) { + segs_enough = (g_instance.wal_cxt.globalEndPosSegNo - t_thrd.xlog_cxt.openLogSegNo) + > (g_instance.attr.attr_storage.wal_file_init_num * 0.2); + } + /* * Unlock WalAuxiliary thread to init new xlog segment if we are running out - * of xlog segments. + * of xlog segments, or available segments is less than wal_file_init_num * 0.2. */ - if (!use_existent) { - g_instance.wal_cxt.globalEndPosSegNo = t_thrd.xlog_cxt.openLogSegNo; + if (!use_existent || !segs_enough) { + g_instance.wal_cxt.globalEndPosSegNo = Max(g_instance.wal_cxt.globalEndPosSegNo, t_thrd.xlog_cxt.openLogSegNo); WakeupWalSemaphore(&g_instance.wal_cxt.walInitSegLock->l.sem); } } @@ -4242,7 +4250,7 @@ bool PreInitXlogFileForStandby(XLogRecPtr requestLsn) return true; } -void PreInitXlogFileForPrimary(int advance_xlog_file_num) +void PreInitXlogFileForPrimary(int wal_file_init_num) { XLogSegNo startSegNo, nextSegNo, target; int lf; @@ -4254,7 +4262,7 @@ void PreInitXlogFileForPrimary(int advance_xlog_file_num) return; } startSegNo = g_instance.wal_cxt.globalEndPosSegNo + 1; - target = startSegNo + advance_xlog_file_num - 1; + target = startSegNo + wal_file_init_num - 1; for (nextSegNo = startSegNo; nextSegNo <= target; nextSegNo++) { use_existent = true; lf = XLogFileInit(nextSegNo, &use_existent, true); @@ -4496,6 +4504,10 @@ static bool InstallXLogFileSegment(XLogSegNo *segno, const char *tmppath, bool f return false; } + if (*segno > g_instance.wal_cxt.globalEndPosSegNo) { + g_instance.wal_cxt.globalEndPosSegNo = *segno; + } + if (use_lock) { LWLockRelease(ControlFileLock); } diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index fa5931dc1..5284da1b9 100755 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -361,7 +361,6 @@ typedef struct XLogwrtResult { XLogRecPtr Flush; /* last byte + 1 flushed */ } XLogwrtResult; -extern void XLogMultiFileInit(int advance_xlog_file_num); typedef struct XLogwrtPaxos { XLogRecPtr Write; /* last byte + 1 written out */ XLogRecPtr Consensus; /* last byte + 1 consensus in DCF */ @@ -708,8 +707,6 @@ extern XLogSegNo GetNewestXLOGSegNo(const char* workingPath); #define XLOG_CONTAIN_CSN 0x80000000 #define XLOG_MASK_TERM 0x7FFFFFFF -extern void XLogMultiFileInit(int advance_xlog_file_num); - extern XLogRecPtr XLogInsertRecord(struct XLogRecData* rdata, XLogRecPtr fpw_lsn); extern void XLogWaitFlush(XLogRecPtr recptr); extern void XLogWaitBufferInit(XLogRecPtr recptr); @@ -719,7 +716,7 @@ extern bool XLogNeedsFlush(XLogRecPtr RecPtr); extern int XLogFileInit(XLogSegNo segno, bool* use_existent, bool use_lock); extern int XLogFileOpen(XLogSegNo segno); extern bool PreInitXlogFileForStandby(XLogRecPtr requestLsn); -extern void PreInitXlogFileForPrimary(int advance_xlog_file_num); +extern void PreInitXlogFileForPrimary(int wal_file_init_num); extern void CheckXLogRemoved(XLogSegNo segno, TimeLineID tli); extern void XLogSetAsyncXactLSN(XLogRecPtr record);