From c43ed406c5980409771a7e36982d4adbbb260425 Mon Sep 17 00:00:00 2001 From: Siddhartha Mahajan Date: Fri, 25 Nov 2022 02:26:07 +0000 Subject: Import wiredtiger: f96dd0257ea106fe8bc301698cfc285e19736ab4 from branch mongodb-master ref: 8341cc7e4b..f96dd0257e for: 6.3.0-rc0 WT-10206 Refactoring log fsync calls --- src/third_party/wiredtiger/import.data | 2 +- src/third_party/wiredtiger/src/log/log.c | 147 +++++++++++++++++-------------- 2 files changed, 84 insertions(+), 65 deletions(-) diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index af21291ffe8..2a4bb363cdd 100644 --- a/src/third_party/wiredtiger/import.data +++ b/src/third_party/wiredtiger/import.data @@ -2,5 +2,5 @@ "vendor": "wiredtiger", "github": "wiredtiger/wiredtiger.git", "branch": "mongodb-master", - "commit": "8341cc7e4b2a411fb68b552dcaf456f120ba20e3" + "commit": "f96dd0257ea106fe8bc301698cfc285e19736ab4" } diff --git a/src/third_party/wiredtiger/src/log/log.c b/src/third_party/wiredtiger/src/log/log.c index 664795625b2..cf12cbabd36 100644 --- a/src/third_party/wiredtiger/src/log/log.c +++ b/src/third_party/wiredtiger/src/log/log.c @@ -219,6 +219,78 @@ __log_fs_write( return (ret); } +/* + * __log_fsync_dir -- + * Perform fsync of log->log_dir_fh. Requires log->log_sync_lock to be held by the caller. + */ +static int +__log_fsync_dir(WT_SESSION_IMPL *session, WT_LSN *min_lsn, const char *method) +{ + WT_LOG *log; + uint64_t fsync_duration_usecs, time_start, time_stop; + + log = S2C(session)->log; + + if (log->sync_dir_lsn.l.file < min_lsn->l.file) { + WT_ASSERT(session, log->log_dir_fh != NULL); + __wt_verbose(session, WT_VERB_LOG, "%s: sync directory %s to LSN %" PRIu32 "/%" PRIu32, + method, log->log_dir_fh->name, min_lsn->l.file, min_lsn->l.offset); + time_start = __wt_clock(session); + WT_RET(__wt_fsync(session, log->log_dir_fh, true)); + time_stop = __wt_clock(session); + fsync_duration_usecs = WT_CLOCKDIFF_US(time_stop, time_start); + WT_ASSIGN_LSN(&log->sync_dir_lsn, min_lsn); + WT_STAT_CONN_INCR(session, log_sync_dir); + WT_STAT_CONN_INCRV(session, log_sync_dir_duration, fsync_duration_usecs); + } + + return (0); +} + +/* + * __log_fsync_file -- + * Perform fsync of log->log_fh if use_own_fh is false. If use_own_fh is true, perform fsync of + * the file specified in min_lsn (will obtain a new file handle to that log file and close it). + * Requires log->log_sync_lock to be held by the caller. + */ +static int +__log_fsync_file(WT_SESSION_IMPL *session, WT_LSN *min_lsn, const char *method, bool use_own_fh) +{ + WT_DECL_RET; + WT_FH *log_fh; + WT_LOG *log; + uint64_t fsync_duration_usecs, time_start, time_stop; + + log = S2C(session)->log; + log_fh = NULL; + + if (__wt_log_cmp(&log->sync_lsn, min_lsn) < 0) { + /* + * Get our own file handle to the log file if requested as it is possible for the file + * handle in the log structure to change out from under us and either be NULL or point to a + * different file than we want. + */ + if (use_own_fh) + WT_ERR(__log_openfile(session, min_lsn->l.file, 0, &log_fh)); + else + log_fh = log->log_fh; + __wt_verbose(session, WT_VERB_LOG, "%s: sync %s to LSN %" PRIu32 "/%" PRIu32, method, + log_fh->name, min_lsn->l.file, min_lsn->l.offset); + time_start = __wt_clock(session); + WT_ERR(__wt_fsync(session, log_fh, true)); + time_stop = __wt_clock(session); + fsync_duration_usecs = WT_CLOCKDIFF_US(time_stop, time_start); + WT_ASSIGN_LSN(&log->sync_lsn, min_lsn); + WT_STAT_CONN_INCR(session, log_sync); + WT_STAT_CONN_INCRV(session, log_sync_duration, fsync_duration_usecs); + __wt_cond_signal(session, log->log_sync_cond); + } +err: + if (use_own_fh && log_fh != NULL) + WT_TRET(__wt_close(session, &log_fh)); + return (ret); +} + /* * __wt_log_ckpt -- * Record the given LSN as the checkpoint LSN and signal the removal thread as needed. @@ -276,12 +348,9 @@ int __wt_log_force_sync(WT_SESSION_IMPL *session, WT_LSN *min_lsn) { WT_DECL_RET; - WT_FH *log_fh; WT_LOG *log; - uint64_t fsync_duration_usecs, time_start, time_stop; log = S2C(session)->log; - log_fh = NULL; /* * We need to wait for the previous log file to get written to disk before we sync out the @@ -293,47 +362,19 @@ __wt_log_force_sync(WT_SESSION_IMPL *session, WT_LSN *min_lsn) __wt_cond_wait(session, log->log_sync_cond, 10000, NULL); } __wt_spin_lock(session, &log->log_sync_lock); - WT_ASSERT(session, log->log_dir_fh != NULL); + /* * Sync the directory if the log file entry hasn't been written into the directory. */ - if (log->sync_dir_lsn.l.file < min_lsn->l.file) { - __wt_verbose(session, WT_VERB_LOG, - "log_force_sync: sync directory %s to LSN %" PRIu32 "/%" PRIu32, log->log_dir_fh->name, - min_lsn->l.file, min_lsn->l.offset); - time_start = __wt_clock(session); - WT_ERR(__wt_fsync(session, log->log_dir_fh, true)); - time_stop = __wt_clock(session); - fsync_duration_usecs = WT_CLOCKDIFF_US(time_stop, time_start); - WT_ASSIGN_LSN(&log->sync_dir_lsn, min_lsn); - WT_STAT_CONN_INCR(session, log_sync_dir); - WT_STAT_CONN_INCRV(session, log_sync_dir_duration, fsync_duration_usecs); - } + WT_ERR(__log_fsync_dir(session, min_lsn, "log_force_sync")); + /* - * Sync the log file if needed. + * Sync the log file if needed. Use a new file handle to the log file by setting use_own_fh to + * true. */ - if (__wt_log_cmp(&log->sync_lsn, min_lsn) < 0) { - /* - * Get our own file handle to the log file. It is possible for the file handle in the log - * structure to change out from under us and either be NULL or point to a different file - * than we want. - */ - WT_ERR(__log_openfile(session, min_lsn->l.file, 0, &log_fh)); - __wt_verbose(session, WT_VERB_LOG, "log_force_sync: sync %s to LSN %" PRIu32 "/%" PRIu32, - log_fh->name, min_lsn->l.file, min_lsn->l.offset); - time_start = __wt_clock(session); - WT_ERR(__wt_fsync(session, log_fh, true)); - time_stop = __wt_clock(session); - fsync_duration_usecs = WT_CLOCKDIFF_US(time_stop, time_start); - WT_ASSIGN_LSN(&log->sync_lsn, min_lsn); - WT_STAT_CONN_INCR(session, log_sync); - WT_STAT_CONN_INCRV(session, log_sync_duration, fsync_duration_usecs); - __wt_cond_signal(session, log->log_sync_cond); - } + WT_ERR(__log_fsync_file(session, min_lsn, "log_force_sync", true)); err: __wt_spin_unlock(session, &log->log_sync_lock); - if (log_fh != NULL) - WT_TRET(__wt_close(session, &log_fh)); return (ret); } @@ -1848,7 +1889,6 @@ __wt_log_release(WT_SESSION_IMPL *session, WT_LOGSLOT *slot, bool *freep) WT_DECL_RET; WT_LOG *log; WT_LSN sync_lsn; - uint64_t fsync_duration_usecs, time_start, time_stop; int64_t release_buffered, release_bytes; bool locked; @@ -1957,36 +1997,15 @@ __wt_log_release(WT_SESSION_IMPL *session, WT_LOGSLOT *slot, bool *freep) * Check if we have to sync the parent directory. Some combinations of sync flags may result * in the log file not yet stable in its parent directory. Do that now if needed. */ - if (F_ISSET(slot, WT_SLOT_SYNC_DIR) && (log->sync_dir_lsn.l.file < sync_lsn.l.file)) { - WT_ASSERT(session, log->log_dir_fh != NULL); - __wt_verbose(session, WT_VERB_LOG, - "log_release: sync directory %s to LSN %" PRIu32 "/%" PRIu32, log->log_dir_fh->name, - sync_lsn.l.file, sync_lsn.l.offset); - time_start = __wt_clock(session); - WT_ERR(__wt_fsync(session, log->log_dir_fh, true)); - time_stop = __wt_clock(session); - fsync_duration_usecs = WT_CLOCKDIFF_US(time_stop, time_start); - WT_ASSIGN_LSN(&log->sync_dir_lsn, &sync_lsn); - WT_STAT_CONN_INCR(session, log_sync_dir); - WT_STAT_CONN_INCRV(session, log_sync_dir_duration, fsync_duration_usecs); - } + if (F_ISSET(slot, WT_SLOT_SYNC_DIR)) + WT_ERR(__log_fsync_dir(session, &sync_lsn, "log_release")); /* * Sync the log file if needed. */ - if (F_ISSET(slot, WT_SLOT_SYNC) && __wt_log_cmp(&log->sync_lsn, &slot->slot_end_lsn) < 0) { - __wt_verbose(session, WT_VERB_LOG, - "log_release: sync log %s to LSN %" PRIu32 "/%" PRIu32, log->log_fh->name, - sync_lsn.l.file, sync_lsn.l.offset); - time_start = __wt_clock(session); - WT_ERR(__wt_fsync(session, log->log_fh, true)); - time_stop = __wt_clock(session); - fsync_duration_usecs = WT_CLOCKDIFF_US(time_stop, time_start); - WT_STAT_CONN_INCR(session, log_sync); - WT_STAT_CONN_INCRV(session, log_sync_duration, fsync_duration_usecs); - WT_ASSIGN_LSN(&log->sync_lsn, &sync_lsn); - __wt_cond_signal(session, log->log_sync_cond); - } + if (F_ISSET(slot, WT_SLOT_SYNC)) + WT_ERR(__log_fsync_file(session, &sync_lsn, "log_release", false)); + /* * Clear the flags before leaving the loop. */ -- cgit v1.2.1