diff options
author | Mathias Stearn <mathias@10gen.com> | 2015-04-14 18:13:08 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2015-06-29 19:23:15 -0400 |
commit | 28be53c1c9721c4ef8a3046bb3546a1b63e759f6 (patch) | |
tree | bdfd20f4ef40f02ebbd6ad307fc04e201316f8ca /jstests/replsets/read_committed.js | |
parent | d7f068a0fb33b2c85d7909e03edbe65a25b2f8e0 (diff) | |
download | mongo-28be53c1c9721c4ef8a3046bb3546a1b63e759f6.tar.gz |
SERVER-18022 Read Majority Committed implementation for primary nodes
Diffstat (limited to 'jstests/replsets/read_committed.js')
-rw-r--r-- | jstests/replsets/read_committed.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/jstests/replsets/read_committed.js b/jstests/replsets/read_committed.js new file mode 100644 index 00000000000..1fae055253e --- /dev/null +++ b/jstests/replsets/read_committed.js @@ -0,0 +1,66 @@ +// Test basic read committed functionality. +(function() { +"use strict"; + +// Set up a set and grab things for later. +var name = "read_committed"; +var replTest = new ReplSetTest({name: name, + nodes: 3, + nodeOptions: {setParameter: "enableReplSnapshotThread=true"}}); +var nodes = replTest.nodeList(); +var conns = replTest.startSet(); +replTest.initiate({"_id": name, + "members": [ + { "_id": 0, "host": nodes[0] }, + { "_id": 1, "host": nodes[1] }, + { "_id": 2, "host": nodes[2], arbiterOnly: true}] + }); + +// Get connections and collection. +var master = replTest.getMaster(); +var slave = replTest.liveNodes.slaves[0]; +var slaveId = replTest.getNodeId(slave); +var db = master.getDB(name); +var t = db[name]; + +if (!db.serverStatus().storageEngine.supportsCommittedReads) { + assert.neq(db.serverStatus().storageEngine.name, "wiredTiger"); + jsTest.log("skipping test since storage engine doesn't support committed reads"); + return; +} + +function doDirtyRead() { + var res = t.runCommand('find', {$readMajorityTemporaryName: false}); + assert.commandWorked(res); + return new DBCommandCursor(db.getMongo(), res).toArray()[0].state; +} + +function doCommittedRead() { + var res = t.runCommand('find', {$readMajorityTemporaryName: true}); + assert.commandWorked(res); + return new DBCommandCursor(db.getMongo(), res).toArray()[0].state; +} + +// Do a write, wait for it to replicate, and ensure it is visible. +assert.writeOK(t.save({_id: 1, state: 0}, {writeConcern: {w: 2, wtimeout: 60*1000}})); +assert.eq(doDirtyRead(), 0); +assert.eq(doCommittedRead(), 0); + +replTest.stop(slaveId); + +// Do a write and ensure it is only visible to dirty reads +assert.writeOK(t.save({_id: 1, state: 1})); +assert.eq(doDirtyRead(), 1); +assert.eq(doCommittedRead(), 0); + +// Try the committed read again after sleeping to ensure it doesn't only work for queries +// immediately after the write. +sleep(1000); +assert.eq(doCommittedRead(), 0); + +// Restart the node and ensure the committed view is updated. +replTest.restart(slaveId); +db.getLastError(2, 60*1000); +assert.eq(doDirtyRead(), 1); +assert.eq(doCommittedRead(), 1); +}()); |