Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c8b42b

Browse files
committed
Use pg_pwrite() in pg_test_fsync.
For consistency with the PostgreSQL behavior this test program isintended to simulate, use pwrite() instead of lseek() + write().Also fix the final "non-sync" test, which was opening and closing thefile for every write.Discussion:https://postgr.es/m/CA%2BhUKGJjjid2BJsvjMALBTduo1ogdx2SPYaTQL3wAy8y2hc4nw%40mail.gmail.com
1 parentd9b0767 commit2c8b42b

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

‎src/bin/pg_test_fsync/pg_test_fsync.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ test_sync(int writes_per_op)
290290
for (ops=0;alarm_triggered== false;ops++)
291291
{
292292
for (writes=0;writes<writes_per_op;writes++)
293-
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
293+
if (pg_pwrite(tmpfile,
294+
buf,
295+
XLOG_BLCKSZ,
296+
writes*XLOG_BLCKSZ)!=XLOG_BLCKSZ)
294297
die("write failed");
295-
if (lseek(tmpfile,0,SEEK_SET)==-1)
296-
die("seek failed");
297298
}
298299
STOP_TIMER;
299300
close(tmpfile);
@@ -315,11 +316,12 @@ test_sync(int writes_per_op)
315316
for (ops=0;alarm_triggered== false;ops++)
316317
{
317318
for (writes=0;writes<writes_per_op;writes++)
318-
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
319+
if (pg_pwrite(tmpfile,
320+
buf,
321+
XLOG_BLCKSZ,
322+
writes*XLOG_BLCKSZ)!=XLOG_BLCKSZ)
319323
die("write failed");
320324
fdatasync(tmpfile);
321-
if (lseek(tmpfile,0,SEEK_SET)==-1)
322-
die("seek failed");
323325
}
324326
STOP_TIMER;
325327
close(tmpfile);
@@ -339,12 +341,13 @@ test_sync(int writes_per_op)
339341
for (ops=0;alarm_triggered== false;ops++)
340342
{
341343
for (writes=0;writes<writes_per_op;writes++)
342-
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
344+
if (pg_pwrite(tmpfile,
345+
buf,
346+
XLOG_BLCKSZ,
347+
writes*XLOG_BLCKSZ)!=XLOG_BLCKSZ)
343348
die("write failed");
344349
if (fsync(tmpfile)!=0)
345350
die("fsync failed");
346-
if (lseek(tmpfile,0,SEEK_SET)==-1)
347-
die("seek failed");
348351
}
349352
STOP_TIMER;
350353
close(tmpfile);
@@ -362,12 +365,13 @@ test_sync(int writes_per_op)
362365
for (ops=0;alarm_triggered== false;ops++)
363366
{
364367
for (writes=0;writes<writes_per_op;writes++)
365-
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
368+
if (pg_pwrite(tmpfile,
369+
buf,
370+
XLOG_BLCKSZ,
371+
writes*XLOG_BLCKSZ)!=XLOG_BLCKSZ)
366372
die("write failed");
367373
if (pg_fsync_writethrough(tmpfile)!=0)
368374
die("fsync failed");
369-
if (lseek(tmpfile,0,SEEK_SET)==-1)
370-
die("seek failed");
371375
}
372376
STOP_TIMER;
373377
close(tmpfile);
@@ -393,17 +397,17 @@ test_sync(int writes_per_op)
393397
for (ops=0;alarm_triggered== false;ops++)
394398
{
395399
for (writes=0;writes<writes_per_op;writes++)
396-
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
397-
400+
if (pg_pwrite(tmpfile,
401+
buf,
402+
XLOG_BLCKSZ,
403+
writes*XLOG_BLCKSZ)!=XLOG_BLCKSZ)
398404
/*
399405
* This can generate write failures if the filesystem has
400406
* a large block size, e.g. 4k, and there is no support
401407
* for O_DIRECT writes smaller than the file system block
402408
* size, e.g. XFS.
403409
*/
404410
die("write failed");
405-
if (lseek(tmpfile,0,SEEK_SET)==-1)
406-
die("seek failed");
407411
}
408412
STOP_TIMER;
409413
close(tmpfile);
@@ -457,11 +461,12 @@ test_open_sync(const char *msg, int writes_size)
457461
for (ops=0;alarm_triggered== false;ops++)
458462
{
459463
for (writes=0;writes<16 /writes_size;writes++)
460-
if (write(tmpfile,buf,writes_size*1024)!=
464+
if (pg_pwrite(tmpfile,
465+
buf,
466+
writes_size*1024,
467+
writes*writes_size*1024)!=
461468
writes_size*1024)
462469
die("write failed");
463-
if (lseek(tmpfile,0,SEEK_SET)==-1)
464-
die("seek failed");
465470
}
466471
STOP_TIMER;
467472
close(tmpfile);
@@ -553,16 +558,16 @@ test_non_sync(void)
553558
printf(LABEL_FORMAT,"write");
554559
fflush(stdout);
555560

561+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
562+
die("could not open output file");
556563
START_TIMER;
557564
for (ops=0;alarm_triggered== false;ops++)
558565
{
559-
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
560-
die("could not open output file");
561-
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
566+
if (pg_pwrite(tmpfile,buf,XLOG_BLCKSZ,0)!=XLOG_BLCKSZ)
562567
die("write failed");
563-
close(tmpfile);
564568
}
565569
STOP_TIMER;
570+
close(tmpfile);
566571
}
567572

568573
staticvoid

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp