Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a9eb539

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 parent 5c63829 commit a9eb539

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-
#ifdef O_DIRECT
63-
#define PG_O_DIRECT O_DIRECT
64-
#else
65-
#define PG_O_DIRECT 0
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-
#define BARE_OPEN_SYNC_FLAG O_SYNC
76-
#elif defined(O_FSYNC)
77-
#define BARE_OPEN_SYNC_FLAG O_FSYNC
78-
#endif
79-
#ifdef BARE_OPEN_SYNC_FLAG
80-
#define OPEN_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-
#if O_DSYNC != BARE_OPEN_SYNC_FLAG
87-
#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
88-
#endif
89-
#else /* !defined(OPEN_SYNC_FLAG) */
90-
/* Win32 only has O_DSYNC */
91-
#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
92-
#endif
93-
#endif
94-
95-
#if defined(OPEN_DATASYNC_FLAG)
96-
#define DEFAULT_SYNC_METHOD_STR "open_datasync"
97-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
98-
#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
99-
#elif defined(HAVE_FDATASYNC)
100-
#define DEFAULT_SYNC_METHOD_STR "fdatasync"
101-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
102-
#define DEFAULT_SYNC_FLAGBIT 0
103-
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
104-
#define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
105-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
106-
#define DEFAULT_SYNC_FLAGBIT 0
107-
#else
108-
#define DEFAULT_SYNC_METHOD_STR "fsync"
109-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
110-
#define DEFAULT_SYNC_FLAGBIT 0
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-
#ifdef O_DIRECT
119-
#define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ
120-
#else
121-
#define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER
122-
#endif
123-
12453

12554
/* File path names (all relative to $PGDATA) */
12655
#define BACKUP_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
#ifndef XLOG_DEFS_H
1313
#define XLOG_DEFS_H
@@ -63,4 +63,75 @@ typedef struct XLogRecPtr
6363
*/
6464
typedef uint32 TimeLineID;
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+
#ifdef O_DIRECT
77+
#define PG_O_DIRECT O_DIRECT
78+
#else
79+
#define PG_O_DIRECT 0
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+
#define BARE_OPEN_SYNC_FLAG O_SYNC
90+
#elif defined(O_FSYNC)
91+
#define BARE_OPEN_SYNC_FLAG O_FSYNC
92+
#endif
93+
#ifdef BARE_OPEN_SYNC_FLAG
94+
#define OPEN_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+
#if O_DSYNC != BARE_OPEN_SYNC_FLAG
101+
#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
102+
#endif
103+
#else /* !defined(OPEN_SYNC_FLAG) */
104+
/* Win32 only has O_DSYNC */
105+
#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
106+
#endif
107+
#endif
108+
109+
#if defined(OPEN_DATASYNC_FLAG)
110+
#define DEFAULT_SYNC_METHOD_STR "open_datasync"
111+
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
112+
#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
113+
#elif defined(HAVE_FDATASYNC)
114+
#define DEFAULT_SYNC_METHOD_STR "fdatasync"
115+
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
116+
#define DEFAULT_SYNC_FLAGBIT 0
117+
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
118+
#define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
119+
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
120+
#define DEFAULT_SYNC_FLAGBIT 0
121+
#else
122+
#define DEFAULT_SYNC_METHOD_STR "fsync"
123+
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
124+
#define DEFAULT_SYNC_FLAGBIT 0
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+
#ifdef O_DIRECT
132+
#define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ
133+
#else
134+
#define ALIGNOF_XLOG_BUFFER ALIGNOF_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-
#ifdef O_DIRECT
36-
#define PG_O_DIRECT O_DIRECT
37-
#else
38-
#define PG_O_DIRECT 0
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-
#define BARE_OPEN_SYNC_FLAG O_SYNC
49-
#elif defined(O_FSYNC)
50-
#define BARE_OPEN_SYNC_FLAG O_FSYNC
51-
#endif
52-
#ifdef BARE_OPEN_SYNC_FLAG
53-
#define OPEN_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-
#if O_DSYNC != BARE_OPEN_SYNC_FLAG
60-
#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
61-
#endif
62-
#else /* !defined(OPEN_SYNC_FLAG) */
63-
/* Win32 only has O_DSYNC */
64-
#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
65-
#endif
66-
#endif
67-
68-
#if defined(OPEN_DATASYNC_FLAG)
69-
#define DEFAULT_SYNC_METHOD_STR "open_datasync"
70-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
71-
#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
72-
#elif defined(HAVE_FDATASYNC)
73-
#define DEFAULT_SYNC_METHOD_STR "fdatasync"
74-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
75-
#define DEFAULT_SYNC_FLAGBIT 0
76-
#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
77-
#define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
78-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
79-
#define DEFAULT_SYNC_FLAGBIT 0
80-
#else
81-
#define DEFAULT_SYNC_METHOD_STR "fsync"
82-
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
83-
#define DEFAULT_SYNC_FLAGBIT 0
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-
#ifdef O_DIRECT
92-
#define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ
93-
#else
94-
#define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER
95-
#endif
96-
97-
/* ------------ from xlog.c --------------- */
9822

9923
#ifdef WIN32
10024
#define FSYNC_FILENAME "./test_fsync.out"

0 commit comments

Comments
 (0)