From ca5a50dd4e9fe186de2c38e5d118b33e2f99f806 Mon Sep 17 00:00:00 2001 From: muyulinzhong Date: Fri, 7 Jun 2024 15:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D&&=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E3=80=91=20=E4=BF=AE=E5=A4=8DXLogInitFile=E7=9A=84=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E7=88=86=E6=A0=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../storage/access/transam/xlog.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index a92d9702f..affaeb14a 100755 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -3993,7 +3993,8 @@ static int XLogFileInitInternal(XLogSegNo logsegno, bool *use_existent, bool use char path[MAXPGPATH]; char tmppath[MAXPGPATH]; char *zbuffer = NULL; - char *ss_zbuffer = NULL; + char* ss_zero_buffer_raw = NULL; + char* ss_zero_buffer = NULL; char zbuffer_raw[XLOG_BLCKSZ + ALIGNOF_BUFFER]; XLogSegNo installed_segno; int max_advance; @@ -4064,7 +4065,6 @@ static int XLogFileInitInternal(XLogSegNo logsegno, bool *use_existent, bool use securec_check(rc, "\0", "\0"); if (is_dss_fd(fd)) { - char ssZeroBuffer[SS_XLOG_WRITE_ZERO_STEP + ALIGNOF_BUFFER]; /* extend file and fill space at once to avoid performance issue */ pgstat_report_waitevent(WAIT_EVENT_WAL_INIT_WRITE); errno = 0; @@ -4079,17 +4079,17 @@ static int XLogFileInitInternal(XLogSegNo logsegno, bool *use_existent, bool use } pgstat_report_waitevent(WAIT_EVENT_END); if (g_instance.wal_cxt.ssZeroBuffer != NULL) { - ss_zbuffer = (char *)BUFFERALIGN(g_instance.wal_cxt.ssZeroBuffer); + ss_zero_buffer = (char *)BUFFERALIGN(g_instance.wal_cxt.ssZeroBuffer); } else { - ss_zbuffer = (char *)BUFFERALIGN(ssZeroBuffer); - rc = memset_s(ss_zbuffer, SS_XLOG_WRITE_ZERO_STEP, 0, SS_XLOG_WRITE_ZERO_STEP); - securec_check(rc, "\0", "\0"); + /* If we run without initializing wal_cxt, such as BootStrap mode */ + ss_zero_buffer_raw = (char*)palloc0(SS_XLOG_WRITE_ZERO_STEP + ALIGNOF_BUFFER); + ss_zero_buffer = (char *)BUFFERALIGN(ss_zero_buffer_raw); } /* zero-file the file after ftruncate */ for (nbytes = 0; (uint32)nbytes < XLogSegSize; nbytes += SS_XLOG_WRITE_ZERO_STEP) { errno = 0; pgstat_report_waitevent(WAIT_EVENT_WAL_INIT_WRITE); - if ((int)write(fd, ss_zbuffer, SS_XLOG_WRITE_ZERO_STEP) != (int)SS_XLOG_WRITE_ZERO_STEP) { + if ((int)write(fd, ss_zero_buffer, SS_XLOG_WRITE_ZERO_STEP) != (int)SS_XLOG_WRITE_ZERO_STEP) { int save_errno = errno; /* If we fail to make the file, delete it to release disk space */ @@ -4103,6 +4103,10 @@ static int XLogFileInitInternal(XLogSegNo logsegno, bool *use_existent, bool use } pgstat_report_waitevent(WAIT_EVENT_END); } + if (ss_zero_buffer_raw != NULL) { + ss_zero_buffer = NULL; + pfree(ss_zero_buffer_raw); + } } else { for (nbytes = 0; (uint32)nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ) { errno = 0;