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

Commit6dc7760

Browse files
committed
Add support for wal_fsync_writethrough for Darwin, and restructure the
code to better handle writethrough.Chris Campbell
1 parente9b33ed commit6dc7760

File tree

7 files changed

+79
-29
lines changed

7 files changed

+79
-29
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.319 2005/05/15 00:26:18 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.320 2005/05/20 14:53:25 momjian Exp $
33
-->
44

55
<chapter Id="runtime">
@@ -1595,7 +1595,7 @@ SET ENABLE_SEQSCAN TO OFF;
15951595
values are
15961596
<literal>fsync</> (call <function>fsync()</> at each commit),
15971597
<literal>fdatasync</> (call <function>fdatasync()</> at each commit),
1598-
<literal>fsync_writethrough</> (call <function>_commit()</> at each commit on Windows),
1598+
<literal>fsync_writethrough</> (force write-through of any disk write cache),
15991599
<literal>open_sync</> (write WAL files with <function>open()</> option <symbol>O_SYNC</>), and
16001600
<literal>open_datasync</> (write WAL files with <function>open()</> option <symbol>O_DSYNC</>).
16011601
Not all of these choices are available on all platforms.

‎src/backend/access/transam/xlog.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.192 2005/05/19 21:35:45 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.193 2005/05/20 14:53:25 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -51,11 +51,6 @@
5151
* default method.We assume that fsync() is always available, and that
5252
* configure determined whether fdatasync() is.
5353
*/
54-
#defineSYNC_METHOD_FSYNC0
55-
#defineSYNC_METHOD_FDATASYNC1
56-
#defineSYNC_METHOD_OPEN2/* used for both O_SYNC and
57-
* O_DSYNC */
58-
5954
#if defined(O_SYNC)
6055
#defineOPEN_SYNC_FLAG O_SYNC
6156
#else
@@ -79,21 +74,19 @@
7974
#defineDEFAULT_SYNC_METHOD_STR "open_datasync"
8075
#defineDEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
8176
#defineDEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
82-
#else
83-
#if defined(HAVE_FDATASYNC)
77+
#elif defined(HAVE_FDATASYNC)
8478
#defineDEFAULT_SYNC_METHOD_STR "fdatasync"
8579
#defineDEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
8680
#defineDEFAULT_SYNC_FLAGBIT 0
87-
#else
88-
#ifndefFSYNC_IS_WRITE_THROUGH
81+
#elif !defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
8982
#defineDEFAULT_SYNC_METHOD_STR "fsync"
83+
#defineDEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
84+
#defineDEFAULT_SYNC_FLAGBIT 0
9085
#else
9186
#defineDEFAULT_SYNC_METHOD_STR "fsync_writethrough"
92-
#endif
93-
#defineDEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
87+
#defineDEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
9488
#defineDEFAULT_SYNC_FLAGBIT 0
9589
#endif
96-
#endif
9790

9891

9992
/* User-settable parameters */
@@ -122,7 +115,7 @@ boolXLOG_DEBUG = false;
122115

123116

124117
/* these are derived from XLOG_sync_method by assign_xlog_sync_method */
125-
staticintsync_method=DEFAULT_SYNC_METHOD;
118+
intsync_method=DEFAULT_SYNC_METHOD;
126119
staticintopen_sync_bit=DEFAULT_SYNC_FLAGBIT;
127120

128121
#defineXLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
@@ -5249,16 +5242,18 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
52495242
intnew_sync_method;
52505243
intnew_sync_bit;
52515244

5252-
#ifndefFSYNC_IS_WRITE_THROUGH
52535245
if (pg_strcasecmp(method,"fsync")==0)
5254-
#else
5255-
/* Win32 fsync() == _commit(), which writes through a write cache */
5256-
if (pg_strcasecmp(method,"fsync_writethrough")==0)
5257-
#endif
52585246
{
52595247
new_sync_method=SYNC_METHOD_FSYNC;
52605248
new_sync_bit=0;
52615249
}
5250+
#ifdefHAVE_FSYNC_WRITETHROUGH
5251+
elseif (pg_strcasecmp(method, "fsync_writethrough")==0)
5252+
{
5253+
new_sync_method=SYNC_METHOD_FSYNC_WRITETHROUGH;
5254+
new_sync_bit=0;
5255+
}
5256+
#endif
52625257
#ifdefHAVE_FDATASYNC
52635258
elseif (pg_strcasecmp(method, "fdatasync")==0)
52645259
{
@@ -5328,12 +5323,21 @@ issue_xlog_fsync(void)
53285323
switch (sync_method)
53295324
{
53305325
caseSYNC_METHOD_FSYNC:
5331-
if (pg_fsync(openLogFile)!=0)
5326+
if (pg_fsync_no_writethrough(openLogFile)!=0)
53325327
ereport(PANIC,
53335328
(errcode_for_file_access(),
53345329
errmsg("could not fsync log file %u, segment %u: %m",
53355330
openLogId,openLogSeg)));
53365331
break;
5332+
#ifdefHAVE_FSYNC_WRITETHROUGH
5333+
caseSYNC_METHOD_FSYNC_WRITETHROUGH:
5334+
if (pg_fsync_writethrough(openLogFile)!=0)
5335+
ereport(PANIC,
5336+
(errcode_for_file_access(),
5337+
errmsg("could not fsync write-through log file %u, segment %u: %m",
5338+
openLogId,openLogSeg)));
5339+
break;
5340+
#endif
53375341
#ifdefHAVE_FDATASYNC
53385342
caseSYNC_METHOD_FDATASYNC:
53395343
if (pg_fdatasync(openLogFile)!=0)

‎src/backend/storage/file/fd.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.115 2004/12/31 22:00:51 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.116 2005/05/20 14:53:26 momjian Exp $
1111
*
1212
* NOTES:
1313
*
@@ -232,17 +232,51 @@ static void RemovePgTempFilesInDir(const char *tmpdirname);
232232

233233

234234
/*
235-
* pg_fsync ---same asfsyncexcept does nothing if enableFsync is off
235+
* pg_fsync ---dofsyncwith or without writethrough
236236
*/
237237
int
238238
pg_fsync(intfd)
239+
{
240+
#ifndefHAVE_FSYNC_WRITETHROUGH_ONLY
241+
if (sync_method!=SYNC_METHOD_FSYNC_WRITETHROUGH)
242+
returnpg_fsync_no_writethrough(fd);
243+
else
244+
#endif
245+
returnpg_fsync_writethrough(fd);
246+
}
247+
248+
249+
/*
250+
* pg_fsync_no_writethrough --- same as fsync except does nothing if
251+
*enableFsync is off
252+
*/
253+
int
254+
pg_fsync_no_writethrough(intfd)
239255
{
240256
if (enableFsync)
241257
returnfsync(fd);
242258
else
243259
return0;
244260
}
245261

262+
/*
263+
* pg_fsync_writethrough
264+
*/
265+
int
266+
pg_fsync_writethrough(intfd)
267+
{
268+
if (enableFsync)
269+
#ifdefWIN32
270+
return_commit(fd);
271+
#elif defined(__darwin__)
272+
return (fcntl(fd,F_FULLFSYNC,0)==-1) ?-1 :0;
273+
#else
274+
return-1;
275+
#endif
276+
else
277+
return0;
278+
}
279+
246280
/*
247281
* pg_fdatasync --- same as fdatasync except does nothing if enableFsync is off
248282
*

‎src/include/access/xlog.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.60 2005/04/28 21:47:17 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.61 2005/05/20 14:53:26 momjian Exp $
1010
*/
1111
#ifndefXLOG_H
1212
#defineXLOG_H
@@ -75,6 +75,13 @@ typedef struct XLogRecord
7575
*/
7676
#defineXLOG_NO_TRANXLR_INFO_MASK
7777

78+
/* Sync methods */
79+
#defineSYNC_METHOD_FSYNC0
80+
#defineSYNC_METHOD_FDATASYNC1
81+
#defineSYNC_METHOD_OPEN2/* for O_SYNC and O_DSYNC */
82+
#defineSYNC_METHOD_FSYNC_WRITETHROUGH3
83+
externintsync_method;
84+
7885
/*
7986
* List of these structs is used to pass data to XLogInsert().
8087
*

‎src/include/port/darwin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
#define__darwin__1
2+
3+
#defineHAVE_FSYNC_WRITETHROUGH
4+

‎src/include/port/win32.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.44 2005/03/24 04:36:19 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.45 2005/05/20 14:53:26 momjian Exp $ */
22

33
/* undefine and redefine after #include */
44
#undef mkdir
@@ -16,8 +16,8 @@
1616
#definemkdir(a,b)mkdir(a)
1717

1818

19-
#definefsync(a)_commit(a)
20-
#defineFSYNC_IS_WRITE_THROUGH
19+
#defineHAVE_FSYNC_WRITETHROUGH
20+
#defineHAVE_FSYNC_WRITETHROUGH_ONLY
2121
#defineftruncate(a,b)chsize(a,b)
2222

2323
#defineUSES_WINSOCK

‎src/include/storage/fd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/fd.h,v 1.50 2004/12/31 22:03:42 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/fd.h,v 1.51 2005/05/20 14:53:26 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -89,6 +89,8 @@ extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
8989
SubTransactionIdparentSubid);
9090
externvoidRemovePgTempFiles(void);
9191
externintpg_fsync(intfd);
92+
externintpg_fsync_no_writethrough(intfd);
93+
externintpg_fsync_writethrough(intfd);
9294
externintpg_fdatasync(intfd);
9395

9496
/* Filename components for OpenTemporaryFile */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp