diff options
author | Alex Gorrod <alexander.gorrod@mongodb.com> | 2017-08-01 16:42:49 +1000 |
---|---|---|
committer | Alex Gorrod <alexander.gorrod@mongodb.com> | 2017-08-01 16:42:49 +1000 |
commit | 835bfb21d8e67663d84a40aa4f7370a4403725a9 (patch) | |
tree | 4f5edb231524f95272f834e31461ba4e17e52903 /src/third_party/wiredtiger/src/os_posix | |
parent | 6300b3bd4ad9cd238a02bdb8ca681a447913f1af (diff) | |
download | mongo-835bfb21d8e67663d84a40aa4f7370a4403725a9.tar.gz |
Import wiredtiger: 2e9744d11a65c63ba7445060dc78371250f04051 from branch mongodb-3.6
ref: 6173a98979..2e9744d11a
for: 3.5.11
WT-2309 Add yields and/or sleeps in #DIAGNOSTIC mode
WT-3047 Add mode aimed at uncovering race conditions in split code
WT-3308 Add statistics tracking around yield loops
WT-3316 Add new engineering section to reference guide documentation
WT-3338 Optimize cursor modify
WT-3380 Special case 8-byte timestamps
WT-3387 Add support for a stable timestamp
WT-3389 Restructure split code to hold a split generation for the entire operation.
WT-3406 Reconciliation is choosing reserved records for writing.
WT-3410 Add developer documentation for table rename
WT-3412 Add backoff logic to the btree delete and walk yield loops
WT-3418 block manager object race
WT-3422 WiredTiger upgrading documents out of date
WT-3432 workgen needs braces around an "if" body
WT-3433 session->alter method should not be supported in read-only mode
WT-3439 lint/cleanup
WT-3440 Add a log record when starting a checkpoint
WT-3442 Coverity 1378213: false positive on diagnostic assignment.
WT-3446 Temporarily disable timestamp testing in test/checkpoint
WT-3447 test_stat_log02 can assert before table stats are printed
WT-3461 Avoid long sleeps when the system clock is adjusted
WT-3463 Add recovery of backup to test_timestamp03.py
WT-3466 Track the first commit timestamp for each transaction
WT-3467 Minor lint/cleanup
Diffstat (limited to 'src/third_party/wiredtiger/src/os_posix')
-rw-r--r-- | src/third_party/wiredtiger/src/os_posix/os_mtx_cond.c | 33 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/os_posix/os_time.c | 27 |
2 files changed, 37 insertions, 23 deletions
diff --git a/src/third_party/wiredtiger/src/os_posix/os_mtx_cond.c b/src/third_party/wiredtiger/src/os_posix/os_mtx_cond.c index 1018bf860d6..5d0295d94ce 100644 --- a/src/third_party/wiredtiger/src/os_posix/os_mtx_cond.c +++ b/src/third_party/wiredtiger/src/os_posix/os_mtx_cond.c @@ -19,11 +19,19 @@ __wt_cond_alloc(WT_SESSION_IMPL *session, const char *name, WT_CONDVAR **condp) WT_DECL_RET; WT_RET(__wt_calloc_one(session, &cond)); - WT_ERR(pthread_mutex_init(&cond->mtx, NULL)); - /* Initialize the condition variable to permit self-blocking. */ +#ifdef HAVE_PTHREAD_COND_MONOTONIC + { + pthread_condattr_t condattr; + + WT_ERR(pthread_condattr_init(&condattr)); + WT_ERR(pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC)); + WT_ERR(pthread_cond_init(&cond->cond, &condattr)); + } +#else WT_ERR(pthread_cond_init(&cond->cond, NULL)); +#endif cond->name = name; cond->waiters = 0; @@ -79,7 +87,26 @@ __wt_cond_wait_signal(WT_SESSION_IMPL *session, WT_CONDVAR *cond, goto skipping; if (usecs > 0) { - __wt_epoch(session, &ts); + /* + * Get the current time as the basis for calculating when the + * wait should end. Prefer a monotonic clock source to avoid + * unexpectedly long sleeps when the system clock is adjusted. + * + * Failing that, query the time directly and don't attempt to + * correct for the clock moving backwards, which would result + * in a sleep that is too long by however much the clock is + * updated. This isn't as good as a monotonic clock source but + * makes the window of vulnerability smaller (i.e., the + * calculated time is only incorrect if the system clock + * changes in between us querying it and waiting). + */ +#ifdef HAVE_PTHREAD_COND_MONOTONIC + WT_SYSCALL_RETRY(clock_gettime(CLOCK_MONOTONIC, &ts), ret); + if (ret != 0) + WT_PANIC_MSG(session, ret, "clock_gettime"); +#else + __wt_epoch_raw(session, &ts); +#endif ts.tv_sec += (time_t) (((uint64_t)ts.tv_nsec + WT_THOUSAND * usecs) / WT_BILLION); ts.tv_nsec = (long) diff --git a/src/third_party/wiredtiger/src/os_posix/os_time.c b/src/third_party/wiredtiger/src/os_posix/os_time.c index cc9516468aa..1b7a9359531 100644 --- a/src/third_party/wiredtiger/src/os_posix/os_time.c +++ b/src/third_party/wiredtiger/src/os_posix/os_time.c @@ -9,14 +9,12 @@ #include "wt_internal.h" /* - * __wt_epoch -- - * Return the time since the Epoch. + * __wt_epoch_raw -- + * Return the time since the Epoch as reported by a system call. */ void -__wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp) - WT_GCC_FUNC_ATTRIBUTE((visibility("default"))) +__wt_epoch_raw(WT_SESSION_IMPL *session, struct timespec *tsp) { - struct timespec tmp; WT_DECL_RET; /* @@ -28,19 +26,10 @@ __wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp) tsp->tv_sec = 0; tsp->tv_nsec = 0; - /* - * Read into a local variable so that we're comparing the correct - * value when we check for monotonic increasing time. There are - * many places we read into an unlocked global variable. - */ #if defined(HAVE_CLOCK_GETTIME) - WT_SYSCALL_RETRY(clock_gettime(CLOCK_REALTIME, &tmp), ret); - if (ret == 0) { - __wt_time_check_monotonic(session, &tmp); - tsp->tv_sec = tmp.tv_sec; - tsp->tv_nsec = tmp.tv_nsec; + WT_SYSCALL_RETRY(clock_gettime(CLOCK_REALTIME, tsp), ret); + if (ret == 0) return; - } WT_PANIC_MSG(session, ret, "clock_gettime"); #elif defined(HAVE_GETTIMEOFDAY) { @@ -48,10 +37,8 @@ __wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp) WT_SYSCALL_RETRY(gettimeofday(&v, NULL), ret); if (ret == 0) { - tmp.tv_sec = v.tv_sec; - tmp.tv_nsec = v.tv_usec * WT_THOUSAND; - __wt_time_check_monotonic(session, &tmp); - *tsp = tmp; + tsp->tv_sec = v.tv_sec; + tsp->tv_nsec = v.tv_usec * WT_THOUSAND; return; } WT_PANIC_MSG(session, ret, "gettimeofday"); |