diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-01-27 16:32:36 -0500 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-01-27 16:32:36 -0500 |
commit | b8cad6a59cbce2831e69e6b94f9544d83d6e00b0 (patch) | |
tree | de37b636b0710365629762947e000b1a3ac97faa | |
parent | 11a4e78df9128c7116da1c2da055aa6faccbdf08 (diff) | |
download | mongo-b8cad6a59cbce2831e69e6b94f9544d83d6e00b0.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.
-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); + } + }); } }; |