Commit e82da34f 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 57bd9114
......@@ -4,6 +4,8 @@
#include <stdint.h>
#include <unistd.h>
#include <windows.h>
#include <toku_atomic.h>
#include <toku_time.h>
int64_t
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)
assert(r==len);
}
// t_fsync exists for testing purposes only
static int (*t_fsync)(int) = 0;
static uint64_t toku_fsync_count;
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
toku_set_func_fsync(int (*fsync_function)(int)) {
t_fsync = fsync_function;
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
toku_file_fsync(int fd) {
int r;
if (t_fsync)
r = t_fsync(fd);
else
r = fsync(fd);
int r = -1;
uint64_t tstart = get_tnow();
while (r != 0) {
if (t_fsync)
r = t_fsync(fd);
else
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;
}
......
......@@ -13,6 +13,8 @@ extern "C" {
//TODO: Sort these into some .h file that makes sense.
int fsync(int fildes);
int toku_fsync_init(void);
int toku_fsync_destroy(void);
int gettimeofday(struct timeval *tv, struct timezone *tz);
......
......@@ -44,6 +44,8 @@ toku_portability_init(void) {
r = toku_malloc_init();
if (r==0)
r = toku_pthread_win32_init();
if (r==0)
r = toku_fsync_init();
if (r==0)
_fmode = _O_BINARY; //Default open file is BINARY
return r;
......@@ -52,6 +54,8 @@ toku_portability_init(void) {
int
toku_portability_destroy(void) {
int r = 0;
if (r==0)
r = toku_fsync_destroy();
if (r==0)
r = toku_pthread_win32_destroy();
return r;
......@@ -248,7 +252,9 @@ toku_os_initialize_settings(int verbosity) {
int
toku_os_is_absolute_name(const char* path) {
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
......
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