Use pg_pwrite() in pg_test_fsync.
For consistency with the PostgreSQL behavior this test program is intended to simulate, use pwrite() instead of lseek() + write(). Also fix the final "non-sync" test, which was opening and closing the file for every write. Discussion: https://postgr.es/m/CA%2BhUKGJjjid2BJsvjMALBTduo1ogdx2SPYaTQL3wAy8y2hc4nw%40mail.gmail.com
This commit is contained in:
parent
d9b0767bec
commit
2c8b42b50d
@ -290,10 +290,11 @@ test_sync(int writes_per_op)
|
|||||||
for (ops = 0; alarm_triggered == false; ops++)
|
for (ops = 0; alarm_triggered == false; ops++)
|
||||||
{
|
{
|
||||||
for (writes = 0; writes < writes_per_op; writes++)
|
for (writes = 0; writes < writes_per_op; writes++)
|
||||||
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (pg_pwrite(tmpfile,
|
||||||
|
buf,
|
||||||
|
XLOG_BLCKSZ,
|
||||||
|
writes * XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
die("write failed");
|
die("write failed");
|
||||||
if (lseek(tmpfile, 0, SEEK_SET) == -1)
|
|
||||||
die("seek failed");
|
|
||||||
}
|
}
|
||||||
STOP_TIMER;
|
STOP_TIMER;
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
@ -315,11 +316,12 @@ test_sync(int writes_per_op)
|
|||||||
for (ops = 0; alarm_triggered == false; ops++)
|
for (ops = 0; alarm_triggered == false; ops++)
|
||||||
{
|
{
|
||||||
for (writes = 0; writes < writes_per_op; writes++)
|
for (writes = 0; writes < writes_per_op; writes++)
|
||||||
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (pg_pwrite(tmpfile,
|
||||||
|
buf,
|
||||||
|
XLOG_BLCKSZ,
|
||||||
|
writes * XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
die("write failed");
|
die("write failed");
|
||||||
fdatasync(tmpfile);
|
fdatasync(tmpfile);
|
||||||
if (lseek(tmpfile, 0, SEEK_SET) == -1)
|
|
||||||
die("seek failed");
|
|
||||||
}
|
}
|
||||||
STOP_TIMER;
|
STOP_TIMER;
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
@ -339,12 +341,13 @@ test_sync(int writes_per_op)
|
|||||||
for (ops = 0; alarm_triggered == false; ops++)
|
for (ops = 0; alarm_triggered == false; ops++)
|
||||||
{
|
{
|
||||||
for (writes = 0; writes < writes_per_op; writes++)
|
for (writes = 0; writes < writes_per_op; writes++)
|
||||||
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (pg_pwrite(tmpfile,
|
||||||
|
buf,
|
||||||
|
XLOG_BLCKSZ,
|
||||||
|
writes * XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
die("write failed");
|
die("write failed");
|
||||||
if (fsync(tmpfile) != 0)
|
if (fsync(tmpfile) != 0)
|
||||||
die("fsync failed");
|
die("fsync failed");
|
||||||
if (lseek(tmpfile, 0, SEEK_SET) == -1)
|
|
||||||
die("seek failed");
|
|
||||||
}
|
}
|
||||||
STOP_TIMER;
|
STOP_TIMER;
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
@ -362,12 +365,13 @@ test_sync(int writes_per_op)
|
|||||||
for (ops = 0; alarm_triggered == false; ops++)
|
for (ops = 0; alarm_triggered == false; ops++)
|
||||||
{
|
{
|
||||||
for (writes = 0; writes < writes_per_op; writes++)
|
for (writes = 0; writes < writes_per_op; writes++)
|
||||||
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (pg_pwrite(tmpfile,
|
||||||
|
buf,
|
||||||
|
XLOG_BLCKSZ,
|
||||||
|
writes * XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
die("write failed");
|
die("write failed");
|
||||||
if (pg_fsync_writethrough(tmpfile) != 0)
|
if (pg_fsync_writethrough(tmpfile) != 0)
|
||||||
die("fsync failed");
|
die("fsync failed");
|
||||||
if (lseek(tmpfile, 0, SEEK_SET) == -1)
|
|
||||||
die("seek failed");
|
|
||||||
}
|
}
|
||||||
STOP_TIMER;
|
STOP_TIMER;
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
@ -393,8 +397,10 @@ test_sync(int writes_per_op)
|
|||||||
for (ops = 0; alarm_triggered == false; ops++)
|
for (ops = 0; alarm_triggered == false; ops++)
|
||||||
{
|
{
|
||||||
for (writes = 0; writes < writes_per_op; writes++)
|
for (writes = 0; writes < writes_per_op; writes++)
|
||||||
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (pg_pwrite(tmpfile,
|
||||||
|
buf,
|
||||||
|
XLOG_BLCKSZ,
|
||||||
|
writes * XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
/*
|
/*
|
||||||
* This can generate write failures if the filesystem has
|
* This can generate write failures if the filesystem has
|
||||||
* a large block size, e.g. 4k, and there is no support
|
* a large block size, e.g. 4k, and there is no support
|
||||||
@ -402,8 +408,6 @@ test_sync(int writes_per_op)
|
|||||||
* size, e.g. XFS.
|
* size, e.g. XFS.
|
||||||
*/
|
*/
|
||||||
die("write failed");
|
die("write failed");
|
||||||
if (lseek(tmpfile, 0, SEEK_SET) == -1)
|
|
||||||
die("seek failed");
|
|
||||||
}
|
}
|
||||||
STOP_TIMER;
|
STOP_TIMER;
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
@ -457,11 +461,12 @@ test_open_sync(const char *msg, int writes_size)
|
|||||||
for (ops = 0; alarm_triggered == false; ops++)
|
for (ops = 0; alarm_triggered == false; ops++)
|
||||||
{
|
{
|
||||||
for (writes = 0; writes < 16 / writes_size; writes++)
|
for (writes = 0; writes < 16 / writes_size; writes++)
|
||||||
if (write(tmpfile, buf, writes_size * 1024) !=
|
if (pg_pwrite(tmpfile,
|
||||||
|
buf,
|
||||||
|
writes_size * 1024,
|
||||||
|
writes * writes_size * 1024) !=
|
||||||
writes_size * 1024)
|
writes_size * 1024)
|
||||||
die("write failed");
|
die("write failed");
|
||||||
if (lseek(tmpfile, 0, SEEK_SET) == -1)
|
|
||||||
die("seek failed");
|
|
||||||
}
|
}
|
||||||
STOP_TIMER;
|
STOP_TIMER;
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
@ -553,16 +558,16 @@ test_non_sync(void)
|
|||||||
printf(LABEL_FORMAT, "write");
|
printf(LABEL_FORMAT, "write");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
|
if ((tmpfile = open(filename, O_RDWR | PG_BINARY, 0)) == -1)
|
||||||
|
die("could not open output file");
|
||||||
START_TIMER;
|
START_TIMER;
|
||||||
for (ops = 0; alarm_triggered == false; ops++)
|
for (ops = 0; alarm_triggered == false; ops++)
|
||||||
{
|
{
|
||||||
if ((tmpfile = open(filename, O_RDWR | PG_BINARY, 0)) == -1)
|
if (pg_pwrite(tmpfile, buf, XLOG_BLCKSZ, 0) != XLOG_BLCKSZ)
|
||||||
die("could not open output file");
|
|
||||||
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
|
||||||
die("write failed");
|
die("write failed");
|
||||||
close(tmpfile);
|
|
||||||
}
|
}
|
||||||
STOP_TIMER;
|
STOP_TIMER;
|
||||||
|
close(tmpfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user