diff options
Diffstat (limited to 'jstests/replsets/change_stream_speculative_majority_optimized_wait.js')
-rw-r--r-- | jstests/replsets/change_stream_speculative_majority_optimized_wait.js | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/jstests/replsets/change_stream_speculative_majority_optimized_wait.js b/jstests/replsets/change_stream_speculative_majority_optimized_wait.js index 20585c11336..65bd4599722 100644 --- a/jstests/replsets/change_stream_speculative_majority_optimized_wait.js +++ b/jstests/replsets/change_stream_speculative_majority_optimized_wait.js @@ -6,78 +6,78 @@ * @tags: [uses_speculative_majority] */ (function() { - "use strict"; +"use strict"; - load("jstests/libs/write_concern_util.js"); // for [stop|restart]ServerReplication. +load("jstests/libs/write_concern_util.js"); // for [stop|restart]ServerReplication. - const name = "change_stream_speculative_majority"; - const replTest = new ReplSetTest({ - name: name, - nodes: [{}, {rsConfig: {priority: 0}}], - nodeOptions: {enableMajorityReadConcern: 'false'} - }); - replTest.startSet(); - replTest.initiate(); +const name = "change_stream_speculative_majority"; +const replTest = new ReplSetTest({ + name: name, + nodes: [{}, {rsConfig: {priority: 0}}], + nodeOptions: {enableMajorityReadConcern: 'false'} +}); +replTest.startSet(); +replTest.initiate(); - const dbName = name; - const collName = "coll"; +const dbName = name; +const collName = "coll"; - let primary = replTest.getPrimary(); - let secondary = replTest.getSecondary(); - let primaryDB = primary.getDB(dbName); - let primaryColl = primaryDB[collName]; +let primary = replTest.getPrimary(); +let secondary = replTest.getSecondary(); +let primaryDB = primary.getDB(dbName); +let primaryColl = primaryDB[collName]; - // Receive 1 change to get an initial resume token. - let res = assert.commandWorked( - primaryDB.runCommand({aggregate: collName, pipeline: [{$changeStream: {}}], cursor: {}})); - let cursorId = res.cursor.id; - assert.commandWorked(primaryColl.insert({_id: 0}, {writeConcern: {w: "majority"}})); - res = primary.getDB(dbName).runCommand({getMore: cursorId, collection: collName}); - assert.eq(res.cursor.nextBatch.length, 1); - let resumeToken = res.cursor.nextBatch[0]["_id"]; +// Receive 1 change to get an initial resume token. +let res = assert.commandWorked( + primaryDB.runCommand({aggregate: collName, pipeline: [{$changeStream: {}}], cursor: {}})); +let cursorId = res.cursor.id; +assert.commandWorked(primaryColl.insert({_id: 0}, {writeConcern: {w: "majority"}})); +res = primary.getDB(dbName).runCommand({getMore: cursorId, collection: collName}); +assert.eq(res.cursor.nextBatch.length, 1); +let resumeToken = res.cursor.nextBatch[0]["_id"]; - // Open a change stream. - res = assert.commandWorked( - primaryDB.runCommand({aggregate: collName, pipeline: [{$changeStream: {}}], cursor: {}})); - cursorId = res.cursor.id; +// Open a change stream. +res = assert.commandWorked( + primaryDB.runCommand({aggregate: collName, pipeline: [{$changeStream: {}}], cursor: {}})); +cursorId = res.cursor.id; - // Insert documents to fill one batch and let them majority commit. - let batchSize = 2; - assert.commandWorked(primaryColl.insert({_id: 1}, {writeConcern: {w: "majority"}})); - assert.commandWorked(primaryColl.insert({_id: 2}, {writeConcern: {w: "majority"}})); +// Insert documents to fill one batch and let them majority commit. +let batchSize = 2; +assert.commandWorked(primaryColl.insert({_id: 1}, {writeConcern: {w: "majority"}})); +assert.commandWorked(primaryColl.insert({_id: 2}, {writeConcern: {w: "majority"}})); - // Pause replication on the secondary so that writes won't majority commit. - stopServerReplication(secondary); +// Pause replication on the secondary so that writes won't majority commit. +stopServerReplication(secondary); - // Do write on primary that won't majority commit but will advance the last applied optime. - assert.commandWorked(primaryColl.insert({_id: 3})); +// Do write on primary that won't majority commit but will advance the last applied optime. +assert.commandWorked(primaryColl.insert({_id: 3})); - // Receive one batch of change events. We should be able to read only the majority committed - // change events and no further in order to generate this batch. - res = assert.commandWorked(primary.getDB(dbName).runCommand( - {getMore: cursorId, collection: collName, batchSize: batchSize})); - let changes = res.cursor.nextBatch; - assert.eq(changes.length, 2); - assert.eq(changes[0]["fullDocument"], {_id: 1}); - assert.eq(changes[0]["operationType"], "insert"); - assert.eq(changes[1]["fullDocument"], {_id: 2}); - assert.eq(changes[1]["operationType"], "insert"); +// Receive one batch of change events. We should be able to read only the majority committed +// change events and no further in order to generate this batch. +res = assert.commandWorked(primary.getDB(dbName).runCommand( + {getMore: cursorId, collection: collName, batchSize: batchSize})); +let changes = res.cursor.nextBatch; +assert.eq(changes.length, 2); +assert.eq(changes[0]["fullDocument"], {_id: 1}); +assert.eq(changes[0]["operationType"], "insert"); +assert.eq(changes[1]["fullDocument"], {_id: 2}); +assert.eq(changes[1]["operationType"], "insert"); - // Make sure that 'aggregate' commands also utilize the optimization. - res = assert.commandWorked(primaryDB.runCommand({ - aggregate: collName, - pipeline: [{$changeStream: {resumeAfter: resumeToken}}], - cursor: {batchSize: batchSize} - })); - changes = res.cursor.firstBatch; - assert.eq(changes.length, 2); - assert.eq(changes[0]["fullDocument"], {_id: 1}); - assert.eq(changes[0]["operationType"], "insert"); - assert.eq(changes[1]["fullDocument"], {_id: 2}); - assert.eq(changes[1]["operationType"], "insert"); +// Make sure that 'aggregate' commands also utilize the optimization. +res = assert.commandWorked(primaryDB.runCommand({ + aggregate: collName, + pipeline: [{$changeStream: {resumeAfter: resumeToken}}], + cursor: {batchSize: batchSize} +})); +changes = res.cursor.firstBatch; +assert.eq(changes.length, 2); +assert.eq(changes[0]["fullDocument"], {_id: 1}); +assert.eq(changes[0]["operationType"], "insert"); +assert.eq(changes[1]["fullDocument"], {_id: 2}); +assert.eq(changes[1]["operationType"], "insert"); - // Let the test finish. - restartServerReplication(secondary); +// Let the test finish. +restartServerReplication(secondary); - replTest.stopSet(); +replTest.stopSet(); })();
\ No newline at end of file |