Commit 20f15785 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

imp toku_file_fsync in the port layer closes[t:1748]

git-svn-id: file:///svn/toku/tokudb@15805 c7de825b-a66e-492c-adef-691d508d4ae1
parent d1e3911a
...@@ -82,3 +82,20 @@ toku_os_write (int fd, const void *buf, size_t len) { ...@@ -82,3 +82,20 @@ toku_os_write (int fd, const void *buf, size_t len) {
return r; 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;
}
...@@ -2186,9 +2186,10 @@ void *toku_cachefile_get_userdata(CACHEFILE cf) { ...@@ -2186,9 +2186,10 @@ void *toku_cachefile_get_userdata(CACHEFILE cf) {
int int
toku_cachefile_fsync(CACHEFILE cf) { toku_cachefile_fsync(CACHEFILE cf) {
int r; int r;
if (toku_cachefile_is_dev_null(cf))
if (toku_cachefile_is_dev_null(cf)) r = 0; //Don't fsync /dev/null r = 0; //Don't fsync /dev/null
else r = fsync(cf->fd); else
r = toku_file_fsync(cf->fd);
return r; return r;
} }
......
...@@ -10,11 +10,6 @@ static const int log_format_version=TOKU_LOG_VERSION; ...@@ -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 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 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 open_logfile (TOKULOGGER logger);
static int toku_logger_write_buffer (TOKULOGGER logger, int do_fsync); static int toku_logger_write_buffer (TOKULOGGER logger, int do_fsync);
static int delete_logfile(TOKULOGGER logger, long long index); static int delete_logfile(TOKULOGGER logger, long long index);
...@@ -170,7 +165,7 @@ static int write_it (int fd, const void *bufv, int nbytes) { ...@@ -170,7 +165,7 @@ static int write_it (int fd, const void *bufv, int nbytes) {
static int close_and_open_logfile (TOKULOGGER logger) { static int close_and_open_logfile (TOKULOGGER logger) {
int r; int r;
if (logger->write_log_files) { 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); assert(logger->fsynced_lsn.lsn <= logger->written_lsn.lsn);
logger->fsynced_lsn = logger->written_lsn; logger->fsynced_lsn = logger->written_lsn;
} }
...@@ -480,7 +475,7 @@ int toku_logger_maybe_fsync (TOKULOGGER logger, LSN lsn, int do_fsync) ...@@ -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; logger->fsynced_lsn = logger->outbuf.max_lsn_in_buf;
} else { } else {
assert(logger->fsynced_lsn.lsn < logger->written_lsn.lsn); // the fsynced_lsn was less than lsn, but not less than the written lsn? 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; } if (r!=0) { r = errno; goto panic; }
logger->fsynced_lsn = logger->written_lsn; logger->fsynced_lsn = logger->written_lsn;
} }
...@@ -532,7 +527,7 @@ toku_logger_write_buffer (TOKULOGGER logger, int do_fsync) ...@@ -532,7 +527,7 @@ toku_logger_write_buffer (TOKULOGGER logger, int do_fsync)
r = close_and_open_logfile(logger); if (r!=0) goto panic; r = close_and_open_logfile(logger); if (r!=0) goto panic;
logger->fsynced_lsn = logger->outbuf.max_lsn_in_buf; logger->fsynced_lsn = logger->outbuf.max_lsn_in_buf;
} else if (do_fsync) { } 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; logger->fsynced_lsn = logger->outbuf.max_lsn_in_buf;
} else { } else {
/* nothing */ /* nothing */
...@@ -947,11 +942,6 @@ int toku_txnid2txn (TOKULOGGER logger, TXNID txnid, TOKUTXN *result) { ...@@ -947,11 +942,6 @@ int toku_txnid2txn (TOKULOGGER logger, TXNID txnid, TOKUTXN *result) {
return rval; 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 // Find the earliest LSN in a log
static int peek_at_log (TOKULOGGER logger, char* filename, LSN *first_lsn) { static int peek_at_log (TOKULOGGER logger, char* filename, LSN *first_lsn) {
logger=logger; logger=logger;
......
...@@ -121,6 +121,8 @@ void *os_realloc(void*,size_t); ...@@ -121,6 +121,8 @@ void *os_realloc(void*,size_t);
void os_free(void*); 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_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); 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_fsync (int (*fsync_function)(int));
int toku_set_func_malloc (void *(*)(size_t)); int toku_set_func_malloc (void *(*)(size_t));
......
...@@ -108,3 +108,20 @@ toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) ...@@ -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;
}
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