1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/**
* Verify that readConcern: snapshot is not permitted outside transactions.
*
* @tags: [uses_transactions]
*/
(function() {
"use strict";
const dbName = "test";
const collName = "no_read_concern_snapshot_outside_txn";
const testDB = db.getSiblingDB(dbName);
// Set up the test collection.
testDB.runCommand({drop: collName, writeConcern: {w: "majority"}});
assert.commandWorked(testDB.createCollection(collName, {writeConcern: {w: "majority"}}));
// Initiate the session.
const sessionOptions = {causalConsistency: false};
let session = db.getMongo().startSession(sessionOptions);
let sessionDb = session.getDatabase(dbName);
let txnNumber = 0;
let stmtId = 0;
function tryCommands({testDB, message}) {
jsTestLog("Verify that inserts cannot use readConcern snapshot " + message);
let cmd = {
insert: collName,
documents: [{_id: 0}],
readConcern: {level: "snapshot"},
};
assert.commandFailedWithCode(testDB.runCommand(cmd), ErrorCodes.InvalidOptions);
jsTestLog("Verify that updates cannot use readConcern snapshot " + message);
cmd = {
update: collName,
updates: [{q: {_id: 0}, u: {$set: {x: 1}}}],
readConcern: {level: "snapshot"},
};
assert.commandFailedWithCode(testDB.runCommand(cmd), ErrorCodes.InvalidOptions);
jsTestLog("Verify that deletes cannot use readConcern snapshot " + message);
cmd = {
delete: collName,
deletes: [{q: {_id: 0}, limit: 1}],
readConcern: {level: "snapshot"},
};
assert.commandFailedWithCode(testDB.runCommand(cmd), ErrorCodes.InvalidOptions);
jsTestLog("Verify that findAndModify cannot use readConcern snapshot " + message);
cmd = {
findAndModify: collName,
query: {_id: 0},
remove: true,
readConcern: {level: "snapshot"},
};
assert.commandFailedWithCode(testDB.runCommand(cmd), ErrorCodes.InvalidOptions);
jsTestLog("Verify that finds cannot use readConcern snapshot " + message);
cmd = {find: collName, readConcern: {level: "snapshot"}};
assert.commandFailedWithCode(testDB.runCommand(cmd), ErrorCodes.InvalidOptions);
jsTestLog("Verify that aggregate cannot use readConcern snapshot " + message);
cmd = {aggregate: collName, pipeline: [], readConcern: {level: "snapshot"}};
assert.commandFailedWithCode(testDB.runCommand(cmd), ErrorCodes.InvalidOptions);
}
tryCommands({testDB: sessionDb, message: "in session."});
tryCommands({testDB: testDB, message: "outside session."});
session.endSession();
}());
|