From b29429ecc5d3ee3907ac7d36c6c125d84c810e52 Mon Sep 17 00:00:00 2001 From: Luke Chen Date: Wed, 21 Dec 2022 15:39:21 +1100 Subject: Import wiredtiger: a7f6fa07f90d701b73206a768ae0cc6fb50ff9b4 from branch mongodb-master ref: 2a414fdee9..a7f6fa07f9 for: 6.3.0-rc0 WT-10338 Ensure threads get uncorrelated sequences of random values. --- src/third_party/wiredtiger/import.data | 2 +- src/third_party/wiredtiger/src/support/rand.c | 28 ++++++++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index ceea0768674..312642f040d 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": "2a414fdee92400156ab05de39b6f0c2363a73469" + "commit": "a7f6fa07f90d701b73206a768ae0cc6fb50ff9b4" } diff --git a/src/third_party/wiredtiger/src/support/rand.c b/src/third_party/wiredtiger/src/support/rand.c index c011d1144e0..67bb6ad7f4f 100644 --- a/src/third_party/wiredtiger/src/support/rand.c +++ b/src/third_party/wiredtiger/src/support/rand.c @@ -83,29 +83,25 @@ __wt_random_init_seed(WT_SESSION_IMPL *session, WT_RAND_STATE volatile *rnd_stat { struct timespec ts; WT_RAND_STATE rnd; - uint32_t v; + uintmax_t threadid; __wt_epoch(session, &ts); + __wt_thread_id(&threadid); /* - * Use this, instead of __wt_random_init if we need to vary the initial state of the RNG. This - * is (currently) only used by test programs, where, for example, an initial set of test data is + * Use this, instead of __wt_random_init, to vary the initial state of the RNG. This is + * (currently) only used by test programs, where, for example, an initial set of test data is * created by a single thread, and we want more variability in the initial state of the RNG. * - * Take the seconds and nanoseconds from the clock as seeds, and smear that value across the - * value space, using algorithm "xor" from Marsaglia, "Xorshift RNGs". + * Take the seconds and nanoseconds from the clock together with the thread ID to generate a + * 64-bit seed, then smear that value using algorithm "xor" from Marsaglia, "Xorshift RNGs". */ - v = (uint32_t)ts.tv_sec; - v ^= v << 13; - v ^= v >> 17; - v ^= v << 5; - M_W(rnd) = v + 521288629; - - v = (uint32_t)ts.tv_nsec; - v ^= v << 13; - v ^= v >> 17; - v ^= v << 5; - M_Z(rnd) = v + 362436069; + M_W(rnd) = (uint32_t)ts.tv_sec ^ 521288629; + M_Z(rnd) = (uint32_t)ts.tv_nsec ^ 362436069; + rnd.v ^= (uint64_t)threadid; + rnd.v ^= rnd.v << 13; + rnd.v ^= rnd.v >> 7; + rnd.v ^= rnd.v << 17; *rnd_state = rnd; } -- cgit v1.2.1