summaryrefslogtreecommitdiff
path: root/jstests/readonly
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2016-05-20 16:01:35 -0400
committerAndy Schwerin <schwerin@mongodb.com>2016-05-20 16:02:01 -0400
commit68ee19bbd79cd33280cb01af38129249a32dcf7a (patch)
tree256cafaf66df6016fbc85c762b54a08113f28862 /jstests/readonly
parentcebf4c171154442c880144e2e24041960d6cc1f1 (diff)
downloadmongo-68ee19bbd79cd33280cb01af38129249a32dcf7a.tar.gz
SERVER-24024 If there is no "local" database at startup in queryableBackupMode, do not panic.
At startup, the logic that checks for version-specific bugs that may need to be worked around attempts to open the "local" database to see what version of mongod was last used to access the data files. In queryableBackupMode, if there is no local database, this can legally fail, at least for some storage engines. This patch recovers from that failure, rather than shutting down the server. This patch also updates the read_only and read_only_sharded test suites, to test cases where there is no "local" database, as this is the standard queryableBackupMode use case.
Diffstat (limited to 'jstests/readonly')
-rw-r--r--jstests/readonly/lib/read_only_test.js233
1 files changed, 119 insertions, 114 deletions
diff --git a/jstests/readonly/lib/read_only_test.js b/jstests/readonly/lib/read_only_test.js
index dd0b6229ace..37802ee66d2 100644
--- a/jstests/readonly/lib/read_only_test.js
+++ b/jstests/readonly/lib/read_only_test.js
@@ -1,148 +1,153 @@
-"use_strict";
+var StandaloneFixture, ShardedFixture, runReadOnlyTest, zip2, cycleN;
-function makeDirectoryReadOnly(dir) {
- if (_isWindows()) {
- run("attrib", "+r", dir, "/s");
- } else {
- run("chmod", "-R", "a-w", dir);
+(function() {
+ "use_strict";
+
+ function makeDirectoryReadOnly(dir) {
+ if (_isWindows()) {
+ run("attrib", "+r", dir, "/s");
+ } else {
+ run("chmod", "-R", "a-w", dir);
+ }
}
-}
-function makeDirectoryWritable(dir) {
- if (_isWindows()) {
- run("attrib", "-r", dir, "/s");
- } else {
- run("chmod", "-R", "a+w", dir);
+ function makeDirectoryWritable(dir) {
+ if (_isWindows()) {
+ run("attrib", "-r", dir, "/s");
+ } else {
+ run("chmod", "-R", "a+w", dir);
+ }
}
-}
-function StandaloneFixture() {
-}
+ StandaloneFixture = function() {};
-StandaloneFixture.prototype.runLoadPhase = function runLoadPhase(test) {
- this.mongod = MongoRunner.runMongod({});
- this.dbpath = this.mongod.dbpath;
+ StandaloneFixture.prototype.runLoadPhase = function runLoadPhase(test) {
+ this.mongod = MongoRunner.runMongod({});
+ this.dbpath = this.mongod.dbpath;
- test.load(this.mongod.getDB("test")[test.name]);
- MongoRunner.stopMongod(this.mongod);
-};
+ test.load(this.mongod.getDB("test")[test.name]);
+ assert.commandWorked(this.mongod.getDB("local").dropDatabase());
+ MongoRunner.stopMongod(this.mongod);
+ };
-StandaloneFixture.prototype.runExecPhase = function runExecPhase(test) {
- try {
- makeDirectoryReadOnly(this.dbpath);
+ StandaloneFixture.prototype.runExecPhase = function runExecPhase(test) {
+ try {
+ makeDirectoryReadOnly(this.dbpath);
- var options = {
- queryableBackupMode: "",
- noCleanData: true,
- dbpath: this.dbpath
- };
+ var options = {
+ queryableBackupMode: "",
+ noCleanData: true,
+ dbpath: this.dbpath
+ };
- this.mongod = MongoRunner.runMongod(options);
+ this.mongod = MongoRunner.runMongod(options);
- test.exec(this.mongod.getDB("test")[test.name]);
+ test.exec(this.mongod.getDB("test")[test.name]);
- MongoRunner.stopMongod(this.mongod);
- } finally {
- makeDirectoryWritable(this.dbpath);
- }
-};
+ MongoRunner.stopMongod(this.mongod);
+ } finally {
+ makeDirectoryWritable(this.dbpath);
+ }
+ };
-function ShardedFixture() {
- this.nShards = 3;
-}
+ ShardedFixture = function() {
+ this.nShards = 3;
+ };
-ShardedFixture.prototype.runLoadPhase = function runLoadPhase(test) {
- this.shardingTest = new ShardingTest({nopreallocj: true, mongos: 1, shards: this.nShards});
+ ShardedFixture.prototype.runLoadPhase = function runLoadPhase(test) {
+ this.shardingTest = new ShardingTest({nopreallocj: true, mongos: 1, shards: this.nShards});
- this.paths = this.shardingTest.getDBPaths();
+ this.paths = this.shardingTest.getDBPaths();
- jsTest.log("sharding test collection...");
+ jsTest.log("sharding test collection...");
- // Use a hashed shard key so we actually hit multiple shards.
- this.shardingTest.shardColl(test.name, {_id: "hashed"});
+ // Use a hashed shard key so we actually hit multiple shards.
+ this.shardingTest.shardColl(test.name, {_id: "hashed"});
- test.load(this.shardingTest.getDB("test")[test.name]);
-};
+ test.load(this.shardingTest.getDB("test")[test.name]);
+ };
-ShardedFixture.prototype.runExecPhase = function runExecPhase(test) {
- jsTest.log("restarting shards...");
- try {
- for (var i = 0; i < this.nShards; ++i) {
- var opts = {
- queryableBackupMode: "",
- dbpath: this.paths[i]
- };
+ ShardedFixture.prototype.runExecPhase = function runExecPhase(test) {
+ jsTest.log("restarting shards...");
+ try {
+ for (var i = 0; i < this.nShards; ++i) {
+ var opts = {
+ queryableBackupMode: "",
+ dbpath: this.paths[i]
+ };
- this.shardingTest.restartMongod(i,
- opts,
- () => {
- makeDirectoryReadOnly(this.paths[i]);
- });
- }
+ assert.commandWorked(this.shardingTest["d" + i].getDB("local").dropDatabase());
+ this.shardingTest.restartMongod(i,
+ opts,
+ () => {
+ makeDirectoryReadOnly(this.paths[i]);
+ });
+ }
- jsTest.log("restarting mongos...");
+ jsTest.log("restarting mongos...");
- this.shardingTest.restartMongos(0);
+ this.shardingTest.restartMongos(0);
- test.exec(this.shardingTest.getDB("test")[test.name]);
+ test.exec(this.shardingTest.getDB("test")[test.name]);
- this.paths.forEach((path) => {
- makeDirectoryWritable(path);
- });
+ this.paths.forEach((path) => {
+ makeDirectoryWritable(path);
+ });
- this.shardingTest.stop();
- } finally {
- this.paths.forEach((path) => {
- makeDirectoryWritable(path);
- });
- }
-};
+ this.shardingTest.stop();
+ } finally {
+ this.paths.forEach((path) => {
+ makeDirectoryWritable(path);
+ });
+ }
+ };
-function runReadOnlyTest(test) {
- printjson(test);
+ runReadOnlyTest = function(test) {
+ printjson(test);
- assert.eq(typeof(test.exec), "function");
- assert.eq(typeof(test.load), "function");
- assert.eq(typeof(test.name), "string");
+ assert.eq(typeof(test.exec), "function");
+ assert.eq(typeof(test.load), "function");
+ assert.eq(typeof(test.name), "string");
- var fixtureType = TestData.fixture || "standalone";
+ var fixtureType = TestData.fixture || "standalone";
- var fixture = null;
- if (fixtureType === "standalone") {
- fixture = new StandaloneFixture();
- } else if (fixtureType === "sharded") {
- fixture = new ShardedFixture();
- } else {
- throw new Error("fixtureType must be one of either 'standalone' or 'sharded'");
- }
+ var fixture = null;
+ if (fixtureType === "standalone") {
+ fixture = new StandaloneFixture();
+ } else if (fixtureType === "sharded") {
+ fixture = new ShardedFixture();
+ } else {
+ throw new Error("fixtureType must be one of either 'standalone' or 'sharded'");
+ }
- jsTest.log("starting load phase for test: " + test.name);
- fixture.runLoadPhase(test);
+ jsTest.log("starting load phase for test: " + test.name);
+ fixture.runLoadPhase(test);
- jsTest.log("starting execution phase for test: " + test.name);
- fixture.runExecPhase(test);
-}
+ jsTest.log("starting execution phase for test: " + test.name);
+ fixture.runExecPhase(test);
+ };
-function * cycleN(arr, N) {
- for (var i = 0; i < N; ++i) {
- yield arr[i % arr.length];
- }
-}
-
-function * zip2(iter1, iter2) {
- var n1 = iter1.next();
- var n2 = iter2.next();
- while (!n1.done || !n2.done) {
- var res = [];
- if (!n1.done) {
- res.push(n1.value);
- n1 = iter1.next();
+ cycleN = function * (arr, N) {
+ for (var i = 0; i < N; ++i) {
+ yield arr[i % arr.length];
}
- if (!n2.done) {
- res.push(n2.value);
- n2 = iter2.next();
+ };
+
+ zip2 = function * (iter1, iter2) {
+ var n1 = iter1.next();
+ var n2 = iter2.next();
+ while (!n1.done || !n2.done) {
+ var res = [];
+ if (!n1.done) {
+ res.push(n1.value);
+ n1 = iter1.next();
+ }
+ if (!n2.done) {
+ res.push(n2.value);
+ n2 = iter2.next();
+ }
+
+ yield res;
}
-
- yield res;
- }
-}
+ };
+}());