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

Commitde559c2

Browse files
committed
Switch pg_test_fsync to use binary mode on Windows
pg_test_fsync has always opened files using the text mode on Windows, asthis is the default mode used if not enforced by _setmode().This fixes a failure when running pg_test_fsync down to 12 becauseO_DSYNC and the text mode are not able to work together nicely. Wefixed the handling of O_DSYNC in 12~ for the tool by switching to theconcurrent-safe version of fopen() in src/port/ with0ba06e0. And40cfe86, by enforcing the text mode for compatibility reasons if O_TEXTor O_BINARY are not specified by the caller, broke pg_test_fsync. Forall versions, this avoids any translation overhead, and pg_test_fsyncshould test binary writes, so it is a gain in all cases.Note that O_DSYNC is still not handled correctly in ~11, leading topg_test_fsync to show insanely high numbers for open_datasync() (usingthis property it is easy to notice that the binary mode is muchfaster). This would require a backpatch of0ba06e0 and40cfe86, whichcould potentially break existing applications, so this is left out.There are no TAP tests for this tool yet, so I have checked all buildsmanually using MSVC. We could invent a new option to run a singletransaction instead of using a duration of 1s to make the tests amaximum short, but this is left as future work.Thanks to Bruce Momjian for the discussion.Reported-by: Jeff JanesAuthor: Michael PaquierDiscussion:https://postgr.es/m/16526-279ded30a230d275@postgresql.orgBackpatch-through: 9.5
1 parentc6d43ff commitde559c2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

‎src/bin/pg_test_fsync/pg_test_fsync.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ test_open(void)
223223
/*
224224
* test if we can open the target file
225225
*/
226-
if ((tmpfile=open(filename,O_RDWR |O_CREAT,S_IRUSR |S_IWUSR))==-1)
226+
if ((tmpfile=open(filename,O_RDWR |O_CREAT |PG_BINARY,S_IRUSR |S_IWUSR))==-1)
227227
die("could not open output file");
228228
needs_unlink=1;
229229
if (write(tmpfile,full_buf,DEFAULT_XLOG_SEG_SIZE)!=
@@ -258,7 +258,7 @@ test_sync(int writes_per_op)
258258
fflush(stdout);
259259

260260
#ifdefOPEN_DATASYNC_FLAG
261-
if ((tmpfile=open(filename,O_RDWR |O_DSYNC |PG_O_DIRECT,0))==-1)
261+
if ((tmpfile=open(filename,O_RDWR |O_DSYNC |PG_O_DIRECT |PG_BINARY,0))==-1)
262262
{
263263
printf(NA_FORMAT,_("n/a*"));
264264
fs_warning= true;
@@ -288,7 +288,7 @@ test_sync(int writes_per_op)
288288
fflush(stdout);
289289

290290
#ifdefHAVE_FDATASYNC
291-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
291+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
292292
die("could not open output file");
293293
START_TIMER;
294294
for (ops=0;alarm_triggered== false;ops++)
@@ -312,7 +312,7 @@ test_sync(int writes_per_op)
312312
printf(LABEL_FORMAT,"fsync");
313313
fflush(stdout);
314314

315-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
315+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
316316
die("could not open output file");
317317
START_TIMER;
318318
for (ops=0;alarm_triggered== false;ops++)
@@ -335,7 +335,7 @@ test_sync(int writes_per_op)
335335
fflush(stdout);
336336

337337
#ifdefHAVE_FSYNC_WRITETHROUGH
338-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
338+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
339339
die("could not open output file");
340340
START_TIMER;
341341
for (ops=0;alarm_triggered== false;ops++)
@@ -361,7 +361,7 @@ test_sync(int writes_per_op)
361361
fflush(stdout);
362362

363363
#ifdefOPEN_SYNC_FLAG
364-
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT,0))==-1)
364+
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT |PG_BINARY,0))==-1)
365365
{
366366
printf(NA_FORMAT,_("n/a*"));
367367
fs_warning= true;
@@ -428,7 +428,7 @@ test_open_sync(const char *msg, int writes_size)
428428
fflush(stdout);
429429

430430
#ifdefOPEN_SYNC_FLAG
431-
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT,0))==-1)
431+
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT |PG_BINARY,0))==-1)
432432
printf(NA_FORMAT,_("n/a*"));
433433
else
434434
{
@@ -476,7 +476,7 @@ test_file_descriptor_sync(void)
476476
START_TIMER;
477477
for (ops=0;alarm_triggered== false;ops++)
478478
{
479-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
479+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
480480
die("could not open output file");
481481
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
482482
die("write failed");
@@ -488,7 +488,7 @@ test_file_descriptor_sync(void)
488488
* open and close the file again to be consistent with the following
489489
* test
490490
*/
491-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
491+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
492492
die("could not open output file");
493493
close(tmpfile);
494494
}
@@ -504,13 +504,13 @@ test_file_descriptor_sync(void)
504504
START_TIMER;
505505
for (ops=0;alarm_triggered== false;ops++)
506506
{
507-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
507+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
508508
die("could not open output file");
509509
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
510510
die("write failed");
511511
close(tmpfile);
512512
/* reopen file */
513-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
513+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
514514
die("could not open output file");
515515
if (fsync(tmpfile)!=0)
516516
die("fsync failed");
@@ -535,7 +535,7 @@ test_non_sync(void)
535535
START_TIMER;
536536
for (ops=0;alarm_triggered== false;ops++)
537537
{
538-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
538+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
539539
die("could not open output file");
540540
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
541541
die("write failed");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp