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

Commit 1420617

Browse files
committed
Change client-side fsync_fname() to report errors fatally
Given all we have learned about fsync() error handling in the last few years, reporting an fsync() error non-fatally is not useful, unless you don't care much about the file, in which case you probably don't need to use fsync() in the first place. Change fsync_fname() and durable_rename() to exit(1) on fsync() errors other than those that we specifically chose to ignore. This affects initdb, pg_basebackup, pg_checksums, pg_dump, pg_dumpall, and pg_rewind. Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/d239d1bd-aef0-ca7c-dc0a-da14bdcf0392%402ndquadrant.com
1 parent a91e2fa commit 1420617

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/common/file_utils.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ static void walkdir(const char *path,
5151
* fsyncing, and might not have privileges to write at all.
5252
*
5353
* serverVersion indicates the version of the server to be fsync'd.
54-
*
55-
* Errors are reported but not considered fatal.
5654
*/
5755
void
5856
fsync_pgdata(const char *pg_data,
@@ -250,8 +248,8 @@ pre_sync_fname(const char *fname, bool isdir)
250248
* fsync_fname -- Try to fsync a file or directory
251249
*
252250
* Ignores errors trying to open unreadable files, or trying to fsync
253-
* directories on systems where that isn't allowed/required. Reports
254-
* other errors non-fatally.
251+
* directories on systems where that isn't allowed/required. All other errors
252+
* are fatal.
255253
*/
256254
int
257255
fsync_fname(const char *fname, bool isdir)
@@ -294,9 +292,9 @@ fsync_fname(const char *fname, bool isdir)
294292
*/
295293
if (returncode != 0 && !(isdir && (errno == EBADF || errno == EINVAL)))
296294
{
297-
pg_log_error("could not fsync file \"%s\": %m", fname);
295+
pg_log_fatal("could not fsync file \"%s\": %m", fname);
298296
(void) close(fd);
299-
return -1;
297+
exit(EXIT_FAILURE);
300298
}
301299

302300
(void) close(fd);
@@ -364,9 +362,9 @@ durable_rename(const char *oldfile, const char *newfile)
364362
{
365363
if (fsync(fd) != 0)
366364
{
367-
pg_log_error("could not fsync file \"%s\": %m", newfile);
365+
pg_log_fatal("could not fsync file \"%s\": %m", newfile);
368366
close(fd);
369-
return -1;
367+
exit(EXIT_FAILURE);
370368
}
371369
close(fd);
372370
}

0 commit comments

Comments
 (0)