diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-10-14 21:54:02 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-10-14 21:54:02 -0400 |
commit | 0ed1b71a50b45b93f0952e1482643c0d9216731d (patch) | |
tree | 6ae06f4d49aa2b106dfb08fd48f3e52d397ed341 /jstests/concurrency | |
parent | 2c5511c8c411c70ac1063d1209764e71f83d0b1a (diff) | |
download | mongo-0ed1b71a50b45b93f0952e1482643c0d9216731d.tar.gz |
SERVER-31456 Set initial{Cluster,Operation}Time in concurrency suite.
Ensures that the FSM worker threads are guaranteed to observe the
effects of the $config.setup() function being called since they'll
specify an afterClusterTime beyond that point.
Diffstat (limited to 'jstests/concurrency')
-rw-r--r-- | jstests/concurrency/fsm_libs/runner.js | 23 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/worker_thread.js | 15 |
2 files changed, 38 insertions, 0 deletions
diff --git a/jstests/concurrency/fsm_libs/runner.js b/jstests/concurrency/fsm_libs/runner.js index 117d1754419..4997a7bf775 100644 --- a/jstests/concurrency/fsm_libs/runner.js +++ b/jstests/concurrency/fsm_libs/runner.js @@ -537,6 +537,29 @@ var runner = (function() { cleanup.push(workload); }); + // Since the worker threads may be running with causal consistency enabled, we set the + // initial clusterTime and initial operationTime for the sessions they'll create so that + // they are guaranteed to observe the effects of the workload's $config.setup() function + // being called. + if (typeof executionOptions.sessionOptions === 'object' && + executionOptions.sessionOptions !== null) { + // We only start a session for the worker threads and never start one for the main + // thread. We can therefore get the clusterTime and operationTime tracked by the + // underlying DummyDriverSession through any DB instance (i.e. the "test" database + // here was chosen arbitrarily). + const session = cluster.getDB('test').getSession(); + + // JavaScript objects backed by C++ objects (e.g. BSON values from a command + // response) do not serialize correctly when passed through the ScopedThread + // constructor. To work around this behavior, we instead pass a stringified form of + // the JavaScript object through the ScopedThread constructor and use eval() to + // rehydrate it. + executionOptions.sessionOptions.initialClusterTime = + tojson(session.getClusterTime()); + executionOptions.sessionOptions.initialOperationTime = + tojson(session.getOperationTime()); + } + if (cluster.shouldPerformContinuousStepdowns()) { cluster.startContinuousFailover(); } diff --git a/jstests/concurrency/fsm_libs/worker_thread.js b/jstests/concurrency/fsm_libs/worker_thread.js index 44bdb870d0c..d03e7393214 100644 --- a/jstests/concurrency/fsm_libs/worker_thread.js +++ b/jstests/concurrency/fsm_libs/worker_thread.js @@ -38,6 +38,21 @@ var workerThread = (function() { } if (typeof args.sessionOptions !== 'undefined') { + // JavaScript objects backed by C++ objects (e.g. BSON values from a command + // response) do not serialize correctly when passed through the ScopedThread + // constructor. To work around this behavior, we instead pass a stringified form + // of the JavaScript object through the ScopedThread constructor and use eval() + // to rehydrate it. + if (typeof args.sessionOptions.initialClusterTime === 'string') { + args.sessionOptions.initialClusterTime = + eval('(' + args.sessionOptions.initialClusterTime + ')'); + } + + if (typeof args.sessionOptions.initialOperationTime === 'string') { + args.sessionOptions.initialOperationTime = + eval('(' + args.sessionOptions.initialOperationTime + ')'); + } + myDB = new Mongo(args.host) .startSession(args.sessionOptions) .getDatabase(args.dbName); |