/**
|
* Test if 'getMore' on an aggregate cursor returns uncommitted data.
|
*/
|
(function() {
|
"use strict";
|
|
load("jstests/libs/write_concern_util.js"); // for [stop|restart]ServerReplication.
|
|
const name = "test";
|
const replTest = new ReplSetTest({name: name, nodes: 4});
|
replTest.startSet();
|
replTest.initiate();
|
|
const dbName = name;
|
const collName = "test";
|
|
const primary = replTest.getPrimary();
|
let secondaries = replTest.getSecondaries();
|
assert.eq(secondaries.length, 3);
|
const primaryDb = primary.getDB(dbName);
|
const secondaryDb = secondaries[0].getDB(dbName);
|
const primaryColl = primaryDb[collName];
|
|
// Do some initial writes on primary and commit them.
|
assert.commandWorked(
|
primaryColl.insert([{_id: 1}, {_id: 2}, {_id: 3}], {writeConcern: {w: 4}}));
|
replTest.awaitLastOpCommitted();
|
|
// Pause replication on two secondaries.
|
jsTestLog("Stopping replication on 2 secondaries.");
|
stopServerReplication(secondaries[1]);
|
stopServerReplication(secondaries[2]);
|
|
jsTestLog("Doing some writes on primary.");
|
// Do a write and replicate to 1 secondary. This write is not majority committed yet.
|
assert.commandWorked(
|
primaryColl.insert([{_id: 4}, {_id: 5}, {_id: 6}], {writeConcern: {w: 2}}));
|
|
jsTestLog("Doing reads on secondary.");
|
|
// A majority 'find' query. This should only return doc ids {1,2,3}.
|
let findDocs = secondaryDb[collName].find().readConcern("majority").toArray();
|
assert.sameMembers(findDocs, [{_id: 1}, {_id: 2}, {_id: 3}]);
|
|
// Do a majority 'getMore' on aggregate cursor.This should only return doc ids {1,2,3}, since
|
// docs {4,5,6} are not majority committed yet.
|
let res = secondaryDb.runCommand({
|
aggregate: collName,
|
pipeline: [],
|
readConcern: {level: "majority"},
|
cursor: {batchSize: 0}
|
});
|
let cursorId = res.cursor.id;
|
res = secondaryDb.runCommand({getMore: cursorId, collection: collName});
|
assert.sameMembers(res.cursor.nextBatch, [{_id: 1}, {_id: 2}, {_id: 3}]);
|
|
// Restart replication to let test complete.
|
restartServerReplication(secondaries[1]);
|
restartServerReplication(secondaries[2]);
|
|
replTest.stopSet();
|
})();
|
|