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

Commit7d7db18

Browse files
committed
Second try at fsyncing directories in CREATE DATABASE. Let's see what the build farm says of opening directories read-only and ignoring EBADF from fsync of directories
1 parenta12333e commit7d7db18

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

‎src/port/copydir.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*as a service.
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.33 2010/02/26 02:01:38 momjian Exp $
14+
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.34 2010/02/28 21:05:30 stark Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -37,7 +37,7 @@
3737

3838

3939
staticvoidcopy_file(char*fromfile,char*tofile);
40-
staticvoidfsync_fname(char*fname);
40+
staticvoidfsync_fname(char*fname,boolisdir);
4141

4242

4343
/*
@@ -121,22 +121,17 @@ copydir(char *fromdir, char *todir, bool recurse)
121121
errmsg("could not stat file \"%s\": %m",tofile)));
122122

123123
if (S_ISREG(fst.st_mode))
124-
fsync_fname(tofile);
124+
fsync_fname(tofile, false);
125125
}
126126
FreeDir(xldir);
127127

128-
#ifdefNOTYET
129-
130128
/*
131129
* It's important to fsync the destination directory itself as individual
132130
* file fsyncs don't guarantee that the directory entry for the file is
133131
* synced. Recent versions of ext4 have made the window much wider but
134132
* it's been true for ext3 and other filesystems in the past.
135-
*
136-
* However we can't do this just yet, it has portability issues.
137133
*/
138-
fsync_fname(todir);
139-
#endif
134+
fsync_fname(todir, true);
140135
}
141136

142137
/*
@@ -216,20 +211,48 @@ copy_file(char *fromfile, char *tofile)
216211

217212
/*
218213
* fsync a file
214+
*
215+
* Try to fsync directories but ignore errors that indicate the OS
216+
* just doesn't allow/require fsyncing directories.
219217
*/
220218
staticvoid
221-
fsync_fname(char*fname)
219+
fsync_fname(char*fname,boolisdir)
222220
{
223-
intfd=BasicOpenFile(fname,
224-
O_RDWR |PG_BINARY,
225-
S_IRUSR |S_IWUSR);
221+
intfd;
222+
intreturncode;
226223

227-
if (fd<0)
224+
/* Some OSs require directories to be opened read-only whereas
225+
* other systems don't allow us to fsync files opened read-only so
226+
* we need both cases here
227+
*/
228+
if (!isdir)
229+
fd=BasicOpenFile(fname,
230+
O_RDWR |PG_BINARY,
231+
S_IRUSR |S_IWUSR);
232+
else
233+
fd=BasicOpenFile(fname,
234+
O_RDONLY |PG_BINARY,
235+
S_IRUSR |S_IWUSR);
236+
237+
/* Some OSs don't allow us to open directories at all */
238+
if (fd<0&&isdir&&errno==EISDIR)
239+
return;
240+
241+
elseif (fd<0)
228242
ereport(ERROR,
229243
(errcode_for_file_access(),
230244
errmsg("could not open file \"%s\": %m",fname)));
231245

232-
if (pg_fsync(fd)!=0)
246+
returncode=pg_fsync(fd);
247+
248+
/* Some OSs don't allow us to fsync directories at all */
249+
if (returncode!=0&&isdir&&errno==EBADF)
250+
{
251+
close(fd);
252+
return;
253+
}
254+
255+
if (returncode!=0)
233256
ereport(ERROR,
234257
(errcode_for_file_access(),
235258
errmsg("could not fsync file \"%s\": %m",fname)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp