|
7 | 7 | * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
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 $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
|
51 | 51 | * default method. We assume that fsync() is always available, and that
|
52 | 52 | * configure determined whether fdatasync() is.
|
53 | 53 | */
|
54 |
| -#define SYNC_METHOD_FSYNC 0 |
55 |
| -#define SYNC_METHOD_FDATASYNC 1 |
56 |
| -#define SYNC_METHOD_OPEN 2 /* used for both O_SYNC and |
57 |
| - * O_DSYNC */ |
58 |
| - |
59 | 54 | #if defined(O_SYNC)
|
60 | 55 | #define OPEN_SYNC_FLAG O_SYNC
|
61 | 56 | #else
|
|
79 | 74 | #define DEFAULT_SYNC_METHOD_STR "open_datasync"
|
80 | 75 | #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
|
81 | 76 | #define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
|
82 |
| -#else |
83 |
| -#if defined(HAVE_FDATASYNC) |
| 77 | +#elif defined(HAVE_FDATASYNC) |
84 | 78 | #define DEFAULT_SYNC_METHOD_STR "fdatasync"
|
85 | 79 | #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
|
86 | 80 | #define DEFAULT_SYNC_FLAGBIT 0
|
87 |
| -#else |
88 |
| -#ifndef FSYNC_IS_WRITE_THROUGH |
| 81 | +#elif !defined(HAVE_FSYNC_WRITETHROUGH_ONLY) |
89 | 82 | #define DEFAULT_SYNC_METHOD_STR "fsync"
|
| 83 | +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC |
| 84 | +#define DEFAULT_SYNC_FLAGBIT 0 |
90 | 85 | #else
|
91 | 86 | #define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
|
92 |
| -#endif |
93 |
| -#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC |
| 87 | +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH |
94 | 88 | #define DEFAULT_SYNC_FLAGBIT 0
|
95 | 89 | #endif
|
96 |
| -#endif |
97 | 90 |
|
98 | 91 |
|
99 | 92 | /* User-settable parameters */
|
@@ -122,7 +115,7 @@ bool XLOG_DEBUG = false;
|
122 | 115 |
|
123 | 116 |
|
124 | 117 | /* these are derived from XLOG_sync_method by assign_xlog_sync_method */
|
125 |
| -static int sync_method = DEFAULT_SYNC_METHOD; |
| 118 | +int sync_method = DEFAULT_SYNC_METHOD; |
126 | 119 | static int open_sync_bit = DEFAULT_SYNC_FLAGBIT;
|
127 | 120 |
|
128 | 121 | #define XLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
|
@@ -5249,16 +5242,18 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
|
5249 | 5242 | int new_sync_method;
|
5250 | 5243 | int new_sync_bit;
|
5251 | 5244 |
|
5252 |
| -#ifndef FSYNC_IS_WRITE_THROUGH |
5253 | 5245 | 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 |
5258 | 5246 | {
|
5259 | 5247 | new_sync_method = SYNC_METHOD_FSYNC;
|
5260 | 5248 | new_sync_bit = 0;
|
5261 | 5249 | }
|
| 5250 | +#ifdef HAVE_FSYNC_WRITETHROUGH |
| 5251 | + else if (pg_strcasecmp(method, "fsync_writethrough") == 0) |
| 5252 | + { |
| 5253 | + new_sync_method = SYNC_METHOD_FSYNC_WRITETHROUGH; |
| 5254 | + new_sync_bit = 0; |
| 5255 | + } |
| 5256 | +#endif |
5262 | 5257 | #ifdef HAVE_FDATASYNC
|
5263 | 5258 | else if (pg_strcasecmp(method, "fdatasync") == 0)
|
5264 | 5259 | {
|
@@ -5328,12 +5323,21 @@ issue_xlog_fsync(void)
|
5328 | 5323 | switch (sync_method)
|
5329 | 5324 | {
|
5330 | 5325 | case SYNC_METHOD_FSYNC:
|
5331 |
| - if (pg_fsync(openLogFile) != 0) |
| 5326 | + if (pg_fsync_no_writethrough(openLogFile) != 0) |
5332 | 5327 | ereport(PANIC,
|
5333 | 5328 | (errcode_for_file_access(),
|
5334 | 5329 | errmsg("could not fsync log file %u, segment %u: %m",
|
5335 | 5330 | openLogId, openLogSeg)));
|
5336 | 5331 | break;
|
| 5332 | +#ifdef HAVE_FSYNC_WRITETHROUGH |
| 5333 | + case SYNC_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 |
5337 | 5341 | #ifdef HAVE_FDATASYNC
|
5338 | 5342 | case SYNC_METHOD_FDATASYNC:
|
5339 | 5343 | if (pg_fdatasync(openLogFile) != 0)
|
|
0 commit comments