mirror of
https://github.com/postgres/postgres.git
synced 2025-12-10 14:22:35 +03:00
Use PGAlignedXLogBlock for some code simplification
The code in BootStrapXLOG() and in pg_test_fsync.c tried to align WAL buffers in complicated ways. Also, they still used XLOG_BLCKSZ for the alignment, even though that should now be PG_IO_ALIGN_SIZE. This can now be simplified and made more consistent by using PGAlignedXLogBlock, either directly in BootStrapXLOG() and using alignas in pg_test_fsync.c. Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/f462a175-b608-44a1-b428-bdf351e914f4%40eisentraut.org
This commit is contained in:
@@ -5089,7 +5089,7 @@ void
|
|||||||
BootStrapXLOG(uint32 data_checksum_version)
|
BootStrapXLOG(uint32 data_checksum_version)
|
||||||
{
|
{
|
||||||
CheckPoint checkPoint;
|
CheckPoint checkPoint;
|
||||||
char *buffer;
|
PGAlignedXLogBlock buffer;
|
||||||
XLogPageHeader page;
|
XLogPageHeader page;
|
||||||
XLogLongPageHeader longpage;
|
XLogLongPageHeader longpage;
|
||||||
XLogRecord *record;
|
XLogRecord *record;
|
||||||
@@ -5118,10 +5118,8 @@ BootStrapXLOG(uint32 data_checksum_version)
|
|||||||
sysidentifier |= ((uint64) tv.tv_usec) << 12;
|
sysidentifier |= ((uint64) tv.tv_usec) << 12;
|
||||||
sysidentifier |= getpid() & 0xFFF;
|
sysidentifier |= getpid() & 0xFFF;
|
||||||
|
|
||||||
/* page buffer must be aligned suitably for O_DIRECT */
|
memset(&buffer, 0, sizeof buffer);
|
||||||
buffer = (char *) palloc(XLOG_BLCKSZ + XLOG_BLCKSZ);
|
page = (XLogPageHeader) &buffer;
|
||||||
page = (XLogPageHeader) TYPEALIGN(XLOG_BLCKSZ, buffer);
|
|
||||||
memset(page, 0, XLOG_BLCKSZ);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up information for the initial checkpoint record
|
* Set up information for the initial checkpoint record
|
||||||
@@ -5202,7 +5200,7 @@ BootStrapXLOG(uint32 data_checksum_version)
|
|||||||
/* Write the first page with the initial record */
|
/* Write the first page with the initial record */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
pgstat_report_wait_start(WAIT_EVENT_WAL_BOOTSTRAP_WRITE);
|
pgstat_report_wait_start(WAIT_EVENT_WAL_BOOTSTRAP_WRITE);
|
||||||
if (write(openLogFile, page, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (write(openLogFile, &buffer, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
{
|
{
|
||||||
/* if write didn't set errno, assume problem is no disk space */
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
if (errno == 0)
|
if (errno == 0)
|
||||||
@@ -5242,8 +5240,6 @@ BootStrapXLOG(uint32 data_checksum_version)
|
|||||||
BootStrapSUBTRANS();
|
BootStrapSUBTRANS();
|
||||||
BootStrapMultiXact();
|
BootStrapMultiXact();
|
||||||
|
|
||||||
pfree(buffer);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Force control file to be read - in contrast to normal processing we'd
|
* Force control file to be read - in contrast to normal processing we'd
|
||||||
* otherwise never run the checks and GUC related initializations therein.
|
* otherwise never run the checks and GUC related initializations therein.
|
||||||
|
|||||||
@@ -68,9 +68,8 @@ static const char *progname;
|
|||||||
|
|
||||||
static unsigned int secs_per_test = 5;
|
static unsigned int secs_per_test = 5;
|
||||||
static int needs_unlink = 0;
|
static int needs_unlink = 0;
|
||||||
static char full_buf[DEFAULT_XLOG_SEG_SIZE],
|
alignas(PGAlignedXLogBlock) static char buf[DEFAULT_XLOG_SEG_SIZE];
|
||||||
*buf,
|
static char *filename = FSYNC_FILENAME;
|
||||||
*filename = FSYNC_FILENAME;
|
|
||||||
static struct timeval start_t,
|
static struct timeval start_t,
|
||||||
stop_t;
|
stop_t;
|
||||||
static sig_atomic_t alarm_triggered = false;
|
static sig_atomic_t alarm_triggered = false;
|
||||||
@@ -232,9 +231,7 @@ prepare_buf(void)
|
|||||||
|
|
||||||
/* write random data into buffer */
|
/* write random data into buffer */
|
||||||
for (ops = 0; ops < DEFAULT_XLOG_SEG_SIZE; ops++)
|
for (ops = 0; ops < DEFAULT_XLOG_SEG_SIZE; ops++)
|
||||||
full_buf[ops] = (char) pg_prng_int32(&pg_global_prng_state);
|
buf[ops] = (char) pg_prng_int32(&pg_global_prng_state);
|
||||||
|
|
||||||
buf = (char *) TYPEALIGN(XLOG_BLCKSZ, full_buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -248,7 +245,7 @@ test_open(void)
|
|||||||
if ((tmpfile = open(filename, O_RDWR | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR)) == -1)
|
if ((tmpfile = open(filename, O_RDWR | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR)) == -1)
|
||||||
die("could not open output file");
|
die("could not open output file");
|
||||||
needs_unlink = 1;
|
needs_unlink = 1;
|
||||||
if (write(tmpfile, full_buf, DEFAULT_XLOG_SEG_SIZE) !=
|
if (write(tmpfile, buf, DEFAULT_XLOG_SEG_SIZE) !=
|
||||||
DEFAULT_XLOG_SEG_SIZE)
|
DEFAULT_XLOG_SEG_SIZE)
|
||||||
die("write failed");
|
die("write failed");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user