Skip to content

Commit f99760c

Browse files
committed
Convert wal_sync_method to guc enum.
1 parent f8c4d7d commit f99760c

File tree

5 files changed

+77
-63
lines changed

5 files changed

+77
-63
lines changed

src/backend/access/transam/xlog.c

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, 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.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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -66,8 +66,6 @@ int XLOGbuffers = 8;
6666
int XLogArchiveTimeout = 0;
6767
bool XLogArchiveMode = false;
6868
char *XLogArchiveCommand = NULL;
69-
char *XLOG_sync_method = NULL;
70-
const char XLOG_sync_method_default[] = DEFAULT_SYNC_METHOD_STR;
7169
bool fullPageWrites = true;
7270
bool log_checkpoints = false;
7371

@@ -95,6 +93,25 @@ static int open_sync_bit = DEFAULT_SYNC_FLAGBIT;
9593

9694
#define XLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
9795

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+
};
98115

99116
/*
100117
* Statistics for current checkpoint are collected in this global struct.
@@ -1601,7 +1618,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
16011618
* have no open file or the wrong one. However, we do not need to
16021619
* fsync more than one file.
16031620
*/
1604-
if (sync_method != SYNC_METHOD_OPEN)
1621+
if (sync_method != SYNC_METHOD_OPEN && sync_method != SYNC_METHOD_OPEN_DSYNC)
16051622
{
16061623
if (openLogFile >= 0 &&
16071624
!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
@@ -6314,50 +6331,46 @@ xlog_outrec(StringInfo buf, XLogRecord *record)
63146331
/*
63156332
* GUC support
63166333
*/
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)
63196336
{
6320-
int new_sync_method;
6321-
int new_sync_bit;
6337+
int new_sync_bit = 0;
63226338

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)
63376340
{
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;
63426352
#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;
63486356
#endif
63496357
#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;
63556361
#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+
}
63586371

63596372
if (!doit)
6360-
return method;
6373+
return true;
63616374

63626375
if (sync_method != new_sync_method || open_sync_bit != new_sync_bit)
63636376
{
@@ -6381,7 +6394,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
63816394
open_sync_bit = new_sync_bit;
63826395
}
63836396

6384-
return method;
6397+
return true;
63856398
}
63866399

63876400

src/backend/utils/misc/guc.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.452 2008/05/12 00:00:52 alvherre Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.453 2008/05/12 08:35:05 mha Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -270,6 +270,11 @@ static const struct config_enum_entry backslash_quote_options[] = {
270270
{NULL, 0}
271271
};
272272

273+
/*
274+
* Options for enum values stored in other modules
275+
*/
276+
extern const struct config_enum_entry sync_method_options[];
277+
273278
/*
274279
* GUC option variables that are exported from this module
275280
*/
@@ -2327,15 +2332,6 @@ static struct config_string ConfigureNamesString[] =
23272332
"localhost", NULL, NULL
23282333
},
23292334

2330-
{
2331-
{"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2332-
gettext_noop("Selects the method used for forcing WAL updates to disk."),
2333-
NULL
2334-
},
2335-
&XLOG_sync_method,
2336-
XLOG_sync_method_default, assign_xlog_sync_method, NULL
2337-
},
2338-
23392335
{
23402336
{"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
23412337
gettext_noop("Sets the list of known custom variable classes."),
@@ -2528,6 +2524,16 @@ static struct config_enum ConfigureNamesEnum[] =
25282524
assign_session_replication_role, NULL
25292525
},
25302526

2527+
{
2528+
{"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2529+
gettext_noop("Selects the method used for forcing WAL updates to disk."),
2530+
NULL
2531+
},
2532+
&sync_method,
2533+
DEFAULT_SYNC_METHOD, sync_method_options,
2534+
assign_xlog_sync_method, NULL
2535+
},
2536+
25312537
{
25322538
{"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
25332539
gettext_noop("Sets how binary values are to be encoded in XML."),

src/include/access/xlog.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2008, 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.87 2008/01/01 19:45:56 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.88 2008/05/12 08:35:05 mha Exp $
1010
*/
1111
#ifndef XLOG_H
1212
#define XLOG_H
@@ -88,8 +88,9 @@ typedef struct XLogRecord
8888
/* Sync methods */
8989
#define SYNC_METHOD_FSYNC 0
9090
#define SYNC_METHOD_FDATASYNC 1
91-
#define SYNC_METHOD_OPEN 2 /* for O_SYNC and O_DSYNC */
91+
#define SYNC_METHOD_OPEN 2 /* for O_SYNC */
9292
#define SYNC_METHOD_FSYNC_WRITETHROUGH 3
93+
#define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */
9394
extern int sync_method;
9495

9596
/*
@@ -141,8 +142,6 @@ extern int XLOGbuffers;
141142
extern bool XLogArchiveMode;
142143
extern char *XLogArchiveCommand;
143144
extern int XLogArchiveTimeout;
144-
extern char *XLOG_sync_method;
145-
extern const char XLOG_sync_method_default[];
146145
extern bool log_checkpoints;
147146

148147
#define XLogArchivingActive() (XLogArchiveMode)

src/include/access/xlogdefs.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.19 2008/01/01 19:45:56 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.20 2008/05/12 08:35:05 mha Exp $
1111
*/
1212
#ifndef XLOG_DEFS_H
1313
#define XLOG_DEFS_H
@@ -109,19 +109,15 @@ typedef uint32 TimeLineID;
109109
#endif
110110

111111
#if defined(OPEN_DATASYNC_FLAG)
112-
#define DEFAULT_SYNC_METHOD_STR "open_datasync"
113-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
112+
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
114113
#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
115114
#elif defined(HAVE_FDATASYNC)
116-
#define DEFAULT_SYNC_METHOD_STR "fdatasync"
117115
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
118116
#define DEFAULT_SYNC_FLAGBIT 0
119117
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
120-
#define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
121118
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
122119
#define DEFAULT_SYNC_FLAGBIT 0
123120
#else
124-
#define DEFAULT_SYNC_METHOD_STR "fsync"
125121
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
126122
#define DEFAULT_SYNC_FLAGBIT 0
127123
#endif

src/include/utils/guc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.94 2008/04/18 01:42:17 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.95 2008/05/12 08:35:05 mha Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndef GUC_H
@@ -267,7 +267,7 @@ extern const char *assign_search_path(const char *newval,
267267
bool doit, GucSource source);
268268

269269
/* in access/transam/xlog.c */
270-
extern const char *assign_xlog_sync_method(const char *method,
271-
bool doit, GucSource source);
270+
extern bool assign_xlog_sync_method(int newval,
271+
bool doit, GucSource source);
272272

273273
#endif /* GUC_H */

0 commit comments

Comments
 (0)