【bugfix】资源池化init xlogfile 强制写0
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user