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

Commit932f9fb

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 parented2c7f6 commit932f9fb

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
@@ -224,7 +224,7 @@ test_open(void)
224224
/*
225225
* test if we can open the target file
226226
*/
227-
if ((tmpfile=open(filename,O_RDWR |O_CREAT,S_IRUSR |S_IWUSR))==-1)
227+
if ((tmpfile=open(filename,O_RDWR |O_CREAT |PG_BINARY,S_IRUSR |S_IWUSR))==-1)
228228
die("could not open output file");
229229
needs_unlink=1;
230230
if (write(tmpfile,full_buf,DEFAULT_XLOG_SEG_SIZE)!=
@@ -259,7 +259,7 @@ test_sync(int writes_per_op)
259259
fflush(stdout);
260260

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

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

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

338338
#ifdefHAVE_FSYNC_WRITETHROUGH
339-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
339+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
340340
die("could not open output file");
341341
START_TIMER;
342342
for (ops=0;alarm_triggered== false;ops++)
@@ -362,7 +362,7 @@ test_sync(int writes_per_op)
362362
fflush(stdout);
363363

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

431431
#ifdefOPEN_SYNC_FLAG
432-
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT,0))==-1)
432+
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT |PG_BINARY,0))==-1)
433433
printf(NA_FORMAT,_("n/a*"));
434434
else
435435
{
@@ -477,7 +477,7 @@ test_file_descriptor_sync(void)
477477
START_TIMER;
478478
for (ops=0;alarm_triggered== false;ops++)
479479
{
480-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
480+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
481481
die("could not open output file");
482482
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
483483
die("write failed");
@@ -489,7 +489,7 @@ test_file_descriptor_sync(void)
489489
* open and close the file again to be consistent with the following
490490
* test
491491
*/
492-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
492+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
493493
die("could not open output file");
494494
close(tmpfile);
495495
}
@@ -505,13 +505,13 @@ test_file_descriptor_sync(void)
505505
START_TIMER;
506506
for (ops=0;alarm_triggered== false;ops++)
507507
{
508-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
508+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
509509
die("could not open output file");
510510
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
511511
die("write failed");
512512
close(tmpfile);
513513
/* reopen file */
514-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
514+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
515515
die("could not open output file");
516516
if (fsync(tmpfile)!=0)
517517
die("fsync failed");
@@ -536,7 +536,7 @@ test_non_sync(void)
536536
START_TIMER;
537537
for (ops=0;alarm_triggered== false;ops++)
538538
{
539-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
539+
if ((tmpfile=open(filename,O_RDWR |PG_BINARY,0))==-1)
540540
die("could not open output file");
541541
if (write(tmpfile,buf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
542542
die("write failed");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp