OSDN Git Service

Convert wal_sync_method to guc enum.
authorMagnus Hagander <magnus@hagander.net>
Mon, 12 May 2008 08:35:05 +0000 (08:35 +0000)
committerMagnus Hagander <magnus@hagander.net>
Mon, 12 May 2008 08:35:05 +0000 (08:35 +0000)
src/backend/access/transam/xlog.c
src/backend/utils/misc/guc.c
src/include/access/xlog.h
src/include/access/xlogdefs.h
src/include/utils/guc.h

index d056422..a8cbc58 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * 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;
 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;
 
@@ -95,6 +93,25 @@ static int   open_sync_bit = DEFAULT_SYNC_FLAGBIT;
 
 #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.
@@ -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
                 * 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 &&
                                !XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
@@ -6314,50 +6331,46 @@ xlog_outrec(StringInfo buf, XLogRecord *record)
 /*
  * GUC support
  */
-const char *
-assign_xlog_sync_method(const char *method, bool doit, GucSource source)
+bool
+assign_xlog_sync_method(int new_sync_method, bool doit, GucSource source)
 {
-       int                     new_sync_method;
-       int                     new_sync_bit;
+       int                     new_sync_bit = 0;
 
-       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)
+       switch (new_sync_method)
        {
-               new_sync_method = SYNC_METHOD_FDATASYNC;
-               new_sync_bit = 0;
-       }
-#endif
+               /*
+                * Values for these sync options are defined even if they are not
+                * supported on the current platform. They are not included in
+                * the enum option array, and therefor will never be set if the
+                * platform doesn't support it.
+                */
+               case SYNC_METHOD_FSYNC:
+               case SYNC_METHOD_FSYNC_WRITETHROUGH:
+               case SYNC_METHOD_FDATASYNC:
+                       new_sync_bit = 0;
+                       break;
 #ifdef OPEN_SYNC_FLAG
-       else if (pg_strcasecmp(method, "open_sync") == 0)
-       {
-               new_sync_method = SYNC_METHOD_OPEN;
-               new_sync_bit = OPEN_SYNC_FLAG;
-       }
+               case SYNC_METHOD_OPEN:
+                       new_sync_bit = OPEN_SYNC_FLAG;
+                       break;
 #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;
-       }
+               case SYNC_METHOD_OPEN_DSYNC:
+                       new_sync_bit = OPEN_DATASYNC_FLAG;
+               break;
 #endif
-       else
-               return NULL;
+               default:
+                       /* 
+                        * 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)
-               return method;
+               return true;
 
        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)
                open_sync_bit = new_sync_bit;
        }
 
-       return method;
+       return true;
 }
 
 
index c39f275..c4b07aa 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut <peter_e@gmx.net>.
  *
  * 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 $
  *
  *--------------------------------------------------------------------
  */
@@ -271,6 +271,11 @@ static const struct config_enum_entry backslash_quote_options[] = {
 };
 
 /*
+ * 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
@@ -2328,15 +2333,6 @@ static struct config_string ConfigureNamesString[] =
        },
 
        {
-               {"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,
@@ -2529,6 +2525,16 @@ static struct config_enum ConfigureNamesEnum[] =
        },
 
        {
+               {"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 3e3163c..a3e8c2f 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * 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
 #define XLOG_H
@@ -88,8 +88,9 @@ typedef struct XLogRecord
 /* 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_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,8 +142,6 @@ extern int  XLOGbuffers;
 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)
index 4129025..17b3e51 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * 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
 #define XLOG_DEFS_H
@@ -109,19 +109,15 @@ typedef uint32 TimeLineID;
 #endif
 
 #if defined(OPEN_DATASYNC_FLAG)
-#define DEFAULT_SYNC_METHOD_STR "open_datasync"
-#define DEFAULT_SYNC_METHOD            SYNC_METHOD_OPEN
+#define DEFAULT_SYNC_METHOD            SYNC_METHOD_OPEN_DSYNC
 #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
index b610355..fc737ec 100644 (file)
@@ -7,7 +7,7 @@
  * Copyright (c) 2000-2008, PostgreSQL Global Development Group
  * 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
@@ -267,7 +267,7 @@ extern const char *assign_search_path(const char *newval,
                                   bool doit, GucSource source);
 
 /* in access/transam/xlog.c */
-extern const char *assign_xlog_sync_method(const char *method,
-                                               bool doit, GucSource source);
+extern bool assign_xlog_sync_method(int newval,
+                               bool doit, GucSource source);
 
 #endif   /* GUC_H */