From e8a671d6116239fda899e7d35e29f29bf10607f3 Mon Sep 17 00:00:00 2001 From: Rich Prohaska Date: Tue, 16 Apr 2013 23:58:52 -0400 Subject: [PATCH] imp toku_file_fsync in the port layer closes[t:1748] git-svn-id: file:///svn/toku/tokudb@15805 c7de825b-a66e-492c-adef-691d508d4ae1 --- linux/file.c | 17 +++++++++++++++++ newbrt/cachetable.c | 7 ++++--- newbrt/logger.c | 16 +++------------- toku_include/toku_portability.h | 2 ++ windows/file.c | 17 +++++++++++++++++ 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/linux/file.c b/linux/file.c index 90bab2a904b..8b0e9eabd73 100644 --- a/linux/file.c +++ b/linux/file.c @@ -82,3 +82,20 @@ again: return r; } +static int (*t_fsync)(int) = 0; + +int +toku_set_func_fsync(int (*fsync_function)(int)) { + t_fsync = fsync_function; + return 0; +} + +int +toku_file_fsync(int fd) { + int r; + if (t_fsync) + r = t_fsync(fd); + else + r = fsync(fd); + return r; +} diff --git a/newbrt/cachetable.c b/newbrt/cachetable.c index 27e60257159..c08cd6f9499 100644 --- a/newbrt/cachetable.c +++ b/newbrt/cachetable.c @@ -2186,9 +2186,10 @@ void *toku_cachefile_get_userdata(CACHEFILE cf) { int toku_cachefile_fsync(CACHEFILE cf) { int r; - - if (toku_cachefile_is_dev_null(cf)) r = 0; //Don't fsync /dev/null - else r = fsync(cf->fd); + if (toku_cachefile_is_dev_null(cf)) + r = 0; //Don't fsync /dev/null + else + r = toku_file_fsync(cf->fd); return r; } diff --git a/newbrt/logger.c b/newbrt/logger.c index d4deb07bd44..f7790991c3a 100644 --- a/newbrt/logger.c +++ b/newbrt/logger.c @@ -10,11 +10,6 @@ static const int log_format_version=TOKU_LOG_VERSION; static toku_pthread_mutex_t logger_mutex = TOKU_PTHREAD_MUTEX_INITIALIZER; static u_int32_t logger_lock_ctr = 0; // useful for debug at a live installation -static int toku_fsync(int UU(fd)) { - return fsync(fd); -} - -static int (*toku_os_fsync_function)(int)=toku_fsync; static int open_logfile (TOKULOGGER logger); static int toku_logger_write_buffer (TOKULOGGER logger, int do_fsync); static int delete_logfile(TOKULOGGER logger, long long index); @@ -170,7 +165,7 @@ static int write_it (int fd, const void *bufv, int nbytes) { static int close_and_open_logfile (TOKULOGGER logger) { int r; if (logger->write_log_files) { - r = toku_os_fsync_function(logger->fd); if (r!=0) return errno; + r = toku_file_fsync(logger->fd); if (r!=0) return errno; assert(logger->fsynced_lsn.lsn <= logger->written_lsn.lsn); logger->fsynced_lsn = logger->written_lsn; } @@ -480,7 +475,7 @@ int toku_logger_maybe_fsync (TOKULOGGER logger, LSN lsn, int do_fsync) logger->fsynced_lsn = logger->outbuf.max_lsn_in_buf; } else { assert(logger->fsynced_lsn.lsn < logger->written_lsn.lsn); // the fsynced_lsn was less than lsn, but not less than the written lsn? - r = toku_os_fsync_function(logger->fd); + r = toku_file_fsync(logger->fd); if (r!=0) { r = errno; goto panic; } logger->fsynced_lsn = logger->written_lsn; } @@ -532,7 +527,7 @@ toku_logger_write_buffer (TOKULOGGER logger, int do_fsync) r = close_and_open_logfile(logger); if (r!=0) goto panic; logger->fsynced_lsn = logger->outbuf.max_lsn_in_buf; } else if (do_fsync) { - r = toku_os_fsync_function(logger->fd); + r = toku_file_fsync(logger->fd); logger->fsynced_lsn = logger->outbuf.max_lsn_in_buf; } else { /* nothing */ @@ -947,11 +942,6 @@ int toku_txnid2txn (TOKULOGGER logger, TXNID txnid, TOKUTXN *result) { return rval; } -int toku_set_func_fsync (int (*fsync_function)(int)) { - toku_os_fsync_function = fsync_function; - return 0; -} - // Find the earliest LSN in a log static int peek_at_log (TOKULOGGER logger, char* filename, LSN *first_lsn) { logger=logger; diff --git a/toku_include/toku_portability.h b/toku_include/toku_portability.h index a16ac042a64..c8f56e13b79 100644 --- a/toku_include/toku_portability.h +++ b/toku_include/toku_portability.h @@ -121,6 +121,8 @@ void *os_realloc(void*,size_t); void os_free(void*); ssize_t toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off); ssize_t toku_os_write (int fd, const void *buf, size_t len); +int toku_file_fsync(int fd); +int toku_get_fsync_times(void); int toku_set_func_fsync (int (*fsync_function)(int)); int toku_set_func_malloc (void *(*)(size_t)); diff --git a/windows/file.c b/windows/file.c index dc8ebcf0fd0..198d1d7b1c7 100644 --- a/windows/file.c +++ b/windows/file.c @@ -108,3 +108,20 @@ toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) } } +static int (*t_fsync)(int) = 0; + +int +toku_set_func_fsync(int (*fsync_function)(int)) { + t_fsync = fsync_function; + return 0; +} + +int +toku_file_fsync(int fd) { + int r; + if (t_fsync) + r = t_fsync(fd); + else + r = fsync(fd); + return r; +}