Commit 4cf833e7 authored by Yoni Fogel's avatar Yoni Fogel

[t:2257] Add fsync times for windows (using mutex since missing 64bit atomic instructions)

Added '/' as allowable directory separator in absolute paths in windows

git-svn-id: file:///svn/toku/tokudb@16997 c7de825b-a66e-492c-adef-691d508d4ae1
parent 836889d0
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <windows.h> #include <windows.h>
#include <toku_atomic.h>
#include <toku_time.h>
int64_t int64_t
pread(int fildes, void *buf, size_t nbyte, int64_t offset) { pread(int fildes, void *buf, size_t nbyte, int64_t offset) {
...@@ -113,23 +115,74 @@ toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) ...@@ -113,23 +115,74 @@ toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off)
assert(r==len); assert(r==len);
} }
// t_fsync exists for testing purposes only
static int (*t_fsync)(int) = 0; static int (*t_fsync)(int) = 0;
static uint64_t toku_fsync_count; static uint64_t toku_fsync_count;
static uint64_t toku_fsync_time; static uint64_t toku_fsync_time;
#if !TOKU_WINDOWS_HAS_FAST_ATOMIC_64
static toku_pthread_mutex_t fsync_lock;
#endif
int
toku_fsync_init(void) {
int r = 0;
#if !TOKU_WINDOWS_HAS_FAST_ATOMIC_64
r = toku_pthread_mutex_init(&fsync_lock, NULL); assert(r == 0);
#endif
return r;
}
int
toku_fsync_destroy(void) {
int r = 0;
#if !TOKU_WINDOWS_HAS_FAST_ATOMIC_64
r = toku_pthread_mutex_destroy(&fsync_lock); assert(r == 0);
#endif
return r;
}
int int
toku_set_func_fsync(int (*fsync_function)(int)) { toku_set_func_fsync(int (*fsync_function)(int)) {
t_fsync = fsync_function; t_fsync = fsync_function;
return 0; return 0;
} }
static uint64_t get_tnow(void) {
struct timeval tv;
int r = gettimeofday(&tv, NULL); assert(r == 0);
return tv.tv_sec * 1000000ULL + tv.tv_usec;
}
// keep trying if fsync fails because of EINTR
int int
toku_file_fsync(int fd) { toku_file_fsync(int fd) {
int r; int r = -1;
uint64_t tstart = get_tnow();
while (r != 0) {
if (t_fsync) if (t_fsync)
r = t_fsync(fd); r = t_fsync(fd);
else else
r = fsync(fd); r = fsync(fd);
if (r)
assert(errno==EINTR);
}
#if TOKU_WINDOWS_HAS_FAST_ATOMIC_64
toku_sync_fetch_and_increment_uint64(&toku_fsync_count);
toku_sync_fetch_and_add_uint64(&toku_fsync_time, get_tnow() - tstart);
#else
//These two need to be fully 64 bit and atomic.
//The windows atomic add 64 bit is not available.
//toku_sync_fetch_and_add_uint64 (and increment) treat it as 32 bit, and
//would overflow.
//Even on 32 bit machines, aligned 64 bit writes/writes are atomic, so we just
//need to make sure there's only one writer for these two variables.
//Protect with a mutex. Fsync is rare/slow enough that this should be ok.
int r_mutex;
r_mutex = toku_pthread_mutex_lock(&fsync_lock); assert(r_mutex == 0);
toku_fsync_count++;
toku_fsync_time += get_tnow() - tstart;
r_mutex = toku_pthread_mutex_unlock(&fsync_lock); assert(r_mutex == 0);
#endif
return r; return r;
} }
......
...@@ -13,6 +13,8 @@ extern "C" { ...@@ -13,6 +13,8 @@ extern "C" {
//TODO: Sort these into some .h file that makes sense. //TODO: Sort these into some .h file that makes sense.
int fsync(int fildes); int fsync(int fildes);
int toku_fsync_init(void);
int toku_fsync_destroy(void);
int gettimeofday(struct timeval *tv, struct timezone *tz); int gettimeofday(struct timeval *tv, struct timezone *tz);
......
...@@ -44,6 +44,8 @@ toku_portability_init(void) { ...@@ -44,6 +44,8 @@ toku_portability_init(void) {
r = toku_malloc_init(); r = toku_malloc_init();
if (r==0) if (r==0)
r = toku_pthread_win32_init(); r = toku_pthread_win32_init();
if (r==0)
r = toku_fsync_init();
if (r==0) if (r==0)
_fmode = _O_BINARY; //Default open file is BINARY _fmode = _O_BINARY; //Default open file is BINARY
return r; return r;
...@@ -52,6 +54,8 @@ toku_portability_init(void) { ...@@ -52,6 +54,8 @@ toku_portability_init(void) {
int int
toku_portability_destroy(void) { toku_portability_destroy(void) {
int r = 0; int r = 0;
if (r==0)
r = toku_fsync_destroy();
if (r==0) if (r==0)
r = toku_pthread_win32_destroy(); r = toku_pthread_win32_destroy();
return r; return r;
...@@ -248,7 +252,9 @@ toku_os_initialize_settings(int verbosity) { ...@@ -248,7 +252,9 @@ toku_os_initialize_settings(int verbosity) {
int int
toku_os_is_absolute_name(const char* path) { toku_os_is_absolute_name(const char* path) {
return (path[0] == '\\' || return (path[0] == '\\' ||
(isalpha(path[0]) && path[1]==':' && path[2]=='\\')); path[0] == '/' ||
(isalpha(path[0]) && path[1]==':' && path[2]=='\\') ||
(isalpha(path[0]) && path[1]==':' && path[2]=='/'));
} }
int int
......
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