diff --git a/src/aof.c b/src/aof.c index dfd58853c..7f9abce9c 100644 --- a/src/aof.c +++ b/src/aof.c @@ -833,7 +833,7 @@ int openNewIncrAofForAppend(void) { * is already synced at this point so fsync doesn't matter. */ if (server.aof_fd != -1) { aof_background_fsync_and_close(server.aof_fd); - server.aof_last_fsync = server.unixtime; + server.aof_last_fsync = server.mstime; } server.aof_fd = newfd; @@ -954,7 +954,7 @@ void stopAppendOnly(void) { if (redis_fsync(server.aof_fd) == -1) { serverLog(LL_WARNING,"Fail to fsync the AOF file: %s",strerror(errno)); } else { - server.aof_last_fsync = server.unixtime; + server.aof_last_fsync = server.mstime; } close(server.aof_fd); @@ -998,7 +998,7 @@ int startAppendOnly(void) { return C_ERR; } } - server.aof_last_fsync = server.unixtime; + server.aof_last_fsync = server.mstime; /* If AOF fsync error in bio job, we just ignore it and log the event. */ int aof_bio_fsync_status; atomicGet(server.aof_bio_fsync_status, aof_bio_fsync_status); @@ -1074,7 +1074,7 @@ void flushAppendOnlyFile(int force) { * the data in page cache cannot be flushed in time. */ if (server.aof_fsync == AOF_FSYNC_EVERYSEC && server.aof_last_incr_fsync_offset != server.aof_last_incr_size && - server.unixtime > server.aof_last_fsync && + server.mstime - server.aof_last_fsync >= 1000 && !(sync_in_progress = aofFsyncInProgress())) { goto try_fsync; @@ -1109,9 +1109,9 @@ void flushAppendOnlyFile(int force) { if (server.aof_flush_postponed_start == 0) { /* No previous write postponing, remember that we are * postponing the flush and return. */ - server.aof_flush_postponed_start = server.unixtime; + server.aof_flush_postponed_start = server.mstime; return; - } else if (server.unixtime - server.aof_flush_postponed_start < 2) { + } else if (server.mstime - server.aof_flush_postponed_start < 2000) { /* We were already waiting for fsync to finish, but for less * than two seconds this is still ok. Postpone again. */ return; @@ -1260,15 +1260,15 @@ try_fsync: latencyEndMonitor(latency); latencyAddSampleIfNeeded("aof-fsync-always",latency); server.aof_last_incr_fsync_offset = server.aof_last_incr_size; - server.aof_last_fsync = server.unixtime; + server.aof_last_fsync = server.mstime; atomicSet(server.fsynced_reploff_pending, server.master_repl_offset); } else if (server.aof_fsync == AOF_FSYNC_EVERYSEC && - server.unixtime > server.aof_last_fsync) { + server.mstime - server.aof_last_fsync >= 1000) { if (!sync_in_progress) { aof_background_fsync(server.aof_fd); server.aof_last_incr_fsync_offset = server.aof_last_incr_size; } - server.aof_last_fsync = server.unixtime; + server.aof_last_fsync = server.mstime; } } diff --git a/src/server.c b/src/server.c index 7ec315e8f..7aa8e7aab 100644 --- a/src/server.c +++ b/src/server.c @@ -2056,7 +2056,7 @@ void initServerConfig(void) { server.aof_rewrite_base_size = 0; server.aof_rewrite_scheduled = 0; server.aof_flush_sleep = 0; - server.aof_last_fsync = time(NULL); + server.aof_last_fsync = time(NULL) * 1000; server.aof_cur_timestamp = 0; atomicSet(server.aof_bio_fsync_status,C_OK); server.aof_rewrite_time_last = -1; diff --git a/src/server.h b/src/server.h index f0be18fe2..acfbd0934 100644 --- a/src/server.h +++ b/src/server.h @@ -1779,8 +1779,8 @@ struct redisServer { sds aof_buf; /* AOF buffer, written before entering the event loop */ int aof_fd; /* File descriptor of currently selected AOF file */ int aof_selected_db; /* Currently selected DB in AOF */ - time_t aof_flush_postponed_start; /* UNIX time of postponed AOF flush */ - time_t aof_last_fsync; /* UNIX time of last fsync() */ + mstime_t aof_flush_postponed_start; /* mstime of postponed AOF flush */ + mstime_t aof_last_fsync; /* mstime of last fsync() */ time_t aof_rewrite_time_last; /* Time used by last AOF rewrite run. */ time_t aof_rewrite_time_start; /* Current AOF rewrite start time. */ time_t aof_cur_timestamp; /* Current record timestamp in AOF */