From c911cee97239542e14a489ed84ab3b46a047659e Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 6 Nov 2024 09:52:19 -0600 Subject: [PATCH v2 5/8] Export pre_sync_fname(). THIS IS A PROOF OF CONCEPT AND IS NOT READY FOR SERIOUS REVIEW. A follow-up commit will use this function to alert the file system that we want a file's data on disk so that subsequent calls to fsync() are faster. --- src/common/file_utils.c | 18 +++++------------- src/include/common/file_utils.h | 1 + 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/common/file_utils.c b/src/common/file_utils.c index 65cdf07ae7..5c201ec6e8 100644 --- a/src/common/file_utils.c +++ b/src/common/file_utils.c @@ -45,10 +45,6 @@ */ #define MINIMUM_VERSION_FOR_PG_WAL 100000 -#ifdef PG_FLUSH_DATA_WORKS -static int pre_sync_fname(const char *fname, bool isdir, void *arg); -#endif - #ifdef HAVE_SYNCFS /* @@ -307,11 +303,7 @@ walkdir(const char *path, * introduce a huge number of function pointer calls and * directory reads that we are trying to avoid. */ -#ifdef PG_FLUSH_DATA_WORKS if ((action != pre_sync_fname && action != fsync_fname) || -#else - if (action != fsync_fname || -#endif !arg || *((bool *) arg) || strcmp(de->d_name, "base") != 0) walkdir(subpath, action, false, arg); @@ -348,11 +340,12 @@ walkdir(const char *path, * Ignores errors trying to open unreadable files, and reports other errors * non-fatally. */ -#ifdef PG_FLUSH_DATA_WORKS - -static int +int pre_sync_fname(const char *fname, bool isdir, void *arg) { +#ifndef PG_FLUSH_DATA_WORKS + return 0; +#else int fd; fd = open(fname, O_RDONLY | PG_BINARY, 0); @@ -380,9 +373,8 @@ pre_sync_fname(const char *fname, bool isdir, void *arg) (void) close(fd); return 0; -} - #endif /* PG_FLUSH_DATA_WORKS */ +} /* * fsync_fname -- Try to fsync a file or directory diff --git a/src/include/common/file_utils.h b/src/include/common/file_utils.h index 3743caa63e..e7a34d4c4e 100644 --- a/src/include/common/file_utils.h +++ b/src/include/common/file_utils.h @@ -43,6 +43,7 @@ extern int fsync_parent_path(const char *fname); extern void walkdir(const char *path, int (*action) (const char *fname, bool isdir, void *arg), bool process_symlinks, void *arg); +extern int pre_sync_fname(const char *fname, bool isdir, void *arg); #endif extern PGFileType get_dirent_type(const char *path, -- 2.39.5 (Apple Git-154)