diff options
Diffstat (limited to 'src/include/misc.i')
-rw-r--r-- | src/include/misc.i | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/include/misc.i b/src/include/misc.i index 7040886cf82..fad10f01103 100644 --- a/src/include/misc.i +++ b/src/include/misc.i @@ -55,6 +55,31 @@ __wt_seconds(WT_SESSION_IMPL *session, time_t *timep) } /* + * __wt_time_check_monotonic -- + * Check and prevent time running backward. If we detect that it has, we + * set the time structure to the previous values, making time stand still + * until we see a time in the future of the highest value seen so far. + */ +static inline void +__wt_time_check_monotonic(WT_SESSION_IMPL *session, struct timespec *tsp) +{ + /* + * Detect time going backward. If so, use the last + * saved timestamp. + */ + if (session == NULL) + return; + + if (tsp->tv_sec < session->last_epoch.tv_sec || + (tsp->tv_sec == session->last_epoch.tv_sec && + tsp->tv_nsec < session->last_epoch.tv_nsec)) { + WT_STAT_CONN_INCR(session, time_travel); + *tsp = session->last_epoch; + } else + session->last_epoch = *tsp; +} + +/* * __wt_verbose -- * Verbose message. * |