Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bf1db0

Browse files
committed
Remove the special variable for open_sync_bit used in O_SYNC and O_DSYNC
modes, replacing it with a call to a function that derives it from thesync_method variable, now that it has distinct values for these two cases.This means that assign_xlog_sync_method() no longer changes any settings,thus fixing the bug introduced in the change to use a guc enum forwal_sync_method.
1 parent14e6858 commit9bf1db0

File tree

1 file changed

+32
-31
lines changed
  • src/backend/access/transam

1 file changed

+32
-31
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 32 additions & 31 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.308 2008/05/13 20:53:52 mha Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.309 2008/05/14 14:02:57 mha Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -85,16 +85,11 @@ boolXLOG_DEBUG = false;
8585
*/
8686
#defineXLOGfileslop(2*CheckPointSegments + 1)
8787

88-
89-
/* these are derived from XLOG_sync_method by assign_xlog_sync_method */
90-
intsync_method=DEFAULT_SYNC_METHOD;
91-
staticintopen_sync_bit=DEFAULT_SYNC_FLAGBIT;
92-
93-
#defineXLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
94-
9588
/*
9689
* GUC support
9790
*/
91+
intsync_method=DEFAULT_SYNC_METHOD;
92+
9893
conststructconfig_enum_entrysync_method_options[]= {
9994
{"fsync",SYNC_METHOD_FSYNC},
10095
#ifdefHAVE_FSYNC_WRITETHROUGH
@@ -444,6 +439,7 @@ static void pg_start_backup_callback(int code, Datum arg);
444439
staticboolread_backup_label(XLogRecPtr*checkPointLoc,
445440
XLogRecPtr*minRecoveryLoc);
446441
staticvoidrm_redo_error_callback(void*arg);
442+
staticintget_sync_bit(intmethod);
447443

448444

449445
/*
@@ -1960,7 +1956,7 @@ XLogFileInit(uint32 log, uint32 seg,
19601956
*/
19611957
if (*use_existent)
19621958
{
1963-
fd=BasicOpenFile(path,O_RDWR |PG_BINARY |XLOG_SYNC_BIT,
1959+
fd=BasicOpenFile(path,O_RDWR |PG_BINARY |get_sync_bit(sync_method),
19641960
S_IRUSR |S_IWUSR);
19651961
if (fd<0)
19661962
{
@@ -1986,7 +1982,7 @@ XLogFileInit(uint32 log, uint32 seg,
19861982

19871983
unlink(tmppath);
19881984

1989-
/* do not useXLOG_SYNC_BIT here --- want to fsync only at end of fill */
1985+
/* do not useget_sync_bit() here --- want to fsync only at end of fill */
19901986
fd=BasicOpenFile(tmppath,O_RDWR |O_CREAT |O_EXCL |PG_BINARY,
19911987
S_IRUSR |S_IWUSR);
19921988
if (fd<0)
@@ -2064,7 +2060,7 @@ XLogFileInit(uint32 log, uint32 seg,
20642060
*use_existent= false;
20652061

20662062
/* Now open original target segment (might not be file I just made) */
2067-
fd=BasicOpenFile(path,O_RDWR |PG_BINARY |XLOG_SYNC_BIT,
2063+
fd=BasicOpenFile(path,O_RDWR |PG_BINARY |get_sync_bit(sync_method),
20682064
S_IRUSR |S_IWUSR);
20692065
if (fd<0)
20702066
ereport(ERROR,
@@ -2115,7 +2111,7 @@ XLogFileCopy(uint32 log, uint32 seg,
21152111

21162112
unlink(tmppath);
21172113

2118-
/* do not useXLOG_SYNC_BIT here --- want to fsync only at end of fill */
2114+
/* do not useget_sync_bit() here --- want to fsync only at end of fill */
21192115
fd=BasicOpenFile(tmppath,O_RDWR |O_CREAT |O_EXCL |PG_BINARY,
21202116
S_IRUSR |S_IWUSR);
21212117
if (fd<0)
@@ -2297,7 +2293,7 @@ XLogFileOpen(uint32 log, uint32 seg)
22972293

22982294
XLogFilePath(path,ThisTimeLineID,log,seg);
22992295

2300-
fd=BasicOpenFile(path,O_RDWR |PG_BINARY |XLOG_SYNC_BIT,
2296+
fd=BasicOpenFile(path,O_RDWR |PG_BINARY |get_sync_bit(sync_method),
23012297
S_IRUSR |S_IWUSR);
23022298
if (fd<0)
23032299
ereport(PANIC,
@@ -3653,7 +3649,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
36533649

36543650
unlink(tmppath);
36553651

3656-
/* do not useXLOG_SYNC_BIT here --- want to fsync only at end of fill */
3652+
/* do not useget_sync_bit() here --- want to fsync only at end of fill */
36573653
fd=BasicOpenFile(tmppath,O_RDWR |O_CREAT |O_EXCL,
36583654
S_IRUSR |S_IWUSR);
36593655
if (fd<0)
@@ -6331,14 +6327,17 @@ xlog_outrec(StringInfo buf, XLogRecord *record)
63316327

63326328

63336329
/*
6334-
* GUC support
6330+
* Return the (possible) sync flag used for opening a file, depending on the
6331+
* value of the GUC wal_sync_method.
63356332
*/
6336-
bool
6337-
assign_xlog_sync_method(intnew_sync_method,booldoit,GucSourcesource)
6333+
staticint
6334+
get_sync_bit(intmethod)
63386335
{
6339-
intnew_sync_bit=0;
6336+
/* If fsync is disabled, never open in sync mode */
6337+
if (!enableFsync)
6338+
return0;
63406339

6341-
switch (new_sync_method)
6340+
switch (method)
63426341
{
63436342
/*
63446343
* Values for these sync options are defined even if they are not
@@ -6349,32 +6348,36 @@ assign_xlog_sync_method(int new_sync_method, bool doit, GucSource source)
63496348
caseSYNC_METHOD_FSYNC:
63506349
caseSYNC_METHOD_FSYNC_WRITETHROUGH:
63516350
caseSYNC_METHOD_FDATASYNC:
6352-
new_sync_bit=0;
6353-
break;
6351+
return0;
63546352
#ifdefOPEN_SYNC_FLAG
63556353
caseSYNC_METHOD_OPEN:
6356-
new_sync_bit=OPEN_SYNC_FLAG;
6357-
break;
6354+
returnOPEN_SYNC_FLAG;
63586355
#endif
63596356
#ifdefOPEN_DATASYNC_FLAG
63606357
caseSYNC_METHOD_OPEN_DSYNC:
6361-
new_sync_bit=OPEN_DATASYNC_FLAG;
6362-
break;
6358+
returnOPEN_DATASYNC_FLAG;
63636359
#endif
63646360
default:
63656361
/*
63666362
* This "can never happen", since the available values in
63676363
* new_sync_method are controlled by the available enum
63686364
* options.
63696365
*/
6370-
elog(PANIC,"unrecognized wal_sync_method: %d",new_sync_method);
6371-
break;
6366+
elog(PANIC,"unrecognized wal_sync_method: %d",method);
6367+
return0;/* silence warning */
63726368
}
6369+
}
63736370

6371+
/*
6372+
* GUC support
6373+
*/
6374+
bool
6375+
assign_xlog_sync_method(intnew_sync_method,booldoit,GucSourcesource)
6376+
{
63746377
if (!doit)
63756378
return true;
63766379

6377-
if (sync_method!=new_sync_method||open_sync_bit!=new_sync_bit)
6380+
if (sync_method!=new_sync_method)
63786381
{
63796382
/*
63806383
* To ensure that no blocks escape unsynced, force an fsync on the
@@ -6389,11 +6392,9 @@ assign_xlog_sync_method(int new_sync_method, bool doit, GucSource source)
63896392
(errcode_for_file_access(),
63906393
errmsg("could not fsync log file %u, segment %u: %m",
63916394
openLogId,openLogSeg)));
6392-
if (open_sync_bit!=new_sync_bit)
6395+
if (get_sync_bit(sync_method)!=get_sync_bit(new_sync_method))
63936396
XLogFileClose();
63946397
}
6395-
sync_method=new_sync_method;
6396-
open_sync_bit=new_sync_bit;
63976398
}
63986399

63996400
return true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp