summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/snapshot_cursor_shutdown_stepdown.js
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2018-03-15 16:16:58 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2018-03-20 10:25:27 -0400
commit374f14d984da357c943098735e7e6d13f250675a (patch)
tree91662f7eb9a6d9582dff0a7e312fffbc9a85398f /jstests/noPassthrough/snapshot_cursor_shutdown_stepdown.js
parent15400ae3c7ec6830e0f80b3dd84fd89632b73648 (diff)
downloadmongo-374f14d984da357c943098735e7e6d13f250675a.tar.gz
SERVER-33669 Stepdown and shutdown should abort all uncommitted transactions
Diffstat (limited to 'jstests/noPassthrough/snapshot_cursor_shutdown_stepdown.js')
-rw-r--r--jstests/noPassthrough/snapshot_cursor_shutdown_stepdown.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/jstests/noPassthrough/snapshot_cursor_shutdown_stepdown.js b/jstests/noPassthrough/snapshot_cursor_shutdown_stepdown.js
new file mode 100644
index 00000000000..aaae19766aa
--- /dev/null
+++ b/jstests/noPassthrough/snapshot_cursor_shutdown_stepdown.js
@@ -0,0 +1,84 @@
+// Tests that stashed transaction resources are destroyed at shutdown and stepdown.
+// @tags: [requires_replication]
+(function() {
+ "use strict";
+
+ const dbName = "test";
+ const collName = "coll";
+
+ //
+ // Test that stashed transaction resources are destroyed at shutdown.
+ //
+
+ let rst = new ReplSetTest({nodes: 1});
+ rst.startSet();
+ rst.initiate();
+
+ let primaryDB = rst.getPrimary().getDB(dbName);
+ if (!primaryDB.serverStatus().storageEngine.supportsSnapshotReadConcern) {
+ rst.stopSet();
+ return;
+ }
+
+ let session = primaryDB.getMongo().startSession();
+ let sessionDB = session.getDatabase(dbName);
+
+ for (let i = 0; i < 4; i++) {
+ assert.commandWorked(sessionDB.coll.insert({_id: i}, {writeConcern: {w: "majority"}}));
+ }
+
+ // Create a snapshot read cursor.
+ assert.commandWorked(sessionDB.runCommand({
+ find: collName,
+ batchSize: 2,
+ readConcern: {level: "snapshot"},
+ txnNumber: NumberLong(0)
+ }));
+
+ // It should be possible to shut down the server without hanging. We must skip collection
+ // validation, since this will hang.
+ const signal = true; // Use default kill signal.
+ const forRestart = false;
+ rst.stopSet(signal, forRestart, {skipValidation: true});
+
+ //
+ // Test that stashed transaction resources are destroyed at stepdown.
+ //
+
+ rst = new ReplSetTest({nodes: 2});
+ rst.startSet();
+ rst.initiate();
+
+ const primary = rst.getPrimary();
+ primaryDB = primary.getDB(dbName);
+
+ session = primaryDB.getMongo().startSession();
+ sessionDB = session.getDatabase(dbName);
+
+ for (let i = 0; i < 4; i++) {
+ assert.commandWorked(sessionDB.coll.insert({_id: i}, {writeConcern: {w: "majority"}}));
+ }
+
+ // Create a snapshot read cursor.
+ const res = assert.commandWorked(sessionDB.runCommand({
+ find: collName,
+ batchSize: 2,
+ readConcern: {level: "snapshot"},
+ txnNumber: NumberLong(0)
+ }));
+ assert(res.hasOwnProperty("cursor"), tojson(res));
+ assert(res.cursor.hasOwnProperty("id"), tojson(res));
+
+ // It should be possible to step down the primary without hanging.
+ assert.throws(function() {
+ primary.adminCommand({replSetStepDown: 60, force: true});
+ });
+ rst.waitForState(primary, ReplSetTest.State.SECONDARY);
+
+ // TODO SERVER-33690: Destroying stashed transaction resources should kill the cursor, so this
+ // getMore should fail.
+ assert.commandWorked(sessionDB.runCommand(
+ {getMore: res.cursor.id, collection: collName, txnNumber: NumberLong(0)}));
+
+ rst.stopSet();
+})();