summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/readConcern_snapshot.js
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-04-03 18:27:56 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2018-04-17 12:03:10 -0400
commitfcf41ce8ddf70894ed6803420e94a1685cc60903 (patch)
tree79de3abcf16f4ad6b9029c7ff3a63504963bb338 /jstests/noPassthrough/readConcern_snapshot.js
parentdc4832736957d840760af6557d65dcf28cd81063 (diff)
downloadmongo-fcf41ce8ddf70894ed6803420e94a1685cc60903.tar.gz
SERVER-34094 Change snapshot read tests to use multi-statement transactions
Diffstat (limited to 'jstests/noPassthrough/readConcern_snapshot.js')
-rw-r--r--jstests/noPassthrough/readConcern_snapshot.js95
1 files changed, 48 insertions, 47 deletions
diff --git a/jstests/noPassthrough/readConcern_snapshot.js b/jstests/noPassthrough/readConcern_snapshot.js
index 8f7187d26c7..e06aac95371 100644
--- a/jstests/noPassthrough/readConcern_snapshot.js
+++ b/jstests/noPassthrough/readConcern_snapshot.js
@@ -10,6 +10,8 @@
// Configurations.
//
+ // TODO: SERVER-34388 - convert this to txn api when we can do failing
+ // command in a transaction.
// readConcern 'snapshot' should fail on storage engines that do not support it.
let rst = new ReplSetTest({nodes: 1});
rst.startSet();
@@ -28,6 +30,8 @@
session.endSession();
rst.stopSet();
+ // TODO: SERVER-34388 - convert this to txn api when we can do failing
+ // command in a transaction.
// readConcern 'snapshot' should fail for autocommit:true transactions when test
// 'enableTestCommands' is set to false.
jsTest.setOption('enableTestCommands', false);
@@ -45,6 +49,8 @@
session.endSession();
rst.stopSet();
+ // TODO: SERVER-34388 - convert this to txn api when we can do failing
+ // command in a transaction.
// readConcern 'snapshot' is not allowed on a standalone.
const conn = MongoRunner.runMongod();
session = conn.startSession({causalConsistency: false});
@@ -61,33 +67,41 @@
rst = new ReplSetTest({nodes: 2});
rst.startSet();
rst.initiate();
+ assert.commandWorked(rst.getPrimary().getDB(dbName).runCommand(
+ {create: collName, writeConcern: {w: "majority"}}));
session = rst.getPrimary().getDB(dbName).getMongo().startSession({causalConsistency: false});
sessionDb = session.getDatabase(dbName);
- let txnNumber = 0;
- assert.commandWorked(sessionDb.coll.insert({}, {writeConcern: {w: "majority"}}));
- assert.commandWorked(sessionDb.runCommand(
- {find: collName, readConcern: {level: "snapshot"}, txnNumber: NumberLong(txnNumber++)}));
+ session.startTransaction({writeConcern: {w: "majority"}, readConcern: {level: "snapshot"}});
+ assert.commandWorked(sessionDb.coll.insert({}));
+ assert.commandWorked(sessionDb.runCommand({find: collName}));
+ session.commitTransaction();
// readConcern 'snapshot' is allowed with 'afterClusterTime'.
+ session.startTransaction();
let pingRes = assert.commandWorked(rst.getPrimary().adminCommand({ping: 1}));
assert(pingRes.hasOwnProperty("$clusterTime"), tojson(pingRes));
assert(pingRes.$clusterTime.hasOwnProperty("clusterTime"), tojson(pingRes));
assert.commandWorked(sessionDb.runCommand({
find: collName,
- readConcern: {level: "snapshot", afterClusterTime: pingRes.$clusterTime.clusterTime},
- txnNumber: NumberLong(txnNumber++)
+ readConcern: {level: "snapshot", afterClusterTime: pingRes.$clusterTime.clusterTime}
}));
+ session.commitTransaction();
// readConcern 'snapshot' is not allowed with 'afterOpTime'.
+ session.startTransaction();
assert.commandFailedWithCode(sessionDb.runCommand({
find: collName,
- readConcern: {level: "snapshot", afterOpTime: {ts: Timestamp(1, 2), t: 1}},
- txnNumber: NumberLong(txnNumber++)
+ readConcern: {level: "snapshot", afterOpTime: {ts: Timestamp(1, 2), t: 1}}
}),
ErrorCodes.InvalidOptions);
+ // TODO: SERVER-34388 - convert this to txn api when we can do failing
+ // command in a transaction.
session.endSession();
+ // TODO: SERVER-34388 - convert this to txn api when we can do failing
+ // command in a transaction.
// readConcern 'snapshot' is allowed on a replica set secondary.
+ let txnNumber = 0;
session = rst.getSecondary().getDB(dbName).getMongo().startSession({causalConsistency: false});
sessionDb = session.getDatabase(dbName);
assert.commandWorked(sessionDb.runCommand(
@@ -124,33 +138,45 @@
session = testDB.getMongo().startSession({causalConsistency: false});
sessionDb = session.getDatabase(dbName);
- txnNumber = 0;
// readConcern 'snapshot' is supported by find.
- assert.commandWorked(sessionDb.runCommand(
- {find: collName, readConcern: {level: "snapshot"}, txnNumber: NumberLong(txnNumber++)}));
+ session.startTransaction({readConcern: {level: "snapshot"}, writeConcern: {w: "majority"}});
+ assert.commandWorked(sessionDb.runCommand({find: collName}));
// readConcern 'snapshot' is supported by aggregate.
- assert.commandWorked(sessionDb.runCommand({
- aggregate: collName,
- pipeline: [],
- cursor: {},
- readConcern: {level: "snapshot"},
- txnNumber: NumberLong(txnNumber++)
- }));
+ assert.commandWorked(sessionDb.runCommand({aggregate: collName, pipeline: [], cursor: {}}));
// readConcern 'snapshot' is supported by count.
- assert.commandWorked(sessionDb.runCommand(
- {count: collName, readConcern: {level: "snapshot"}, txnNumber: NumberLong(txnNumber++)}));
+ assert.commandWorked(sessionDb.runCommand({count: collName}));
// readConcern 'snapshot' is supported by distinct.
+ assert.commandWorked(sessionDb.runCommand({distinct: collName, key: "x"}));
+
+ // readConcern 'snapshot' is supported by geoSearch.
+ assert.commandWorked(
+ sessionDb.runCommand({geoSearch: collName, near: [0, 0], maxDistance: 1, search: {a: 1}}));
+
+ // readConcern 'snapshot' is not supported by non-CRUD commands.
+ assert.commandFailedWithCode(
+ sessionDb.runCommand({createIndexes: collName, indexes: [{key: {a: 1}, name: "a_1"}]}),
+ 50767);
+ session.abortTransaction();
+ session.endSession();
+
+ // TODO: SERVER-34113 Remove this test when we completely remove snapshot
+ // reads since this command is not supported with transaction api.
+ // readConcern 'snapshot' is supported by group.
+ session = rst.getPrimary().getDB(dbName).getMongo().startSession({causalConsistency: false});
+ sessionDb = session.getDatabase(dbName);
+ txnNumber = 0;
assert.commandWorked(sessionDb.runCommand({
- distinct: collName,
- key: "x",
+ group: {ns: collName, key: {_id: 1}, $reduce: function(curr, result) {}, initial: {}},
readConcern: {level: "snapshot"},
txnNumber: NumberLong(txnNumber++)
}));
+ // TODO: SERVER-34113 Remove this test when we completely remove snapshot
+ // reads since this command is not supported with transaction api.
// readConcern 'snapshot' is supported by geoNear.
assert.commandWorked(sessionDb.runCommand({
geoNear: collName,
@@ -159,31 +185,6 @@
txnNumber: NumberLong(txnNumber++)
}));
- // readConcern 'snapshot' is supported by geoSearch.
- assert.commandWorked(sessionDb.runCommand({
- geoSearch: collName,
- near: [0, 0],
- maxDistance: 1,
- search: {a: 1},
- readConcern: {level: "snapshot"},
- txnNumber: NumberLong(txnNumber++)
- }));
-
- // readConcern 'snapshot' is supported by group.
- assert.commandWorked(sessionDb.runCommand({
- group: {ns: collName, key: {_id: 1}, $reduce: function(curr, result) {}, initial: {}},
- readConcern: {level: "snapshot"},
- txnNumber: NumberLong(txnNumber++)
- }));
-
- // readConcern 'snapshot' is not supported by non-CRUD commands.
- assert.commandFailedWithCode(sessionDb.runCommand({
- createIndexes: collName,
- indexes: [{key: {a: 1}, name: "a_1"}],
- readConcern: {level: "snapshot"}
- }),
- ErrorCodes.InvalidOptions);
-
session.endSession();
rst.stopSet();
}());