diff options
author | James Wahlin <james@mongodb.com> | 2018-03-09 14:36:56 -0500 |
---|---|---|
committer | James Wahlin <james@mongodb.com> | 2018-03-20 14:07:58 -0400 |
commit | aaba5b468e67f81380f7fa099932a2722dab3a8a (patch) | |
tree | 26ed3e02b960230d1bc1c4ff17507e153b73354b /jstests/noPassthrough/snapshot_reads.js | |
parent | 3ef314d05280a5acfd84f3a8bb26e3bb9f31abde (diff) | |
download | mongo-aaba5b468e67f81380f7fa099932a2722dab3a8a.tar.gz |
SERVER-33354 Add snapshot read support for additional commands
Diffstat (limited to 'jstests/noPassthrough/snapshot_reads.js')
-rw-r--r-- | jstests/noPassthrough/snapshot_reads.js | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/jstests/noPassthrough/snapshot_reads.js b/jstests/noPassthrough/snapshot_reads.js index 5f6f7774d98..a431861aab4 100644 --- a/jstests/noPassthrough/snapshot_reads.js +++ b/jstests/noPassthrough/snapshot_reads.js @@ -20,6 +20,20 @@ } const secondaryDB = rst.getSecondary().getDB(dbName); + function parseCursor(cmdResult) { + if (cmdResult.hasOwnProperty("cursor")) { + assert(cmdResult.cursor.hasOwnProperty("id")); + return cmdResult.cursor; + } else if (cmdResult.hasOwnProperty("cursors") && cmdResult.cursors.length === 1 && + cmdResult.cursors[0].hasOwnProperty("cursor")) { + assert(cmdResult.cursors[0].cursor.hasOwnProperty("id")); + return cmdResult.cursors[0].cursor; + } + + throw Error("parseCursor failed to find cursor object. Command Result: " + + tojson(cmdResult)); + } + function runTest({useCausalConsistency, readFromSecondary, establishCursorCmd}) { primaryDB.coll.drop(); @@ -51,14 +65,11 @@ // Establish a snapshot batchSize:0 cursor. let res = assert.commandWorked(sessionDb.runCommand(cursorCmd)); + let cursor = parseCursor(res); - assert(res.hasOwnProperty("cursor"), tojson(res)); - assert(res.cursor.hasOwnProperty("firstBatch"), tojson(res)); - assert.eq(0, res.cursor.firstBatch.length, tojson(res)); - - assert(res.cursor.hasOwnProperty("id"), tojson(res)); - const cursorId = res.cursor.id; - assert.neq(cursorId, 0); + assert(cursor.hasOwnProperty("firstBatch"), tojson(res)); + assert.eq(0, cursor.firstBatch.length, tojson(res)); + assert.neq(cursor.id, 0); // Insert an 11th document which should not be visible to the snapshot cursor. This write is // performed outside of the session. @@ -66,35 +77,33 @@ // Fetch the first 5 documents. res = assert.commandWorked(sessionDb.runCommand({ - getMore: cursorId, + getMore: cursor.id, collection: collName, batchSize: 5, txnNumber: NumberLong(txnNumber) })); - assert(res.hasOwnProperty("cursor"), tojson(res)); - assert(res.cursor.hasOwnProperty("id"), tojson(res)); - assert.neq(0, res.cursor.id, tojson(res)); - assert(res.cursor.hasOwnProperty("nextBatch"), tojson(res)); - assert.eq(5, res.cursor.nextBatch.length, tojson(res)); + cursor = parseCursor(res); + assert.neq(0, cursor.id, tojson(res)); + assert(cursor.hasOwnProperty("nextBatch"), tojson(res)); + assert.eq(5, cursor.nextBatch.length, tojson(res)); // Exhaust the cursor, retrieving the remainder of the result set. Performing a second // getMore tests snapshot isolation across multiple getMore invocations. res = assert.commandWorked(sessionDb.runCommand({ - getMore: cursorId, + getMore: cursor.id, collection: collName, batchSize: 20, txnNumber: NumberLong(txnNumber++) })); // The cursor has been exhausted. - assert(res.hasOwnProperty("cursor"), tojson(res)); - assert(res.cursor.hasOwnProperty("id"), tojson(res)); - assert.eq(0, res.cursor.id, tojson(res)); + cursor = parseCursor(res); + assert.eq(0, cursor.id, tojson(res)); // Only the remaining 5 of the initial 10 documents are returned. The 11th document is not // part of the result set. - assert(res.cursor.hasOwnProperty("nextBatch"), tojson(res)); - assert.eq(5, res.cursor.nextBatch.length, tojson(res)); + assert(cursor.hasOwnProperty("nextBatch"), tojson(res)); + assert.eq(5, cursor.nextBatch.length, tojson(res)); if (readFromSecondary) { rst.awaitLastOpCommitted(); @@ -110,13 +119,12 @@ })); // The cursor has been exhausted. - assert(res.hasOwnProperty("cursor"), tojson(res)); - assert(res.cursor.hasOwnProperty("id"), tojson(res)); - assert.eq(0, res.cursor.id, tojson(res)); + cursor = parseCursor(res); + assert.eq(0, cursor.id, tojson(res)); // All 11 documents are returned. - assert(res.cursor.hasOwnProperty("firstBatch"), tojson(res)); - assert.eq(11, res.cursor.firstBatch.length, tojson(res)); + assert(cursor.hasOwnProperty("firstBatch"), tojson(res)); + assert.eq(11, cursor.firstBatch.length, tojson(res)); // Reject snapshot reads without txnNumber. assert.commandFailed(sessionDb.runCommand( @@ -148,5 +156,28 @@ runTest({useCausalConsistency: false, readFromSecondary: true, establishCursorCmd: aggCmd}); runTest({useCausalConsistency: true, readFromSecondary: true, establishCursorCmd: aggCmd}); + // Test snapshot reads using parallelCollectionScan. + let parallelCollScanCmd = {parallelCollectionScan: collName, numCursors: 1}; + runTest({ + useCausalConsistency: false, + readFromSecondary: false, + establishCursorCmd: parallelCollScanCmd + }); + runTest({ + useCausalConsistency: true, + readFromSecondary: false, + establishCursorCmd: parallelCollScanCmd + }); + runTest({ + useCausalConsistency: false, + readFromSecondary: true, + establishCursorCmd: parallelCollScanCmd + }); + runTest({ + useCausalConsistency: true, + readFromSecondary: true, + establishCursorCmd: parallelCollScanCmd + }); + rst.stopSet(); })(); |