Attached patch implements wal_sync_method as an enum. I'd like someone
to look it over before I apply it - I don't have the machines to test
all codepaths (and some of it is hard to test - better to read it and
make sure it's right).
In order to implement the enum guc, I had to break out a new
SYNC_METHOD_OPEN_DSYNC out of SYNC_METHOD_OPEN where it was previously
overloaded. This is one of the parts where I'm slightly worried I have
made a mistake.
//Magnus
Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.296
diff -c -r1.296 xlog.c
*** src/backend/access/transam/xlog.c 5 Apr 2008 01:34:06 -0000 1.296
--- src/backend/access/transam/xlog.c 7 Apr 2008 10:20:58 -0000
***************
*** 65,72 ****
int XLogArchiveTimeout = 0;
bool XLogArchiveMode = false;
char *XLogArchiveCommand = NULL;
- char *XLOG_sync_method = NULL;
- const char XLOG_sync_method_default[] = DEFAULT_SYNC_METHOD_STR;
bool fullPageWrites = true;
bool log_checkpoints = false;
--- 65,70 ----
***************
*** 94,99 ****
--- 92,116 ----
#define XLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
+ /*
+ * GUC support
+ */
+ const struct config_enum_entry sync_method_options[] = {
+ {"fsync", SYNC_METHOD_FSYNC},
+ #ifdef HAVE_FSYNC_WRITETHROUGH
+ {"fsync_writethrough", SYNC_METHOD_FSYNC_WRITETHROUGH},
+ #endif
+ #ifdef HAVE_FDATASYNC
+ {"fdatasync", SYNC_METHOD_FDATASYNC},
+ #endif
+ #ifdef OPEN_SYNC_FLAG
+ {"open_sync", SYNC_METHOD_OPEN},
+ #endif
+ #ifdef OPEN_DATASYNC_FLAG
+ {"open_datasync", SYNC_METHOD_OPEN_DSYNC},
+ #endif
+ {NULL, 0}
+ };
/*
* Statistics for current checkpoint are collected in this global struct.
***************
*** 1600,1606 ****
* have no open file or the wrong one. However, we do not need to
* fsync more than one file.
*/
! if (sync_method != SYNC_METHOD_OPEN)
{
if (openLogFile >= 0 &&
!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
--- 1617,1623 ----
* have no open file or the wrong one. However, we do not need to
* fsync more than one file.
*/
! if (sync_method != SYNC_METHOD_OPEN && sync_method != SYNC_METHOD_OPEN_DSYNC)
{
if (openLogFile >= 0 &&
!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
***************
*** 6255,6304 ****
/*
* GUC support
*/
! const char *
! assign_xlog_sync_method(const char *method, bool doit, GucSource source)
{
! int new_sync_method;
! int new_sync_bit;
! if (pg_strcasecmp(method, "fsync") == 0)
! {
! new_sync_method = SYNC_METHOD_FSYNC;
! new_sync_bit = 0;
! }
! #ifdef HAVE_FSYNC_WRITETHROUGH
! else if (pg_strcasecmp(method, "fsync_writethrough") == 0)
! {
! new_sync_method = SYNC_METHOD_FSYNC_WRITETHROUGH;
! new_sync_bit = 0;
! }
! #endif
! #ifdef HAVE_FDATASYNC
! else if (pg_strcasecmp(method, "fdatasync") == 0)
{
! new_sync_method = SYNC_METHOD_FDATASYNC;
! new_sync_bit = 0;
! }
! #endif
#ifdef OPEN_SYNC_FLAG
! else if (pg_strcasecmp(method, "open_sync") == 0)
! {
! new_sync_method = SYNC_METHOD_OPEN;
! new_sync_bit = OPEN_SYNC_FLAG;
! }
#endif
#ifdef OPEN_DATASYNC_FLAG
! else if (pg_strcasecmp(method, "open_datasync") == 0)
! {
! new_sync_method = SYNC_METHOD_OPEN;
! new_sync_bit = OPEN_DATASYNC_FLAG;
! }
#endif
! else
! return NULL;
if (!doit)
! return method;
if (sync_method != new_sync_method || open_sync_bit != new_sync_bit)
{
--- 6272,6305 ----
/*
* GUC support
*/
! bool
! assign_xlog_sync_method(int new_sync_method, bool doit, GucSource source)
{
! int new_sync_bit = 0;
! switch (new_sync_method)
{
! case SYNC_METHOD_FSYNC:
! case SYNC_METHOD_FSYNC_WRITETHROUGH:
! case SYNC_METHOD_FDATASYNC:
! new_sync_bit = 0;
! break;
#ifdef OPEN_SYNC_FLAG
! case SYNC_METHOD_OPEN:
! new_sync_bit = OPEN_SYNC_FLAG;
! break;
#endif
#ifdef OPEN_DATASYNC_FLAG
! case SYNC_METHOD_OPEN_DSYNC:
! new_sync_bit = OPEN_DATASYNC_FLAG;
! break;
#endif
! default:
! ereport(PANIC, (errmsg("FIXME")));
! }
if (!doit)
! return true;
if (sync_method != new_sync_method || open_sync_bit != new_sync_bit)
{
***************
*** 6322,6328 ****
open_sync_bit = new_sync_bit;
}
! return method;
}
--- 6323,6329 ----
open_sync_bit = new_sync_bit;
}
! return true;
}
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.446
diff -c -r1.446 guc.c
*** src/backend/utils/misc/guc.c 4 Apr 2008 17:25:23 -0000 1.446
--- src/backend/utils/misc/guc.c 7 Apr 2008 10:20:58 -0000
***************
*** 270,275 ****
--- 270,280 ----
};
/*
+ * Options for enum values stored in other modules
+ */
+ extern const struct config_enum_entry sync_method_options[];
+
+ /*
* GUC option variables that are exported from this module
*/
#ifdef USE_ASSERT_CHECKING
***************
*** 2327,2341 ****
},
{
- {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
- gettext_noop("Selects the method used for forcing WAL updates to disk."),
- NULL
- },
- &XLOG_sync_method,
- XLOG_sync_method_default, assign_xlog_sync_method, NULL
- },
-
- {
{"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
gettext_noop("Sets the list of known custom variable classes."),
NULL,
--- 2332,2337 ----
***************
*** 2528,2533 ****
--- 2524,2539 ----
},
{
+ {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
+ gettext_noop("Selects the method used for forcing WAL updates to disk."),
+ NULL
+ },
+ &sync_method,
+ DEFAULT_SYNC_METHOD, sync_method_options,
+ assign_xlog_sync_method, NULL
+ },
+
+ {
{"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
gettext_noop("Sets how binary values are to be encoded in XML."),
gettext_noop("Valid values are BASE64 and HEX.")
Index: src/include/access/xlog.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/access/xlog.h,v
retrieving revision 1.87
diff -c -r1.87 xlog.h
*** src/include/access/xlog.h 1 Jan 2008 19:45:56 -0000 1.87
--- src/include/access/xlog.h 7 Apr 2008 10:20:58 -0000
***************
*** 88,95 ****
/* Sync methods */
#define SYNC_METHOD_FSYNC 0
#define SYNC_METHOD_FDATASYNC 1
! #define SYNC_METHOD_OPEN 2 /* for O_SYNC and O_DSYNC */
#define SYNC_METHOD_FSYNC_WRITETHROUGH 3
extern int sync_method;
/*
--- 88,96 ----
/* Sync methods */
#define SYNC_METHOD_FSYNC 0
#define SYNC_METHOD_FDATASYNC 1
! #define SYNC_METHOD_OPEN 2 /* for O_SYNC */
#define SYNC_METHOD_FSYNC_WRITETHROUGH 3
+ #define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */
extern int sync_method;
/*
***************
*** 141,148 ****
extern bool XLogArchiveMode;
extern char *XLogArchiveCommand;
extern int XLogArchiveTimeout;
- extern char *XLOG_sync_method;
- extern const char XLOG_sync_method_default[];
extern bool log_checkpoints;
#define XLogArchivingActive() (XLogArchiveMode)
--- 142,147 ----
Index: src/include/access/xlogdefs.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/access/xlogdefs.h,v
retrieving revision 1.19
diff -c -r1.19 xlogdefs.h
*** src/include/access/xlogdefs.h 1 Jan 2008 19:45:56 -0000 1.19
--- src/include/access/xlogdefs.h 7 Apr 2008 10:20:58 -0000
***************
*** 109,127 ****
#endif
#if defined(OPEN_DATASYNC_FLAG)
! #define DEFAULT_SYNC_METHOD_STR "open_datasync"
! #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
#elif defined(HAVE_FDATASYNC)
- #define DEFAULT_SYNC_METHOD_STR "fdatasync"
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
#define DEFAULT_SYNC_FLAGBIT 0
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
- #define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
#define DEFAULT_SYNC_FLAGBIT 0
#else
- #define DEFAULT_SYNC_METHOD_STR "fsync"
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
#define DEFAULT_SYNC_FLAGBIT 0
#endif
--- 109,123 ----
#endif
#if defined(OPEN_DATASYNC_FLAG)
! #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
#elif defined(HAVE_FDATASYNC)
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
#define DEFAULT_SYNC_FLAGBIT 0
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
#define DEFAULT_SYNC_FLAGBIT 0
#else
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
#define DEFAULT_SYNC_FLAGBIT 0
#endif
Index: src/include/utils/guc.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/utils/guc.h,v
retrieving revision 1.93
diff -c -r1.93 guc.h
*** src/include/utils/guc.h 2 Apr 2008 14:42:56 -0000 1.93
--- src/include/utils/guc.h 7 Apr 2008 10:20:58 -0000
***************
*** 268,274 ****
bool doit, GucSource source);
/* in access/transam/xlog.c */
! extern const char *assign_xlog_sync_method(const char *method,
! bool doit, GucSource source);
#endif /* GUC_H */
--- 268,274 ----
bool doit, GucSource source);
/* in access/transam/xlog.c */
! extern bool assign_xlog_sync_method(int newval,
! bool doit, GucSource source);
#endif /* GUC_H */
--
Sent via pgsql-patches mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches