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

Commit fd6b510

Browse files
committed
fsync directory after rename
1 parent e2b6257 commit fd6b510

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/backend/storage/file/cfs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ static bool cfs_gc_file(char* map_path, bool background)
706706
cfs_state->gc_stat.scannedFiles += 1;
707707

708708
/* do we need to perform defragmentation? */
709-
if ((physSize - usedSize)*100 > physSize*cfs_gc_threshold)
709+
if ((uint64)(physSize - usedSize)*100 > (uint64)physSize*cfs_gc_threshold)
710710
{
711711
long delay = CFS_LOCK_MIN_TIMEOUT;
712712
char* file_path = (char*)palloc(suf+1);
@@ -950,6 +950,11 @@ static bool cfs_gc_file(char* map_path, bool background)
950950
elog(WARNING, "CFS failed to rename file %s: %m", file_path);
951951
goto Cleanup;
952952
}
953+
if (fsync_parent_path(file_path, LOG) != 0)
954+
{
955+
elog(WARNING, "CFS failed to sync directory for file %s: %m", file_path);
956+
goto Cleanup;
957+
}
953958

954959
ReplaceMap:
955960
/*

src/backend/storage/file/fd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ static void pre_sync_fname(const char *fname, bool isdir, int elevel);
330330
static void datadir_fsync_fname(const char *fname, bool isdir, int elevel);
331331

332332
static int fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel);
333-
static int fsync_parent_path(const char *fname, int elevel);
334333

335334

336335
/*
@@ -3520,7 +3519,7 @@ fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)
35203519
* This is aimed at making file operations persistent on disk in case of
35213520
* an OS crash or power failure.
35223521
*/
3523-
static int
3522+
int
35243523
fsync_parent_path(const char *fname, int elevel)
35253524
{
35263525
char parentpath[MAXPGPATH];

src/include/storage/cfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "port/atomics.h"
77
#include "storage/rijndael.h"
88

9-
#define CFS_VERSION "0.36"
9+
#define CFS_VERSION "0.41"
1010

1111
#define CFS_GC_LOCK 0x10000000
1212

src/include/storage/fd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ extern int pg_fsync_writethrough(int fd);
120120
extern int pg_fdatasync(int fd);
121121
extern void pg_flush_data(int fd, off_t offset, off_t amount);
122122
extern void fsync_fname(const char *fname, bool isdir);
123+
extern int fsync_parent_path(const char *fname, int elevel);
123124
extern int durable_rename(const char *oldfile, const char *newfile, int loglevel);
124125
extern int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel);
125126
extern void SyncDataDirectory(void);

0 commit comments

Comments
 (0)