7
7
* Portions Copyright (c) 1996-2008, 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.303 2008/05/12 00:00:46 alvherre Exp $
10
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.304 2008/05/12 08:35:05 mha Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -66,8 +66,6 @@ int XLOGbuffers = 8;
66
66
int XLogArchiveTimeout = 0 ;
67
67
bool XLogArchiveMode = false;
68
68
char * XLogArchiveCommand = NULL ;
69
- char * XLOG_sync_method = NULL ;
70
- const char XLOG_sync_method_default [] = DEFAULT_SYNC_METHOD_STR ;
71
69
bool fullPageWrites = true;
72
70
bool log_checkpoints = false;
73
71
@@ -95,6 +93,25 @@ static int open_sync_bit = DEFAULT_SYNC_FLAGBIT;
95
93
96
94
#define XLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
97
95
96
+ /*
97
+ * GUC support
98
+ */
99
+ const struct config_enum_entry sync_method_options [] = {
100
+ {"fsync" , SYNC_METHOD_FSYNC },
101
+ #ifdef HAVE_FSYNC_WRITETHROUGH
102
+ {"fsync_writethrough" , SYNC_METHOD_FSYNC_WRITETHROUGH },
103
+ #endif
104
+ #ifdef HAVE_FDATASYNC
105
+ {"fdatasync" , SYNC_METHOD_FDATASYNC },
106
+ #endif
107
+ #ifdef OPEN_SYNC_FLAG
108
+ {"open_sync" , SYNC_METHOD_OPEN },
109
+ #endif
110
+ #ifdef OPEN_DATASYNC_FLAG
111
+ {"open_datasync" , SYNC_METHOD_OPEN_DSYNC },
112
+ #endif
113
+ {NULL , 0 }
114
+ };
98
115
99
116
/*
100
117
* Statistics for current checkpoint are collected in this global struct.
@@ -1601,7 +1618,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
1601
1618
* have no open file or the wrong one. However, we do not need to
1602
1619
* fsync more than one file.
1603
1620
*/
1604
- if (sync_method != SYNC_METHOD_OPEN )
1621
+ if (sync_method != SYNC_METHOD_OPEN && sync_method != SYNC_METHOD_OPEN_DSYNC )
1605
1622
{
1606
1623
if (openLogFile >= 0 &&
1607
1624
!XLByteInPrevSeg (LogwrtResult .Write , openLogId , openLogSeg ))
@@ -6314,50 +6331,46 @@ xlog_outrec(StringInfo buf, XLogRecord *record)
6314
6331
/*
6315
6332
* GUC support
6316
6333
*/
6317
- const char *
6318
- assign_xlog_sync_method (const char * method , bool doit , GucSource source )
6334
+ bool
6335
+ assign_xlog_sync_method (int new_sync_method , bool doit , GucSource source )
6319
6336
{
6320
- int new_sync_method ;
6321
- int new_sync_bit ;
6337
+ int new_sync_bit = 0 ;
6322
6338
6323
- if (pg_strcasecmp (method , "fsync" ) == 0 )
6324
- {
6325
- new_sync_method = SYNC_METHOD_FSYNC ;
6326
- new_sync_bit = 0 ;
6327
- }
6328
- #ifdef HAVE_FSYNC_WRITETHROUGH
6329
- else if (pg_strcasecmp (method , "fsync_writethrough ") == 0 )
6330
- {
6331
- new_sync_method = SYNC_METHOD_FSYNC_WRITETHROUGH ;
6332
- new_sync_bit = 0 ;
6333
- }
6334
- #endif
6335
- #ifdef HAVE_FDATASYNC
6336
- else if (pg_strcasecmp (method , "fdatasync ") == 0 )
6339
+ switch (new_sync_method )
6337
6340
{
6338
- new_sync_method = SYNC_METHOD_FDATASYNC ;
6339
- new_sync_bit = 0 ;
6340
- }
6341
- #endif
6341
+ /*
6342
+ * Values for these sync options are defined even if they are not
6343
+ * supported on the current platform. They are not included in
6344
+ * the enum option array, and therefor will never be set if the
6345
+ * platform doesn't support it.
6346
+ */
6347
+ case SYNC_METHOD_FSYNC :
6348
+ case SYNC_METHOD_FSYNC_WRITETHROUGH :
6349
+ case SYNC_METHOD_FDATASYNC :
6350
+ new_sync_bit = 0 ;
6351
+ break ;
6342
6352
#ifdef OPEN_SYNC_FLAG
6343
- else if (pg_strcasecmp (method , "open_sync ") == 0 )
6344
- {
6345
- new_sync_method = SYNC_METHOD_OPEN ;
6346
- new_sync_bit = OPEN_SYNC_FLAG ;
6347
- }
6353
+ case SYNC_METHOD_OPEN :
6354
+ new_sync_bit = OPEN_SYNC_FLAG ;
6355
+ break ;
6348
6356
#endif
6349
6357
#ifdef OPEN_DATASYNC_FLAG
6350
- else if (pg_strcasecmp (method , "open_datasync ") == 0 )
6351
- {
6352
- new_sync_method = SYNC_METHOD_OPEN ;
6353
- new_sync_bit = OPEN_DATASYNC_FLAG ;
6354
- }
6358
+ case SYNC_METHOD_OPEN_DSYNC :
6359
+ new_sync_bit = OPEN_DATASYNC_FLAG ;
6360
+ break ;
6355
6361
#endif
6356
- else
6357
- return NULL ;
6362
+ default :
6363
+ /*
6364
+ * This "can never happen", since the available values in
6365
+ * new_sync_method are controlled by the available enum
6366
+ * options.
6367
+ */
6368
+ elog (PANIC , "unrecognized wal_sync_method: %d" , sync_method );
6369
+ break ;
6370
+ }
6358
6371
6359
6372
if (!doit )
6360
- return method ;
6373
+ return true ;
6361
6374
6362
6375
if (sync_method != new_sync_method || open_sync_bit != new_sync_bit )
6363
6376
{
@@ -6381,7 +6394,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
6381
6394
open_sync_bit = new_sync_bit ;
6382
6395
}
6383
6396
6384
- return method ;
6397
+ return true ;
6385
6398
}
6386
6399
6387
6400
0 commit comments