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

Commita9eb539

Browse files
committed
Move fsync method macro defines into /include/access/xlogdefs.h so they
can be used by src/tools/fsync/test_fsync.c.
1 parent5c63829 commita9eb539

File tree

3 files changed

+75
-151
lines changed

3 files changed

+75
-151
lines changed

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

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, 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.263 2007/02/08 11:10:27 petere Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.264 2007/02/14 05:00:40 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,6 +31,7 @@
3131
#include"access/twophase.h"
3232
#include"access/xact.h"
3333
#include"access/xlog_internal.h"
34+
#include"access/xlogdefs.h"
3435
#include"access/xlogutils.h"
3536
#include"catalog/catversion.h"
3637
#include"catalog/pg_control.h"
@@ -49,78 +50,6 @@
4950
#include"utils/pg_locale.h"
5051

5152

52-
/*
53-
*Because O_DIRECT bypasses the kernel buffers, and because we never
54-
*read those buffers except during crash recovery, it is a win to use
55-
*it in all cases where we sync on each write().We could allow O_DIRECT
56-
*with fsync(), but because skipping the kernel buffer forces writes out
57-
*quickly, it seems best just to use it for O_SYNC. It is hard to imagine
58-
*how fsync() could be a win for O_DIRECT compared to O_SYNC and O_DIRECT.
59-
*Also, O_DIRECT is never enough to force data to the drives, it merely
60-
*tries to bypass the kernel cache, so we still need O_SYNC or fsync().
61-
*/
62-
#ifdefO_DIRECT
63-
#definePG_O_DIRECTO_DIRECT
64-
#else
65-
#definePG_O_DIRECT0
66-
#endif
67-
68-
/*
69-
* This chunk of hackery attempts to determine which file sync methods
70-
* are available on the current platform, and to choose an appropriate
71-
* default method.We assume that fsync() is always available, and that
72-
* configure determined whether fdatasync() is.
73-
*/
74-
#if defined(O_SYNC)
75-
#defineBARE_OPEN_SYNC_FLAGO_SYNC
76-
#elif defined(O_FSYNC)
77-
#defineBARE_OPEN_SYNC_FLAGO_FSYNC
78-
#endif
79-
#ifdefBARE_OPEN_SYNC_FLAG
80-
#defineOPEN_SYNC_FLAG(BARE_OPEN_SYNC_FLAG | PG_O_DIRECT)
81-
#endif
82-
83-
#if defined(O_DSYNC)
84-
#if defined(OPEN_SYNC_FLAG)
85-
/* O_DSYNC is distinct? */
86-
#ifO_DSYNC!=BARE_OPEN_SYNC_FLAG
87-
#defineOPEN_DATASYNC_FLAG(O_DSYNC | PG_O_DIRECT)
88-
#endif
89-
#else/* !defined(OPEN_SYNC_FLAG) */
90-
/* Win32 only has O_DSYNC */
91-
#defineOPEN_DATASYNC_FLAG(O_DSYNC | PG_O_DIRECT)
92-
#endif
93-
#endif
94-
95-
#if defined(OPEN_DATASYNC_FLAG)
96-
#defineDEFAULT_SYNC_METHOD_STR "open_datasync"
97-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_OPEN
98-
#defineDEFAULT_SYNC_FLAGBITOPEN_DATASYNC_FLAG
99-
#elif defined(HAVE_FDATASYNC)
100-
#defineDEFAULT_SYNC_METHOD_STR "fdatasync"
101-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FDATASYNC
102-
#defineDEFAULT_SYNC_FLAGBIT0
103-
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
104-
#defineDEFAULT_SYNC_METHOD_STR "fsync_writethrough"
105-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FSYNC_WRITETHROUGH
106-
#defineDEFAULT_SYNC_FLAGBIT0
107-
#else
108-
#defineDEFAULT_SYNC_METHOD_STR "fsync"
109-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FSYNC
110-
#defineDEFAULT_SYNC_FLAGBIT0
111-
#endif
112-
113-
114-
/*
115-
* Limitation of buffer-alignment for direct IO depends on OS and filesystem,
116-
* but XLOG_BLCKSZ is assumed to be enough for it.
117-
*/
118-
#ifdefO_DIRECT
119-
#defineALIGNOF_XLOG_BUFFERXLOG_BLCKSZ
120-
#else
121-
#defineALIGNOF_XLOG_BUFFERALIGNOF_BUFFER
122-
#endif
123-
12453

12554
/* File path names (all relative to $PGDATA) */
12655
#defineBACKUP_LABEL_FILE"backup_label"

‎src/include/access/xlogdefs.h

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.16 2007/01/05 22:19:51 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.17 2007/02/14 05:00:40 momjian Exp $
1111
*/
1212
#ifndefXLOG_DEFS_H
1313
#defineXLOG_DEFS_H
@@ -63,4 +63,75 @@ typedef struct XLogRecPtr
6363
*/
6464
typedefuint32TimeLineID;
6565

66+
/*
67+
*Because O_DIRECT bypasses the kernel buffers, and because we never
68+
*read those buffers except during crash recovery, it is a win to use
69+
*it in all cases where we sync on each write().We could allow O_DIRECT
70+
*with fsync(), but because skipping the kernel buffer forces writes out
71+
*quickly, it seems best just to use it for O_SYNC. It is hard to imagine
72+
*how fsync() could be a win for O_DIRECT compared to O_SYNC and O_DIRECT.
73+
*Also, O_DIRECT is never enough to force data to the drives, it merely
74+
*tries to bypass the kernel cache, so we still need O_SYNC or fsync().
75+
*/
76+
#ifdefO_DIRECT
77+
#definePG_O_DIRECTO_DIRECT
78+
#else
79+
#definePG_O_DIRECT0
80+
#endif
81+
82+
/*
83+
* This chunk of hackery attempts to determine which file sync methods
84+
* are available on the current platform, and to choose an appropriate
85+
* default method.We assume that fsync() is always available, and that
86+
* configure determined whether fdatasync() is.
87+
*/
88+
#if defined(O_SYNC)
89+
#defineBARE_OPEN_SYNC_FLAGO_SYNC
90+
#elif defined(O_FSYNC)
91+
#defineBARE_OPEN_SYNC_FLAGO_FSYNC
92+
#endif
93+
#ifdefBARE_OPEN_SYNC_FLAG
94+
#defineOPEN_SYNC_FLAG(BARE_OPEN_SYNC_FLAG | PG_O_DIRECT)
95+
#endif
96+
97+
#if defined(O_DSYNC)
98+
#if defined(OPEN_SYNC_FLAG)
99+
/* O_DSYNC is distinct? */
100+
#ifO_DSYNC!=BARE_OPEN_SYNC_FLAG
101+
#defineOPEN_DATASYNC_FLAG(O_DSYNC | PG_O_DIRECT)
102+
#endif
103+
#else/* !defined(OPEN_SYNC_FLAG) */
104+
/* Win32 only has O_DSYNC */
105+
#defineOPEN_DATASYNC_FLAG(O_DSYNC | PG_O_DIRECT)
106+
#endif
107+
#endif
108+
109+
#if defined(OPEN_DATASYNC_FLAG)
110+
#defineDEFAULT_SYNC_METHOD_STR "open_datasync"
111+
#defineDEFAULT_SYNC_METHODSYNC_METHOD_OPEN
112+
#defineDEFAULT_SYNC_FLAGBITOPEN_DATASYNC_FLAG
113+
#elif defined(HAVE_FDATASYNC)
114+
#defineDEFAULT_SYNC_METHOD_STR "fdatasync"
115+
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FDATASYNC
116+
#defineDEFAULT_SYNC_FLAGBIT0
117+
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
118+
#defineDEFAULT_SYNC_METHOD_STR "fsync_writethrough"
119+
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FSYNC_WRITETHROUGH
120+
#defineDEFAULT_SYNC_FLAGBIT0
121+
#else
122+
#defineDEFAULT_SYNC_METHOD_STR "fsync"
123+
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FSYNC
124+
#defineDEFAULT_SYNC_FLAGBIT0
125+
#endif
126+
127+
/*
128+
* Limitation of buffer-alignment for direct IO depends on OS and filesystem,
129+
* but XLOG_BLCKSZ is assumed to be enough for it.
130+
*/
131+
#ifdefO_DIRECT
132+
#defineALIGNOF_XLOG_BUFFERXLOG_BLCKSZ
133+
#else
134+
#defineALIGNOF_XLOG_BUFFERALIGNOF_BUFFER
135+
#endif
136+
66137
#endif/* XLOG_DEFS_H */

‎src/tools/fsync/test_fsync.c

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include"access/xlog_internal.h"
99
#include"access/xlog.h"
10+
#include"access/xlogdefs.h"
1011

1112
#include<sys/types.h>
1213
#include<sys/stat.h>
@@ -18,83 +19,6 @@
1819
#include<unistd.h>
1920
#include<string.h>
2021

21-
/* ---------------------------------------------------------------
22-
*Copied from xlog.c. Some day this should be moved an include file.
23-
*/
24-
25-
/*
26-
*Because O_DIRECT bypasses the kernel buffers, and because we never
27-
*read those buffers except during crash recovery, it is a win to use
28-
*it in all cases where we sync on each write().We could allow O_DIRECT
29-
*with fsync(), but because skipping the kernel buffer forces writes out
30-
*quickly, it seems best just to use it for O_SYNC. It is hard to imagine
31-
*how fsync() could be a win for O_DIRECT compared to O_SYNC and O_DIRECT.
32-
*Also, O_DIRECT is never enough to force data to the drives, it merely
33-
*tries to bypass the kernel cache, so we still need O_SYNC or fsync().
34-
*/
35-
#ifdefO_DIRECT
36-
#definePG_O_DIRECTO_DIRECT
37-
#else
38-
#definePG_O_DIRECT0
39-
#endif
40-
41-
/*
42-
* This chunk of hackery attempts to determine which file sync methods
43-
* are available on the current platform, and to choose an appropriate
44-
* default method.We assume that fsync() is always available, and that
45-
* configure determined whether fdatasync() is.
46-
*/
47-
#if defined(O_SYNC)
48-
#defineBARE_OPEN_SYNC_FLAGO_SYNC
49-
#elif defined(O_FSYNC)
50-
#defineBARE_OPEN_SYNC_FLAGO_FSYNC
51-
#endif
52-
#ifdefBARE_OPEN_SYNC_FLAG
53-
#defineOPEN_SYNC_FLAG(BARE_OPEN_SYNC_FLAG | PG_O_DIRECT)
54-
#endif
55-
56-
#if defined(O_DSYNC)
57-
#if defined(OPEN_SYNC_FLAG)
58-
/* O_DSYNC is distinct? */
59-
#ifO_DSYNC!=BARE_OPEN_SYNC_FLAG
60-
#defineOPEN_DATASYNC_FLAG(O_DSYNC | PG_O_DIRECT)
61-
#endif
62-
#else/* !defined(OPEN_SYNC_FLAG) */
63-
/* Win32 only has O_DSYNC */
64-
#defineOPEN_DATASYNC_FLAG(O_DSYNC | PG_O_DIRECT)
65-
#endif
66-
#endif
67-
68-
#if defined(OPEN_DATASYNC_FLAG)
69-
#defineDEFAULT_SYNC_METHOD_STR "open_datasync"
70-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_OPEN
71-
#defineDEFAULT_SYNC_FLAGBITOPEN_DATASYNC_FLAG
72-
#elif defined(HAVE_FDATASYNC)
73-
#defineDEFAULT_SYNC_METHOD_STR "fdatasync"
74-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FDATASYNC
75-
#defineDEFAULT_SYNC_FLAGBIT0
76-
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
77-
#defineDEFAULT_SYNC_METHOD_STR "fsync_writethrough"
78-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FSYNC_WRITETHROUGH
79-
#defineDEFAULT_SYNC_FLAGBIT0
80-
#else
81-
#defineDEFAULT_SYNC_METHOD_STR "fsync"
82-
#defineDEFAULT_SYNC_METHODSYNC_METHOD_FSYNC
83-
#defineDEFAULT_SYNC_FLAGBIT0
84-
#endif
85-
86-
87-
/*
88-
* Limitation of buffer-alignment for direct IO depends on OS and filesystem,
89-
* but XLOG_BLCKSZ is assumed to be enough for it.
90-
*/
91-
#ifdefO_DIRECT
92-
#defineALIGNOF_XLOG_BUFFERXLOG_BLCKSZ
93-
#else
94-
#defineALIGNOF_XLOG_BUFFERALIGNOF_BUFFER
95-
#endif
96-
97-
/* ------------ from xlog.c --------------- */
9822

9923
#ifdefWIN32
10024
#defineFSYNC_FILENAME"./test_fsync.out"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp