diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-01-27 16:48:44 -0500 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-01-27 16:48:44 -0500 |
commit | 9744b58a005e2011f8ffb106208e75d0432fa38b (patch) | |
tree | d7d2a15e2db67f674f2a3033d2ede30e232f34f6 | |
parent | 70d53cfcb4751603f6509ea2c734eccafe565e2e (diff) | |
download | mongo-9744b58a005e2011f8ffb106208e75d0432fa38b.tar.gz |
SERVER-22324 Update findAndModify_inc.js to handle mmapv1 invalidations.
The "findAndModify" command will return a 'value' of null if a document
is invalidated during a yield.
(cherry picked from commit b8cad6a59cbce2831e69e6b94f9544d83d6e00b0)
-rw-r--r-- | jstests/concurrency/fsm_workloads/findAndModify_inc.js | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/jstests/concurrency/fsm_workloads/findAndModify_inc.js b/jstests/concurrency/fsm_workloads/findAndModify_inc.js index 84aa5e3e5b9..2c14791e8d9 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_inc.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_inc.js @@ -10,6 +10,8 @@ * * This workload was designed to reproduce SERVER-15892. */ +load('jstests/concurrency/fsm_workload_helpers/server_types.js'); // for isMongod and isMMAPv1 + var $config = (function() { var states = { @@ -22,20 +24,41 @@ var $config = (function() { update: function update(db, collName) { var updateDoc = { $inc: {} }; updateDoc.$inc[this.fieldName] = 1; - db[collName].findAndModify({ + + var res = db.runCommand({ + findAndModify: collName, query: { _id: 'findAndModify_inc' }, update: updateDoc }); - ++this.count; + assertAlways.commandWorked(res); + + // If the document was invalidated during a yield, then we wouldn't have modified it. + // The "findAndModify" command returns a null value in this case. See SERVER-22002 for + // more details. + if (isMongod(db) && !isMMAPv1(db)) { + // For storage engines other than MMAPv1, if the document is modified by another + // thread during a yield, then the operation is retried internally. We never expect + // to see a null value returned by the "findAndModify" command when it is known that + // a matching document exists in the collection. + assertWhenOwnColl(res.value !== null, 'query spec should have matched a document'); + } + + if (res.value !== null) { + ++this.count; + } }, find: function find(db, collName) { var docs = db[collName].find().toArray(); assertWhenOwnColl.eq(1, docs.length); - assertWhenOwnColl((function() { + assertWhenOwnColl(() => { var doc = docs[0]; - assertWhenOwnColl.eq(this.count, doc[this.fieldName]); - }).bind(this)); + if (doc.hasOwnProperty(this.fieldName)) { + assertWhenOwnColl.eq(this.count, doc[this.fieldName]); + } else { + assertWhenOwnColl.eq(this.count, 0); + } + }); } }; |