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

Commit ce3da29

Browse files
committed
Use durable_rename
1 parent c6dec8c commit ce3da29

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

src/backend/storage/file/cfs.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -961,16 +961,11 @@ static bool cfs_gc_file(char* map_path, bool background)
961961
* Use rename and rely on file system to provide atomicity of this operation.
962962
*/
963963
remove_backups = false;
964-
if (rename(file_bck_path, file_path) < 0)
964+
if (durable_rename(file_bck_path, file_path, LOG) < 0)
965965
{
966966
elog(WARNING, "CFS failed to rename file %s: %m", file_path);
967967
goto Cleanup;
968968
}
969-
if (fsync_parent_path(file_path, LOG) != 0)
970-
{
971-
elog(WARNING, "CFS failed to sync directory for file %s: %m", file_path);
972-
goto Cleanup;
973-
}
974969

975970
ReplaceMap:
976971
/*
@@ -1174,7 +1169,7 @@ static void cfs_gc_bgworker_main(Datum arg)
11741169
void cfs_gc_start_bgworkers()
11751170
{
11761171
int i;
1177-
cfs_state->max_iterations = INT_MAX;
1172+
cfs_state->max_iterations = INT64_MAX;
11781173
cfs_state->n_workers = cfs_gc_workers;
11791174

11801175
for (i = 0; i < cfs_gc_workers; i++)

src/backend/storage/file/fd.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ 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);
333334

334335

335336
/*
@@ -1774,7 +1775,7 @@ FileRead(File file, char *buffer, int amount)
17741775
amount = CFS_INODE_SIZE(inode);
17751776
if (amount == 0)
17761777
{
1777-
uint32 fileSize = pg_atomic_read_u32(&map->virtSize);
1778+
uint32 fileSize = pg_atomic_read_u32(&map->hdr.virtSize);
17781779
if (VfdCache[file].seekPos + BLCKSZ <= fileSize)
17791780
{
17801781
amount = BLCKSZ;
@@ -2178,7 +2179,7 @@ FileSeek(File file, off_t offset, int whence)
21782179
if (VfdCache[file].fileFlags & PG_COMPRESSION)
21792180
{
21802181
FileMap* map = VfdCache[file].map;
2181-
uint32 fileSize = pg_atomic_read_u32(&map->virtSize);
2182+
uint32 fileSize = pg_atomic_read_u32(&map->hdr.virtSize);
21822183

21832184
if (offset > 0 && offset > fileSize)
21842185
offset = fileSize;
@@ -2267,13 +2268,13 @@ FileTruncate(File file, off_t offset)
22672268
map->inodes[i] = 0;
22682269
}
22692270

2270-
pg_atomic_write_u32(&map->virtSize, offset);
2271-
pg_atomic_fetch_sub_u32(&map->usedSize, released);
2271+
pg_atomic_write_u32(&map->hdr.virtSize, offset);
2272+
pg_atomic_fetch_sub_u32(&map->hdr.usedSize, released);
22722273

22732274
if (offset == 0)
22742275
{
22752276
/* We can truncate compressed file only with zero offset */
2276-
pg_atomic_write_u32(&map->physSize, 0);
2277+
pg_atomic_write_u32(&map->hdr.physSize, 0);
22772278
returnCode = ftruncate(VfdCache[file].fd, 0);
22782279
}
22792280
cfs_unlock_file(map);
@@ -3519,7 +3520,7 @@ fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)
35193520
* This is aimed at making file operations persistent on disk in case of
35203521
* an OS crash or power failure.
35213522
*/
3522-
int
3523+
static int
35233524
fsync_parent_path(const char *fname, int elevel)
35243525
{
35253526
char parentpath[MAXPGPATH];

src/include/storage/cfs.h

Lines changed: 2 additions & 2 deletions
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.41"
9+
#define CFS_VERSION "0.42"
1010

1111
#define CFS_GC_LOCK 0x10000000
1212

@@ -81,7 +81,7 @@ typedef struct
8181
int n_workers;
8282
/* Maximal number of iterations with GC should perform. Automatically started GC performs infinite number of iterations.
8383
* Manually started GC performs just one iteration. */
84-
int max_iterations;
84+
int64 max_iterations;
8585
/* Flag for temporary disabling GC */
8686
bool gc_enabled;
8787
/* Flag for controlling background GC */

src/include/storage/fd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ 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);
124123
extern int durable_rename(const char *oldfile, const char *newfile, int loglevel);
125124
extern int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel);
126125
extern void SyncDataDirectory(void);

0 commit comments

Comments
 (0)