Skip to content

Commit 8d140c5

Browse files
Improve the naming in wal_sync_method code.
* sync_method is renamed to wal_sync_method. * sync_method_options[] is renamed to wal_sync_method_options[]. * assign_xlog_sync_method() is renamed to assign_wal_sync_method(). * The names of the available synchronization methods are now prefixed with "WAL_SYNC_METHOD_" and have been moved into a WalSyncMethod enum. * PLATFORM_DEFAULT_SYNC_METHOD is renamed to PLATFORM_DEFAULT_WAL_SYNC_METHOD, and DEFAULT_SYNC_METHOD is renamed to DEFAULT_WAL_SYNC_METHOD. These more descriptive names help distinguish the code for wal_sync_method from the code for DataDirSyncMethod (e.g., the recovery_init_sync_method configuration parameter and the --sync-method option provided by several frontend utilities). This change also prevents name collisions between the aforementioned sets of code. Since this only improves the naming of internal identifiers, there should be no behavior change. Author: Maxim Orlov Discussion: https://postgr.es/m/CACG%3DezbL1gwE7_K7sr9uqaCGkWhmvRTcTEnm3%2BX1xsRNwbXULQ%40mail.gmail.com
1 parent c5a032e commit 8d140c5

File tree

9 files changed

+52
-48
lines changed

9 files changed

+52
-48
lines changed

src/backend/access/transam/xlog.c

+29-29
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool *wal_consistency_checking = NULL;
130130
bool wal_init_zero = true;
131131
bool wal_recycle = true;
132132
bool log_checkpoints = true;
133-
int sync_method = DEFAULT_SYNC_METHOD;
133+
int wal_sync_method = DEFAULT_WAL_SYNC_METHOD;
134134
int wal_level = WAL_LEVEL_REPLICA;
135135
int CommitDelay = 0; /* precommit delay in microseconds */
136136
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
@@ -171,17 +171,17 @@ static bool check_wal_consistency_checking_deferred = false;
171171
/*
172172
* GUC support
173173
*/
174-
const struct config_enum_entry sync_method_options[] = {
175-
{"fsync", SYNC_METHOD_FSYNC, false},
174+
const struct config_enum_entry wal_sync_method_options[] = {
175+
{"fsync", WAL_SYNC_METHOD_FSYNC, false},
176176
#ifdef HAVE_FSYNC_WRITETHROUGH
177-
{"fsync_writethrough", SYNC_METHOD_FSYNC_WRITETHROUGH, false},
177+
{"fsync_writethrough", WAL_SYNC_METHOD_FSYNC_WRITETHROUGH, false},
178178
#endif
179-
{"fdatasync", SYNC_METHOD_FDATASYNC, false},
179+
{"fdatasync", WAL_SYNC_METHOD_FDATASYNC, false},
180180
#ifdef O_SYNC
181-
{"open_sync", SYNC_METHOD_OPEN, false},
181+
{"open_sync", WAL_SYNC_METHOD_OPEN, false},
182182
#endif
183183
#ifdef O_DSYNC
184-
{"open_datasync", SYNC_METHOD_OPEN_DSYNC, false},
184+
{"open_datasync", WAL_SYNC_METHOD_OPEN_DSYNC, false},
185185
#endif
186186
{NULL, 0, false}
187187
};
@@ -2343,8 +2343,8 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
23432343
* have no open file or the wrong one. However, we do not need to
23442344
* fsync more than one file.
23452345
*/
2346-
if (sync_method != SYNC_METHOD_OPEN &&
2347-
sync_method != SYNC_METHOD_OPEN_DSYNC)
2346+
if (wal_sync_method != WAL_SYNC_METHOD_OPEN &&
2347+
wal_sync_method != WAL_SYNC_METHOD_OPEN_DSYNC)
23482348
{
23492349
if (openLogFile >= 0 &&
23502350
!XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo,
@@ -2974,7 +2974,7 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
29742974
*/
29752975
*added = false;
29762976
fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC |
2977-
get_sync_bit(sync_method));
2977+
get_sync_bit(wal_sync_method));
29782978
if (fd < 0)
29792979
{
29802980
if (errno != ENOENT)
@@ -3139,7 +3139,7 @@ XLogFileInit(XLogSegNo logsegno, TimeLineID logtli)
31393139

31403140
/* Now open original target segment (might not be file I just made) */
31413141
fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC |
3142-
get_sync_bit(sync_method));
3142+
get_sync_bit(wal_sync_method));
31433143
if (fd < 0)
31443144
ereport(ERROR,
31453145
(errcode_for_file_access(),
@@ -3371,7 +3371,7 @@ XLogFileOpen(XLogSegNo segno, TimeLineID tli)
33713371
XLogFilePath(path, tli, segno, wal_segment_size);
33723372

33733373
fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC |
3374-
get_sync_bit(sync_method));
3374+
get_sync_bit(wal_sync_method));
33753375
if (fd < 0)
33763376
ereport(PANIC,
33773377
(errcode_for_file_access(),
@@ -8137,16 +8137,16 @@ get_sync_bit(int method)
81378137
* not included in the enum option array, and therefore will never
81388138
* be seen here.
81398139
*/
8140-
case SYNC_METHOD_FSYNC:
8141-
case SYNC_METHOD_FSYNC_WRITETHROUGH:
8142-
case SYNC_METHOD_FDATASYNC:
8140+
case WAL_SYNC_METHOD_FSYNC:
8141+
case WAL_SYNC_METHOD_FSYNC_WRITETHROUGH:
8142+
case WAL_SYNC_METHOD_FDATASYNC:
81438143
return o_direct_flag;
81448144
#ifdef O_SYNC
8145-
case SYNC_METHOD_OPEN:
8145+
case WAL_SYNC_METHOD_OPEN:
81468146
return O_SYNC | o_direct_flag;
81478147
#endif
81488148
#ifdef O_DSYNC
8149-
case SYNC_METHOD_OPEN_DSYNC:
8149+
case WAL_SYNC_METHOD_OPEN_DSYNC:
81508150
return O_DSYNC | o_direct_flag;
81518151
#endif
81528152
default:
@@ -8160,9 +8160,9 @@ get_sync_bit(int method)
81608160
* GUC support
81618161
*/
81628162
void
8163-
assign_xlog_sync_method(int new_sync_method, void *extra)
8163+
assign_wal_sync_method(int new_wal_sync_method, void *extra)
81648164
{
8165-
if (sync_method != new_sync_method)
8165+
if (wal_sync_method != new_wal_sync_method)
81668166
{
81678167
/*
81688168
* To ensure that no blocks escape unsynced, force an fsync on the
@@ -8188,7 +8188,7 @@ assign_xlog_sync_method(int new_sync_method, void *extra)
81888188
}
81898189

81908190
pgstat_report_wait_end();
8191-
if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
8191+
if (get_sync_bit(wal_sync_method) != get_sync_bit(new_wal_sync_method))
81928192
XLogFileClose();
81938193
}
81948194
}
@@ -8214,8 +8214,8 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
82148214
* file.
82158215
*/
82168216
if (!enableFsync ||
8217-
sync_method == SYNC_METHOD_OPEN ||
8218-
sync_method == SYNC_METHOD_OPEN_DSYNC)
8217+
wal_sync_method == WAL_SYNC_METHOD_OPEN ||
8218+
wal_sync_method == WAL_SYNC_METHOD_OPEN_DSYNC)
82198219
return;
82208220

82218221
/* Measure I/O timing to sync the WAL file */
@@ -8225,29 +8225,29 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
82258225
INSTR_TIME_SET_ZERO(start);
82268226

82278227
pgstat_report_wait_start(WAIT_EVENT_WAL_SYNC);
8228-
switch (sync_method)
8228+
switch (wal_sync_method)
82298229
{
8230-
case SYNC_METHOD_FSYNC:
8230+
case WAL_SYNC_METHOD_FSYNC:
82318231
if (pg_fsync_no_writethrough(fd) != 0)
82328232
msg = _("could not fsync file \"%s\": %m");
82338233
break;
82348234
#ifdef HAVE_FSYNC_WRITETHROUGH
8235-
case SYNC_METHOD_FSYNC_WRITETHROUGH:
8235+
case WAL_SYNC_METHOD_FSYNC_WRITETHROUGH:
82368236
if (pg_fsync_writethrough(fd) != 0)
82378237
msg = _("could not fsync write-through file \"%s\": %m");
82388238
break;
82398239
#endif
8240-
case SYNC_METHOD_FDATASYNC:
8240+
case WAL_SYNC_METHOD_FDATASYNC:
82418241
if (pg_fdatasync(fd) != 0)
82428242
msg = _("could not fdatasync file \"%s\": %m");
82438243
break;
8244-
case SYNC_METHOD_OPEN:
8245-
case SYNC_METHOD_OPEN_DSYNC:
8244+
case WAL_SYNC_METHOD_OPEN:
8245+
case WAL_SYNC_METHOD_OPEN_DSYNC:
82468246
/* not reachable */
82478247
Assert(false);
82488248
break;
82498249
default:
8250-
elog(PANIC, "unrecognized wal_sync_method: %d", sync_method);
8250+
elog(PANIC, "unrecognized wal_sync_method: %d", wal_sync_method);
82518251
break;
82528252
}
82538253

src/backend/storage/file/fd.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ pg_fsync(int fd)
398398
errno = 0;
399399
#endif
400400

401-
/* #if is to skip the sync_method test if there's no need for it */
401+
/* #if is to skip the wal_sync_method test if there's no need for it */
402402
#if defined(HAVE_FSYNC_WRITETHROUGH)
403-
if (sync_method == SYNC_METHOD_FSYNC_WRITETHROUGH)
403+
if (wal_sync_method == WAL_SYNC_METHOD_FSYNC_WRITETHROUGH)
404404
return pg_fsync_writethrough(fd);
405405
else
406406
#endif

src/backend/utils/misc/guc_tables.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static const struct config_enum_entry wal_compression_options[] = {
485485
extern const struct config_enum_entry wal_level_options[];
486486
extern const struct config_enum_entry archive_mode_options[];
487487
extern const struct config_enum_entry recovery_target_action_options[];
488-
extern const struct config_enum_entry sync_method_options[];
488+
extern const struct config_enum_entry wal_sync_method_options[];
489489
extern const struct config_enum_entry dynamic_shared_memory_options[];
490490

491491
/*
@@ -4843,9 +4843,9 @@ struct config_enum ConfigureNamesEnum[] =
48434843
gettext_noop("Selects the method used for forcing WAL updates to disk."),
48444844
NULL
48454845
},
4846-
&sync_method,
4847-
DEFAULT_SYNC_METHOD, sync_method_options,
4848-
NULL, assign_xlog_sync_method, NULL
4846+
&wal_sync_method,
4847+
DEFAULT_WAL_SYNC_METHOD, wal_sync_method_options,
4848+
NULL, assign_wal_sync_method, NULL
48494849
},
48504850

48514851
{

src/include/access/xlog.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020

2121
/* Sync methods */
22-
#define SYNC_METHOD_FSYNC 0
23-
#define SYNC_METHOD_FDATASYNC 1
24-
#define SYNC_METHOD_OPEN 2 /* for O_SYNC */
25-
#define SYNC_METHOD_FSYNC_WRITETHROUGH 3
26-
#define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */
27-
extern PGDLLIMPORT int sync_method;
22+
typedef enum WalSyncMethod
23+
{
24+
WAL_SYNC_METHOD_FSYNC = 0,
25+
WAL_SYNC_METHOD_FDATASYNC,
26+
WAL_SYNC_METHOD_OPEN, /* for O_SYNC */
27+
WAL_SYNC_METHOD_FSYNC_WRITETHROUGH,
28+
WAL_SYNC_METHOD_OPEN_DSYNC /* for O_DSYNC */
29+
} WalSyncMethod;
30+
extern PGDLLIMPORT int wal_sync_method;
2831

2932
extern PGDLLIMPORT XLogRecPtr ProcLastRecPtr;
3033
extern PGDLLIMPORT XLogRecPtr XactLastRecEnd;

src/include/access/xlogdefs.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ typedef uint16 RepOriginId;
7171
*
7272
* Note that we define our own O_DSYNC on Windows, but not O_SYNC.
7373
*/
74-
#if defined(PLATFORM_DEFAULT_SYNC_METHOD)
75-
#define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
74+
#if defined(PLATFORM_DEFAULT_WAL_SYNC_METHOD)
75+
#define DEFAULT_WAL_SYNC_METHOD PLATFORM_DEFAULT_WAL_SYNC_METHOD
7676
#elif defined(O_DSYNC) && (!defined(O_SYNC) || O_DSYNC != O_SYNC)
77-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
77+
#define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_OPEN_DSYNC
7878
#else
79-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
79+
#define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC
8080
#endif
8181

8282
#endif /* XLOG_DEFS_H */

src/include/port/freebsd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* would prefer open_datasync on FreeBSD 13+, but that is not a good choice on
66
* many systems.
77
*/
8-
#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
8+
#define PLATFORM_DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC

src/include/port/linux.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
* perform better and (b) causes outright failures on ext4 data=journal
2020
* filesystems, because those don't support O_DIRECT.
2121
*/
22-
#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
22+
#define PLATFORM_DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC

src/include/utils/guc_hooks.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ extern bool check_wal_consistency_checking(char **newval, void **extra,
159159
GucSource source);
160160
extern void assign_wal_consistency_checking(const char *newval, void *extra);
161161
extern bool check_wal_segment_size(int *newval, void **extra, GucSource source);
162-
extern void assign_xlog_sync_method(int new_sync_method, void *extra);
162+
extern void assign_wal_sync_method(int new_wal_sync_method, void *extra);
163163

164164
#endif /* GUC_HOOKS_H */

src/tools/pgindent/typedefs.list

+1
Original file line numberDiff line numberDiff line change
@@ -3016,6 +3016,7 @@ WalSnd
30163016
WalSndCtlData
30173017
WalSndSendDataCallback
30183018
WalSndState
3019+
WalSyncMethod
30193020
WalTimeSample
30203021
WalUsage
30213022
WalWriteMethod

0 commit comments

Comments
 (0)