Commit f99760c1 authored by Magnus Hagander's avatar Magnus Hagander

Convert wal_sync_method to guc enum.

parent f8c4d7db
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.303 2008/05/12 00:00:46 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.304 2008/05/12 08:35:05 mha Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -66,8 +66,6 @@ int XLOGbuffers = 8; ...@@ -66,8 +66,6 @@ int XLOGbuffers = 8;
int XLogArchiveTimeout = 0; int XLogArchiveTimeout = 0;
bool XLogArchiveMode = false; bool XLogArchiveMode = false;
char *XLogArchiveCommand = NULL; char *XLogArchiveCommand = NULL;
char *XLOG_sync_method = NULL;
const char XLOG_sync_method_default[] = DEFAULT_SYNC_METHOD_STR;
bool fullPageWrites = true; bool fullPageWrites = true;
bool log_checkpoints = false; bool log_checkpoints = false;
...@@ -95,6 +93,25 @@ static int open_sync_bit = DEFAULT_SYNC_FLAGBIT; ...@@ -95,6 +93,25 @@ static int open_sync_bit = DEFAULT_SYNC_FLAGBIT;
#define XLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0) #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. * Statistics for current checkpoint are collected in this global struct.
...@@ -1601,7 +1618,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch) ...@@ -1601,7 +1618,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
* have no open file or the wrong one. However, we do not need to * have no open file or the wrong one. However, we do not need to
* fsync more than one file. * fsync more than one file.
*/ */
if (sync_method != SYNC_METHOD_OPEN) if (sync_method != SYNC_METHOD_OPEN && sync_method != SYNC_METHOD_OPEN_DSYNC)
{ {
if (openLogFile >= 0 && if (openLogFile >= 0 &&
!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg)) !XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
...@@ -6314,50 +6331,46 @@ xlog_outrec(StringInfo buf, XLogRecord *record) ...@@ -6314,50 +6331,46 @@ xlog_outrec(StringInfo buf, XLogRecord *record)
/* /*
* GUC support * GUC support
*/ */
const char * bool
assign_xlog_sync_method(const char *method, bool doit, GucSource source) assign_xlog_sync_method(int new_sync_method, bool doit, GucSource source)
{ {
int new_sync_method; int new_sync_bit = 0;
int new_sync_bit;
if (pg_strcasecmp(method, "fsync") == 0) switch (new_sync_method)
{ {
new_sync_method = SYNC_METHOD_FSYNC; /*
new_sync_bit = 0; * Values for these sync options are defined even if they are not
} * supported on the current platform. They are not included in
#ifdef HAVE_FSYNC_WRITETHROUGH * the enum option array, and therefor will never be set if the
else if (pg_strcasecmp(method, "fsync_writethrough") == 0) * platform doesn't support it.
{ */
new_sync_method = SYNC_METHOD_FSYNC_WRITETHROUGH; case SYNC_METHOD_FSYNC:
new_sync_bit = 0; case SYNC_METHOD_FSYNC_WRITETHROUGH:
} case SYNC_METHOD_FDATASYNC:
#endif
#ifdef HAVE_FDATASYNC
else if (pg_strcasecmp(method, "fdatasync") == 0)
{
new_sync_method = SYNC_METHOD_FDATASYNC;
new_sync_bit = 0; new_sync_bit = 0;
} break;
#endif
#ifdef OPEN_SYNC_FLAG #ifdef OPEN_SYNC_FLAG
else if (pg_strcasecmp(method, "open_sync") == 0) case SYNC_METHOD_OPEN:
{
new_sync_method = SYNC_METHOD_OPEN;
new_sync_bit = OPEN_SYNC_FLAG; new_sync_bit = OPEN_SYNC_FLAG;
} break;
#endif #endif
#ifdef OPEN_DATASYNC_FLAG #ifdef OPEN_DATASYNC_FLAG
else if (pg_strcasecmp(method, "open_datasync") == 0) case SYNC_METHOD_OPEN_DSYNC:
{
new_sync_method = SYNC_METHOD_OPEN;
new_sync_bit = OPEN_DATASYNC_FLAG; new_sync_bit = OPEN_DATASYNC_FLAG;
} break;
#endif #endif
else default:
return NULL; /*
* This "can never happen", since the available values in
* new_sync_method are controlled by the available enum
* options.
*/
elog(PANIC, "unrecognized wal_sync_method: %d", sync_method);
break;
}
if (!doit) if (!doit)
return method; return true;
if (sync_method != new_sync_method || open_sync_bit != new_sync_bit) if (sync_method != new_sync_method || open_sync_bit != new_sync_bit)
{ {
...@@ -6381,7 +6394,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source) ...@@ -6381,7 +6394,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
open_sync_bit = new_sync_bit; open_sync_bit = new_sync_bit;
} }
return method; return true;
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.452 2008/05/12 00:00:52 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.453 2008/05/12 08:35:05 mha Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
...@@ -270,6 +270,11 @@ static const struct config_enum_entry backslash_quote_options[] = { ...@@ -270,6 +270,11 @@ static const struct config_enum_entry backslash_quote_options[] = {
{NULL, 0} {NULL, 0}
}; };
/*
* 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 * GUC option variables that are exported from this module
*/ */
...@@ -2327,15 +2332,6 @@ static struct config_string ConfigureNamesString[] = ...@@ -2327,15 +2332,6 @@ static struct config_string ConfigureNamesString[] =
"localhost", NULL, NULL "localhost", NULL, NULL
}, },
{
{"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, {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
gettext_noop("Sets the list of known custom variable classes."), gettext_noop("Sets the list of known custom variable classes."),
...@@ -2528,6 +2524,16 @@ static struct config_enum ConfigureNamesEnum[] = ...@@ -2528,6 +2524,16 @@ static struct config_enum ConfigureNamesEnum[] =
assign_session_replication_role, NULL assign_session_replication_role, NULL
}, },
{
{"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, {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
gettext_noop("Sets how binary values are to be encoded in XML."), gettext_noop("Sets how binary values are to be encoded in XML."),
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.87 2008/01/01 19:45:56 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.88 2008/05/12 08:35:05 mha Exp $
*/ */
#ifndef XLOG_H #ifndef XLOG_H
#define XLOG_H #define XLOG_H
...@@ -88,8 +88,9 @@ typedef struct XLogRecord ...@@ -88,8 +88,9 @@ typedef struct XLogRecord
/* Sync methods */ /* Sync methods */
#define SYNC_METHOD_FSYNC 0 #define SYNC_METHOD_FSYNC 0
#define SYNC_METHOD_FDATASYNC 1 #define SYNC_METHOD_FDATASYNC 1
#define SYNC_METHOD_OPEN 2 /* for O_SYNC and O_DSYNC */ #define SYNC_METHOD_OPEN 2 /* for O_SYNC */
#define SYNC_METHOD_FSYNC_WRITETHROUGH 3 #define SYNC_METHOD_FSYNC_WRITETHROUGH 3
#define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */
extern int sync_method; extern int sync_method;
/* /*
...@@ -141,8 +142,6 @@ extern int XLOGbuffers; ...@@ -141,8 +142,6 @@ extern int XLOGbuffers;
extern bool XLogArchiveMode; extern bool XLogArchiveMode;
extern char *XLogArchiveCommand; extern char *XLogArchiveCommand;
extern int XLogArchiveTimeout; extern int XLogArchiveTimeout;
extern char *XLOG_sync_method;
extern const char XLOG_sync_method_default[];
extern bool log_checkpoints; extern bool log_checkpoints;
#define XLogArchivingActive() (XLogArchiveMode) #define XLogArchivingActive() (XLogArchiveMode)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.19 2008/01/01 19:45:56 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.20 2008/05/12 08:35:05 mha Exp $
*/ */
#ifndef XLOG_DEFS_H #ifndef XLOG_DEFS_H
#define XLOG_DEFS_H #define XLOG_DEFS_H
...@@ -109,19 +109,15 @@ typedef uint32 TimeLineID; ...@@ -109,19 +109,15 @@ typedef uint32 TimeLineID;
#endif #endif
#if defined(OPEN_DATASYNC_FLAG) #if defined(OPEN_DATASYNC_FLAG)
#define DEFAULT_SYNC_METHOD_STR "open_datasync" #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG #define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
#elif defined(HAVE_FDATASYNC) #elif defined(HAVE_FDATASYNC)
#define DEFAULT_SYNC_METHOD_STR "fdatasync"
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
#define DEFAULT_SYNC_FLAGBIT 0 #define DEFAULT_SYNC_FLAGBIT 0
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY) #elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
#define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
#define DEFAULT_SYNC_FLAGBIT 0 #define DEFAULT_SYNC_FLAGBIT 0
#else #else
#define DEFAULT_SYNC_METHOD_STR "fsync"
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
#define DEFAULT_SYNC_FLAGBIT 0 #define DEFAULT_SYNC_FLAGBIT 0
#endif #endif
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 2000-2008, PostgreSQL Global Development Group * Copyright (c) 2000-2008, PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.94 2008/04/18 01:42:17 tgl Exp $ * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.95 2008/05/12 08:35:05 mha Exp $
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
#ifndef GUC_H #ifndef GUC_H
...@@ -267,7 +267,7 @@ extern const char *assign_search_path(const char *newval, ...@@ -267,7 +267,7 @@ extern const char *assign_search_path(const char *newval,
bool doit, GucSource source); bool doit, GucSource source);
/* in access/transam/xlog.c */ /* in access/transam/xlog.c */
extern const char *assign_xlog_sync_method(const char *method, extern bool assign_xlog_sync_method(int newval,
bool doit, GucSource source); bool doit, GucSource source);
#endif /* GUC_H */ #endif /* GUC_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment