0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-22148 Simplify read committed tests

Many read committed tests share some fairly complex code to determine
if the current storage engine supports committed reads. This commit
moves that duplicate code into rslib.js.
This commit is contained in:
Charlie Swanson 2015-12-03 12:23:44 -05:00
parent c60496946b
commit bf8b5340af
7 changed files with 99 additions and 52 deletions

View File

@ -1,4 +1,20 @@
load('jstests/libs/analyze_plan.js');
/**
* Tests a variety of functionality related to committed reads:
* - A killOp command can successfully kill an operation that is waiting for snapshots to be
* created.
* - A user should not be able to do any committed reads before a snapshot has been blessed.
* - Inserts and catalog changes should not be visible in a snapshot before they occurred.
* - A getMore should see the new blessed snapshot.
* - Dropping an index, repairing, and reIndexing should bump the min snapshot version.
* - Dropping a collection is visible in committed snapshot, since metadata changes are special.
* - 'local'-only commands should error on 'majority' level, and accept 'local' level.
* - An aggregation with '$out' should fail with 'majority' level.
*
* All of this requires support for committed reads, so this test will be skipped if the storage
* engine does not support them.
*/
load("jstests/libs/analyze_plan.js");
(function() {
"use strict";

View File

@ -1,4 +1,13 @@
// Test basic read committed functionality.
/**
* Test basic read committed functionality, including:
* - Writes with writeConcern 'majority' should be visible once the write completes.
* - With the only data-bearing secondary down, committed reads should not include newly inserted
* data.
* - When data-bearing node comes back up and catches up, writes should be readable.
*/
load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
(function() {
"use strict";
@ -7,20 +16,13 @@ var name = "read_committed";
var replTest = new ReplSetTest({name: name,
nodes: 3,
nodeOptions: {enableMajorityReadConcern: ''}});
var nodes = replTest.nodeList();
try {
replTest.startSet();
} catch (e) {
var conn = MongoRunner.runMongod();
if (!conn.getDB('admin').serverStatus().storageEngine.supportsCommittedReads) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
MongoRunner.stopMongod(conn);
return;
}
throw e;
if (!startSetIfSupportsReadMajority(replTest)) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
return;
}
var nodes = replTest.nodeList();
replTest.initiate({"_id": name,
"members": [
{ "_id": 0, "host": nodes[0] },

View File

@ -1,6 +1,11 @@
// Test basic read committed maxTimeMS timeout while waiting for a committedSnapshot
/**
* Test basic read committed maxTimeMS timeout while waiting for a committed snapshot:
* - Reads with an 'afterOpTime' snapshot >= current time should be able to see things that
* happened before or at that opTime.
* - Reads should time out if there are no snapshots available on secondary.
*/
load("jstests/replsets/rslib.js");
load("jstests/replsets/rslib.js"); // For reconfig and startSetIfSupportsReadMajority.
(function() {
"use strict";
@ -10,20 +15,13 @@ var name = "read_committed_no_snapshots";
var replTest = new ReplSetTest({name: name,
nodes: 3,
nodeOptions: {enableMajorityReadConcern: ''}});
var nodes = replTest.nodeList();
try {
replTest.startSet();
} catch (e) {
var conn = MongoRunner.runMongod();
if (!conn.getDB('admin').serverStatus().storageEngine.supportsCommittedReads) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
MongoRunner.stopMongod(conn);
return;
}
throw e;
if (!startSetIfSupportsReadMajority(replTest)) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
return;
}
var nodes = replTest.nodeList();
replTest.initiate({"_id": name,
"members": [
{ "_id": 0, "host": nodes[0] },

View File

@ -1,4 +1,11 @@
// Test basic read committed functionality on a secondary.
/**
* Test basic read committed functionality on a secondary:
* - Updates should not be visible until they are in the blessed snapshot.
* - Updates should be visible once they are in the blessed snapshot.
*/
load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
(function() {
"use strict";
@ -7,20 +14,13 @@ var name = "read_committed_on_secondary";
var replTest = new ReplSetTest({name: name,
nodes: 3,
nodeOptions: {enableMajorityReadConcern: ''}});
var nodes = replTest.nodeList();
try {
replTest.startSet();
} catch (e) {
var conn = MongoRunner.runMongod();
if (!conn.getDB('admin').serverStatus().storageEngine.supportsCommittedReads) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
MongoRunner.stopMongod(conn);
return;
}
throw e;
if (!startSetIfSupportsReadMajority(replTest)) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
return;
}
var nodes = replTest.nodeList();
replTest.initiate({"_id": name,
"members": [
{ "_id": 0, "host": nodes[0] },

View File

@ -1,5 +1,10 @@
// Test read committed and writeConcern: "majority" work properly with all other nodes being
// arbiters.
/**
* Tests that writeConcern 'majority' writes succeed and are visible in a replica set that has one
* data-bearing node and two arbiters.
*/
load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
(function() {
"use strict";
@ -8,20 +13,13 @@ var name = "read_majority_two_arbs";
var replTest = new ReplSetTest({name: name,
nodes: 3,
nodeOptions: {enableMajorityReadConcern: ''}});
var nodes = replTest.nodeList();
try {
replTest.startSet();
} catch (e) {
var conn = MongoRunner.runMongod();
if (!conn.getDB('admin').serverStatus().storageEngine.supportsCommittedReads) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
MongoRunner.stopMongod(conn);
return;
}
throw e;
if (!startSetIfSupportsReadMajority(replTest)) {
jsTest.log("skipping test since storage engine doesn't support committed reads");
return;
}
var nodes = replTest.nodeList();
replTest.initiate({"_id": name,
"members": [
{"_id": 0, "host": nodes[0]},

View File

@ -1,4 +1,11 @@
var wait, occasionally, reconnect, getLatestOp, waitForAllMembers, reconfig, awaitOpTime;
var wait;
var occasionally;
var reconnect;
var getLatestOp;
var waitForAllMembers;
var reconfig;
var awaitOpTime;
var startSetIfSupportsReadMajority;
var waitUntilAllNodesCaughtUp;
(function () {
@ -181,4 +188,25 @@ waitUntilAllNodesCaughtUp = function(rs) {
});
};
/**
* Starts each node in the given replica set if the storage engine supports readConcern 'majority'.
* Returns true if the replica set was started successfully and false otherwise.
*
* @param replSetTest - The instance of {@link ReplSetTest} to start
* @param options - The options passed to {@link ReplSetTest.startSet}
*/
startSetIfSupportsReadMajority = function (replSetTest, options) {
try {
replSetTest.startSet(options);
} catch (e) {
var conn = MongoRunner.runMongod();
if (!conn.getDB("admin").serverStatus().storageEngine.supportsCommittedReads) {
MongoRunner.stopMongod(conn);
return false;
}
throw e;
}
return true;
};
}());

View File

@ -377,6 +377,11 @@ var ReplSetTest = function(opts) {
return this.name + "/" + hosts.join(",");
};
/**
* Starts each node in the replica set with the given options.
*
* @param options - The options passed to {@link MongoRunner.runMongod}
*/
this.startSet = function(options) {
print("ReplSetTest starting set");