From 65afd2923aba65d36b7ea2e1165f5b005fc44918 Mon Sep 17 00:00:00 2001 From: congzhou2603 Date: Wed, 8 May 2024 16:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90bugfix=E3=80=91=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=B1=A0=E5=8C=96init=20xlogfile=20=E5=BC=BA=E5=88=B6=E5=86=99?= =?UTF-8?q?0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/threadpool/knl_instance.cpp | 3 ++ .../storage/access/transam/xlog.cpp | 29 ++++++++++++++++++- src/include/access/xlog_basic.h | 4 +++ src/include/knl/knl_instance.h | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/process/threadpool/knl_instance.cpp b/src/gausskernel/process/threadpool/knl_instance.cpp index 3764b06af..56e7ca600 100755 --- a/src/gausskernel/process/threadpool/knl_instance.cpp +++ b/src/gausskernel/process/threadpool/knl_instance.cpp @@ -149,6 +149,9 @@ static void knl_g_wal_init(knl_g_wal_context *const wal_cxt) SpinLockInit(&wal_cxt->walReceiverStats->mutex); wal_cxt->walRecvWriterStats = (WalRecvWriterStats*)palloc0(sizeof(WalRecvWriterStats)); SpinLockInit(&wal_cxt->walRecvWriterStats->mutex); + if (ENABLE_DMS) { + wal_cxt->ssZeroBuffer = (char*)palloc0(SS_XLOG_WRITE_ZERO_STEP + ALIGNOF_BUFFER); + } } static void knl_g_bgwriter_init(knl_g_bgwriter_context *bgwriter_cxt) diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index d0facab56..d8459cc72 100755 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -3994,6 +3994,7 @@ static int XLogFileInitInternal(XLogSegNo logsegno, bool *use_existent, bool use char path[MAXPGPATH]; char tmppath[MAXPGPATH]; char *zbuffer = NULL; + char *ss_zbuffer = NULL; char zbuffer_raw[XLOG_BLCKSZ + ALIGNOF_BUFFER]; XLogSegNo installed_segno; int max_advance; @@ -4064,6 +4065,7 @@ 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; @@ -4073,10 +4075,35 @@ static int XLogFileInitInternal(XLogSegNo logsegno, bool *use_existent, bool use unlink(tmppath); /* if write didn't set errno, assume problem is no disk space */ errno = save_errno ? save_errno : ENOSPC; - ereport(ERROR, (errcode_for_file_access(), errmsg("could not write to file \"%s\": %s", + ereport(ERROR, (errcode_for_file_access(), errmsg("could not write to file \"%s\": %s", tmppath, TRANSLATE_ERRNO))); } pgstat_report_waitevent(WAIT_EVENT_END); + if (g_instance.wal_cxt.ssZeroBuffer != NULL) { + ss_zbuffer = (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"); + } + /* 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) { + int save_errno = errno; + + /* If we fail to make the file, delete it to release disk space */ + close(fd); + unlink(tmppath); + /* if write didn't set errno, assume problem is no disk space */ + errno = save_errno ? save_errno : ENOSPC; + + ereport(ERROR, (errcode_for_file_access(), errmsg("could not write to file \"%s\": %s", + tmppath, TRANSLATE_ERRNO))); + } + pgstat_report_waitevent(WAIT_EVENT_END); + } } else { for (nbytes = 0; (uint32)nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ) { errno = 0; diff --git a/src/include/access/xlog_basic.h b/src/include/access/xlog_basic.h index 817cfa8d9..cb34822c0 100644 --- a/src/include/access/xlog_basic.h +++ b/src/include/access/xlog_basic.h @@ -112,6 +112,10 @@ #define SS_DORADO_CTRL_FILE (g_instance.datadir_cxt.controlInfoPath) +/** + * The writing zero step when XLogFileInit in share storage mode. + */ +#define SS_XLOG_WRITE_ZERO_STEP (XLOG_BLCKSZ * 256) #define InvalidRepOriginId 0 #define InvalidXlogPreReadStartPtr 0xFFFFFFFFFFFFFFFF diff --git a/src/include/knl/knl_instance.h b/src/include/knl/knl_instance.h index 3568c474c..0ffb3f41c 100755 --- a/src/include/knl/knl_instance.h +++ b/src/include/knl/knl_instance.h @@ -1059,6 +1059,7 @@ typedef struct knl_g_wal_context { WalSenderStats* walSenderStats; WalReceiverStats* walReceiverStats; WalRecvWriterStats* walRecvWriterStats; + char* ssZeroBuffer; /* an all-zero buffer used to write zero when initing xlog file */ } knl_g_wal_context; typedef struct GlobalSeqInfoHashBucket {