Commit 7a0c9482 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

closes[t:2445] fsync dirs after file creation

git-svn-id: file:///svn/toku/tokudb@20735 c7de825b-a66e-492c-adef-691d508d4ae1
parent e592d9a7
......@@ -13,7 +13,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "memory.h"
static int toku_assert_on_write_enospc = 0;
static const int toku_write_enospc_sleep = 1;
......@@ -395,3 +395,43 @@ toku_get_fsync_sched(uint64_t *fsync_count, uint64_t *fsync_time) {
*fsync_count = sched_fsync_count;
*fsync_time = sched_fsync_time;
}
int
toku_fsync_directory(const char *fname) {
int result = 0;
// extract dirname from fname
char *sp = strrchr(fname, '/');
size_t len;
char *dirname = NULL;
if (sp) {
resource_assert(sp >= fname);
len = sp - fname + 1;
dirname = toku_malloc(len+1);
if (dirname == NULL)
result = errno;
else {
strncpy(dirname, fname, len);
dirname[len] = 0;
}
} else {
dirname = toku_strdup(".");
if (dirname == NULL)
result = errno;
}
if (result == 0) {
// fsync the dir
DIR *d = opendir(dirname);
if (d == NULL) {
result = errno;
} else {
result = toku_fsync_dirfd_without_accounting(d);
int r = closedir(d);
if (result == 0 && r != 0)
result = errno;
}
}
toku_free(dirname);
return result;
}
......@@ -2949,6 +2949,10 @@ static int brt_create_file(BRT brt, const char *fname, int *fdp) {
r = errno;
return r;
}
r = toku_fsync_directory(fname);
resource_assert(r == 0);
*fdp = fd;
return 0;
}
......
......@@ -2416,6 +2416,9 @@ static int loader_do_i (BRTLOADER bl,
if (fd < 0) {
r = errno; goto error;
}
r = toku_fsync_directory(new_fname);
if (r != 0) goto error;
// This structure must stay live until the join below.
struct fractal_thread_args fta = { bl,
......
......@@ -170,6 +170,8 @@ int toku_os_fclose(FILE * stream);
int toku_file_fsync_without_accounting(int fd);
int toku_file_fsync(int fd);
int toku_fsync_directory(const char *fname);
// get the number of fsync calls and the fsync times (total)
void toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time);
......
......@@ -145,3 +145,7 @@ toku_fsync_dirfd_without_accounting(DIR *dirp) {
return 0;
}
int
toku_fsync_directory(const char *UU(fname)) {
return 0; // toku_fsync_dirfd
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment