diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-21 20:10:29 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-21 20:10:29 -0400 |
commit | 2d46a57ddcad394e514bbefb193a4a03e766f163 (patch) | |
tree | a6f4cb51623dc770e284d127986bf37f14f5744b /src/backend/storage/file/copydir.c | |
parent | 2c4f5b4bc5385b37d062451642abd384536eeeb3 (diff) | |
download | postgresql-2d46a57ddcad394e514bbefb193a4a03e766f163.tar.gz postgresql-2d46a57ddcad394e514bbefb193a4a03e766f163.zip |
Improve copydir() code for the case that fsync is off.
We should avoid calling sync_file_range or posix_fadvise in this case,
since (a) we don't really care if the data gets synced, and might as
well save the kernel calls; (b) at least on Linux we know that the
kernel might block us until it's scheduled the write.
Also, avoid making a useless second traversal of the directory tree
if we're not actually going to call fsync(2) after all.
Diffstat (limited to 'src/backend/storage/file/copydir.c')
-rw-r--r-- | src/backend/storage/file/copydir.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c index dc89442041a..cf47708a797 100644 --- a/src/backend/storage/file/copydir.c +++ b/src/backend/storage/file/copydir.c @@ -98,7 +98,11 @@ copydir(char *fromdir, char *todir, bool recurse) /* * Be paranoid here and fsync all files to ensure the copy is really done. + * But if fsync is disabled, we're done. */ + if (!enableFsync) + return; + xldir = AllocateDir(todir); if (xldir == NULL) ereport(ERROR, @@ -200,9 +204,9 @@ copy_file(char *fromfile, char *tofile) /* * We fsync the files later but first flush them to avoid spamming the * cache and hopefully get the kernel to start writing them out before - * the fsync comes. + * the fsync comes. Ignore any error, since it's only a hint. */ - pg_flush_data(dstfd, offset, nbytes); + (void) pg_flush_data(dstfd, offset, nbytes); } if (close(dstfd)) |