summaryrefslogtreecommitdiff
path: root/jstests/disk
diff options
context:
space:
mode:
authorclang-format-7.0.1 <adam.martin@10gen.com>2019-07-26 18:20:35 -0400
committerADAM David Alan Martin <adam.martin@10gen.com>2019-07-27 11:02:23 -0400
commit134a4083953270e8a11430395357fb70a29047ad (patch)
treedd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /jstests/disk
parent1e46b5049003f427047e723ea5fab15b5a9253ca (diff)
downloadmongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'jstests/disk')
-rw-r--r--jstests/disk/repair_does_not_invalidate_config_on_standalone.js44
-rw-r--r--jstests/disk/repair_failure_is_recoverable.js74
-rw-r--r--jstests/disk/repair_invalidates_replica_set_config.js194
-rw-r--r--jstests/disk/wt_corrupt_file_errors.js116
-rw-r--r--jstests/disk/wt_missing_file_errors.js116
-rw-r--r--jstests/disk/wt_repair_corrupt_files.js152
-rw-r--r--jstests/disk/wt_repair_corrupt_metadata.js184
-rw-r--r--jstests/disk/wt_repair_missing_files.js186
-rw-r--r--jstests/disk/wt_repair_orphaned_idents.js140
9 files changed, 597 insertions, 609 deletions
diff --git a/jstests/disk/repair_does_not_invalidate_config_on_standalone.js b/jstests/disk/repair_does_not_invalidate_config_on_standalone.js
index 70f0cde97b8..aba146fb37c 100644
--- a/jstests/disk/repair_does_not_invalidate_config_on_standalone.js
+++ b/jstests/disk/repair_does_not_invalidate_config_on_standalone.js
@@ -6,37 +6,37 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/disk/libs/wt_file_helper.js');
- const baseName = "repair_does_not_invalidate_config_on_standalone";
- const dbName = baseName;
- const collName = "test";
+const baseName = "repair_does_not_invalidate_config_on_standalone";
+const dbName = baseName;
+const collName = "test";
- const dbpath = MongoRunner.dataPath + baseName + "/";
- resetDbpath(dbpath);
+const dbpath = MongoRunner.dataPath + baseName + "/";
+resetDbpath(dbpath);
- let mongod = MongoRunner.runMongod({dbpath: dbpath});
- const port = mongod.port;
+let mongod = MongoRunner.runMongod({dbpath: dbpath});
+const port = mongod.port;
- let testColl = mongod.getDB(dbName)[collName];
+let testColl = mongod.getDB(dbName)[collName];
- assert.commandWorked(testColl.insert({_id: 0, foo: "bar"}));
+assert.commandWorked(testColl.insert({_id: 0, foo: "bar"}));
- let collUri = getUriForColl(testColl);
- let collFile = dbpath + "/" + collUri + ".wt";
+let collUri = getUriForColl(testColl);
+let collFile = dbpath + "/" + collUri + ".wt";
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
- jsTestLog("Deleting collection file: " + collFile);
- removeFile(collFile);
+jsTestLog("Deleting collection file: " + collFile);
+removeFile(collFile);
- assertRepairSucceeds(dbpath, port);
+assertRepairSucceeds(dbpath, port);
- assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
- let nodeDB = node.getDB(dbName);
- assert(nodeDB[collName].exists());
- assert.eq(nodeDB[collName].find().itcount(), 0);
+assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
+ let nodeDB = node.getDB(dbName);
+ assert(nodeDB[collName].exists());
+ assert.eq(nodeDB[collName].find().itcount(), 0);
- assert(!nodeDB.getSiblingDB("local")["system.replset"].exists());
- });
+ assert(!nodeDB.getSiblingDB("local")["system.replset"].exists());
+});
})();
diff --git a/jstests/disk/repair_failure_is_recoverable.js b/jstests/disk/repair_failure_is_recoverable.js
index cbfc12e5b4b..2ede4bfe36d 100644
--- a/jstests/disk/repair_failure_is_recoverable.js
+++ b/jstests/disk/repair_failure_is_recoverable.js
@@ -7,56 +7,56 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/disk/libs/wt_file_helper.js');
- const exitBeforeRepairParameter = "exitBeforeDataRepair";
- const exitBeforeRepairInvalidatesConfigParameter = "exitBeforeRepairInvalidatesConfig";
+const exitBeforeRepairParameter = "exitBeforeDataRepair";
+const exitBeforeRepairInvalidatesConfigParameter = "exitBeforeRepairInvalidatesConfig";
- const baseName = "repair_failure_is_recoverable";
- const dbName = "repair_failure_is_recoverable";
- const collName = "test";
+const baseName = "repair_failure_is_recoverable";
+const dbName = "repair_failure_is_recoverable";
+const collName = "test";
- const dbpath = MongoRunner.dataPath + baseName + "/";
- resetDbpath(dbpath);
+const dbpath = MongoRunner.dataPath + baseName + "/";
+resetDbpath(dbpath);
- let mongod = MongoRunner.runMongod({dbpath: dbpath});
- const port = mongod.port;
+let mongod = MongoRunner.runMongod({dbpath: dbpath});
+const port = mongod.port;
- let testColl = mongod.getDB(dbName)[collName];
+let testColl = mongod.getDB(dbName)[collName];
- assert.commandWorked(testColl.insert({_id: 0, foo: "bar"}));
+assert.commandWorked(testColl.insert({_id: 0, foo: "bar"}));
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
- /**
- * Test 1. Cause an exit before repairing data. MongoDB should not be able to restart without
- * --repair.
- */
- assertRepairFailsWithFailpoint(dbpath, port, exitBeforeRepairParameter);
+/**
+ * Test 1. Cause an exit before repairing data. MongoDB should not be able to restart without
+ * --repair.
+ */
+assertRepairFailsWithFailpoint(dbpath, port, exitBeforeRepairParameter);
- assertErrorOnStartupAfterIncompleteRepair(dbpath, port);
+assertErrorOnStartupAfterIncompleteRepair(dbpath, port);
- assertRepairSucceeds(dbpath, port);
+assertRepairSucceeds(dbpath, port);
- assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
- let nodeDB = node.getDB(dbName);
- assert(nodeDB[collName].exists());
- assert.eq(nodeDB[collName].find().itcount(), 1);
- });
+assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
+ let nodeDB = node.getDB(dbName);
+ assert(nodeDB[collName].exists());
+ assert.eq(nodeDB[collName].find().itcount(), 1);
+});
- /**
- * Test 2. Fail after repairing data, before invalidating the replica set config. MongoDB should
- * not be able to restart without --repair.
- */
- assertRepairFailsWithFailpoint(dbpath, port, exitBeforeRepairInvalidatesConfigParameter);
+/**
+ * Test 2. Fail after repairing data, before invalidating the replica set config. MongoDB should
+ * not be able to restart without --repair.
+ */
+assertRepairFailsWithFailpoint(dbpath, port, exitBeforeRepairInvalidatesConfigParameter);
- assertErrorOnStartupAfterIncompleteRepair(dbpath, port);
+assertErrorOnStartupAfterIncompleteRepair(dbpath, port);
- assertRepairSucceeds(dbpath, port);
+assertRepairSucceeds(dbpath, port);
- assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
- let nodeDB = node.getDB(dbName);
- assert(nodeDB[collName].exists());
- assert.eq(nodeDB[collName].find().itcount(), 1);
- });
+assertStartAndStopStandaloneOnExistingDbpath(dbpath, port, function(node) {
+ let nodeDB = node.getDB(dbName);
+ assert(nodeDB[collName].exists());
+ assert.eq(nodeDB[collName].find().itcount(), 1);
+});
})();
diff --git a/jstests/disk/repair_invalidates_replica_set_config.js b/jstests/disk/repair_invalidates_replica_set_config.js
index a110ce79857..2e67012f68f 100644
--- a/jstests/disk/repair_invalidates_replica_set_config.js
+++ b/jstests/disk/repair_invalidates_replica_set_config.js
@@ -7,122 +7,118 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/disk/libs/wt_file_helper.js');
- const dbName = "repair_invalidates_replica_set_config";
- const collName = "test";
+const dbName = "repair_invalidates_replica_set_config";
+const collName = "test";
- let replSet = new ReplSetTest({nodes: 2});
- replSet.startSet();
- replSet.initiate();
- replSet.awaitReplication();
+let replSet = new ReplSetTest({nodes: 2});
+replSet.startSet();
+replSet.initiate();
+replSet.awaitReplication();
- const originalSecondary = replSet.getSecondary();
+const originalSecondary = replSet.getSecondary();
- let primaryDB = replSet.getPrimary().getDB(dbName);
- let secondaryDB = originalSecondary.getDB(dbName);
+let primaryDB = replSet.getPrimary().getDB(dbName);
+let secondaryDB = originalSecondary.getDB(dbName);
- assert.commandWorked(primaryDB[collName].insert({_id: 0, foo: "bar"}));
- replSet.awaitLastOpCommitted();
+assert.commandWorked(primaryDB[collName].insert({_id: 0, foo: "bar"}));
+replSet.awaitLastOpCommitted();
- const secondaryPort = originalSecondary.port;
- const secondaryDbpath = originalSecondary.dbpath;
+const secondaryPort = originalSecondary.port;
+const secondaryDbpath = originalSecondary.dbpath;
- let secondary = originalSecondary;
+let secondary = originalSecondary;
- //
- // 1. This repairs the data on a clean data directory and asserts that the node is still able
- // to re-join its original replica set without an initial sync.
- //
+//
+// 1. This repairs the data on a clean data directory and asserts that the node is still able
+// to re-join its original replica set without an initial sync.
+//
- // Shut down the secondary.
- MongoRunner.stopMongod(secondary);
+// Shut down the secondary.
+MongoRunner.stopMongod(secondary);
- // Ensure the secondary can be repaired successfully.
- assertRepairSucceeds(secondaryDbpath, secondaryPort);
+// Ensure the secondary can be repaired successfully.
+assertRepairSucceeds(secondaryDbpath, secondaryPort);
- // Starting up without --replSet should not fail, and the collection should exist with its data.
- assertStartAndStopStandaloneOnExistingDbpath(secondaryDbpath, secondaryPort, function(node) {
+// Starting up without --replSet should not fail, and the collection should exist with its data.
+assertStartAndStopStandaloneOnExistingDbpath(secondaryDbpath, secondaryPort, function(node) {
+ let nodeDB = node.getDB(dbName);
+ assert(nodeDB[collName].exists());
+ assert.eq(nodeDB[collName].find().itcount(), 1);
+});
+
+// Starting the secondary with the same data directory should succeed with the same data.
+secondary = assertStartInReplSet(
+ replSet, originalSecondary, false /* cleanData */, false /* expectResync */, function(node) {
let nodeDB = node.getDB(dbName);
- assert(nodeDB[collName].exists());
assert.eq(nodeDB[collName].find().itcount(), 1);
});
-
- // Starting the secondary with the same data directory should succeed with the same data.
- secondary = assertStartInReplSet(replSet,
- originalSecondary,
- false /* cleanData */,
- false /* expectResync */,
- function(node) {
- let nodeDB = node.getDB(dbName);
- assert.eq(nodeDB[collName].find().itcount(), 1);
- });
- secondaryDB = secondary.getDB(dbName);
-
- //
- // 2. This test corrupts WiredTiger data files on a secondary, repairs the data, and asserts
- // that the node is unable to re-join its original replica set without an initial sync.
- //
-
- let secondaryCollUri = getUriForColl(secondaryDB[collName]);
- let secondaryCollFile = secondaryDbpath + "/" + secondaryCollUri + ".wt";
- // Shut down the secondary. Delete the collection's data file.
- MongoRunner.stopMongod(secondary);
- jsTestLog("Deleting secondary collection file: " + secondaryCollFile);
- removeFile(secondaryCollFile);
-
- // Ensure the secondary can be repaired successfully.
- assertRepairSucceeds(secondaryDbpath, secondaryPort);
-
- // Starting up with --replSet should fail with a specific error.
- assertErrorOnStartupWhenStartingAsReplSet(
- secondaryDbpath, secondaryPort, replSet.getReplSetConfig()._id);
-
- // Starting up without --replSet should not fail, but the collection should exist with no data.
- assertStartAndStopStandaloneOnExistingDbpath(secondaryDbpath, secondaryPort, function(node) {
+secondaryDB = secondary.getDB(dbName);
+
+//
+// 2. This test corrupts WiredTiger data files on a secondary, repairs the data, and asserts
+// that the node is unable to re-join its original replica set without an initial sync.
+//
+
+let secondaryCollUri = getUriForColl(secondaryDB[collName]);
+let secondaryCollFile = secondaryDbpath + "/" + secondaryCollUri + ".wt";
+// Shut down the secondary. Delete the collection's data file.
+MongoRunner.stopMongod(secondary);
+jsTestLog("Deleting secondary collection file: " + secondaryCollFile);
+removeFile(secondaryCollFile);
+
+// Ensure the secondary can be repaired successfully.
+assertRepairSucceeds(secondaryDbpath, secondaryPort);
+
+// Starting up with --replSet should fail with a specific error.
+assertErrorOnStartupWhenStartingAsReplSet(
+ secondaryDbpath, secondaryPort, replSet.getReplSetConfig()._id);
+
+// Starting up without --replSet should not fail, but the collection should exist with no data.
+assertStartAndStopStandaloneOnExistingDbpath(secondaryDbpath, secondaryPort, function(node) {
+ let nodeDB = node.getDB(dbName);
+ assert(nodeDB[collName].exists());
+ assert.eq(nodeDB[collName].find().itcount(), 0);
+});
+
+// Starting the secondary with a wiped data directory should force an initial sync.
+secondary = assertStartInReplSet(
+ replSet, originalSecondary, true /* cleanData */, true /* expectResync */, function(node) {
let nodeDB = node.getDB(dbName);
- assert(nodeDB[collName].exists());
- assert.eq(nodeDB[collName].find().itcount(), 0);
+ assert.eq(nodeDB[collName].find().itcount(), 1);
});
-
- // Starting the secondary with a wiped data directory should force an initial sync.
- secondary = assertStartInReplSet(
- replSet, originalSecondary, true /* cleanData */, true /* expectResync */, function(node) {
- let nodeDB = node.getDB(dbName);
- assert.eq(nodeDB[collName].find().itcount(), 1);
- });
- secondaryDB = secondary.getDB(dbName);
-
- //
- // 3. This test corrupts the _mdb_catalog file on a secondary, repairs the data. Because the
- // node's local.system.replset collection gets deleted, we assert that it is able to start up
- // and re-sync on the existing data directory immediately.
-
- // Shut down the secondary. Delete the catalog file.
- MongoRunner.stopMongod(secondary);
- let mdbCatalogFile = secondaryDbpath + "/_mdb_catalog.wt";
- jsTestLog("Deleting secondary catalog file: " + mdbCatalogFile);
- removeFile(mdbCatalogFile);
-
- // Ensure the secondary can be repaired successfully.
- assertRepairSucceeds(secondaryDbpath, secondaryPort);
-
- // Starting up without --replSet should not fail, but the collection should exist with no data.
- assertStartAndStopStandaloneOnExistingDbpath(secondaryDbpath, secondaryPort, function(node) {
+secondaryDB = secondary.getDB(dbName);
+
+//
+// 3. This test corrupts the _mdb_catalog file on a secondary, repairs the data. Because the
+// node's local.system.replset collection gets deleted, we assert that it is able to start up
+// and re-sync on the existing data directory immediately.
+
+// Shut down the secondary. Delete the catalog file.
+MongoRunner.stopMongod(secondary);
+let mdbCatalogFile = secondaryDbpath + "/_mdb_catalog.wt";
+jsTestLog("Deleting secondary catalog file: " + mdbCatalogFile);
+removeFile(mdbCatalogFile);
+
+// Ensure the secondary can be repaired successfully.
+assertRepairSucceeds(secondaryDbpath, secondaryPort);
+
+// Starting up without --replSet should not fail, but the collection should exist with no data.
+assertStartAndStopStandaloneOnExistingDbpath(secondaryDbpath, secondaryPort, function(node) {
+ let nodeDB = node.getDB(dbName);
+ assert(!nodeDB[collName].exists());
+ assert(!nodeDB.getSiblingDB("local")["system.replset"].exists());
+});
+
+// The node's local.system.replset collection has been deleted, so it's perfectly okay that it
+// is is able to start up and re-sync.
+// Starting the secondary with the same data directory should force an initial sync.
+secondary = assertStartInReplSet(
+ replSet, originalSecondary, false /* cleanData */, true /* expectResync */, function(node) {
let nodeDB = node.getDB(dbName);
- assert(!nodeDB[collName].exists());
- assert(!nodeDB.getSiblingDB("local")["system.replset"].exists());
+ assert.eq(nodeDB[collName].find().itcount(), 1);
});
- // The node's local.system.replset collection has been deleted, so it's perfectly okay that it
- // is is able to start up and re-sync.
- // Starting the secondary with the same data directory should force an initial sync.
- secondary = assertStartInReplSet(
- replSet, originalSecondary, false /* cleanData */, true /* expectResync */, function(node) {
- let nodeDB = node.getDB(dbName);
- assert.eq(nodeDB[collName].find().itcount(), 1);
- });
-
- replSet.stopSet();
-
+replSet.stopSet();
})();
diff --git a/jstests/disk/wt_corrupt_file_errors.js b/jstests/disk/wt_corrupt_file_errors.js
index 5f829e5de8f..c45b5ae80df 100644
--- a/jstests/disk/wt_corrupt_file_errors.js
+++ b/jstests/disk/wt_corrupt_file_errors.js
@@ -6,73 +6,69 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/disk/libs/wt_file_helper.js');
- const baseName = "wt_corrupt_file_errors";
- const collName = "test";
- const dbpath = MongoRunner.dataPath + baseName + "/";
+const baseName = "wt_corrupt_file_errors";
+const collName = "test";
+const dbpath = MongoRunner.dataPath + baseName + "/";
- /**
- * Test 1. Corrupt a collection's .wt file.
- */
-
- assertErrorOnStartupWhenFilesAreCorruptOrMissing(
- dbpath, baseName, collName, (mongod, testColl) => {
- const testCollUri = getUriForColl(testColl);
- const testCollFile = dbpath + testCollUri + ".wt";
- MongoRunner.stopMongod(mongod);
- jsTestLog("corrupting collection file: " + testCollFile);
- corruptFile(testCollFile);
- }, "Fatal Assertion 50882");
+/**
+ * Test 1. Corrupt a collection's .wt file.
+ */
- /**
- * Test 2. Corrupt the _mdb_catalog.
- */
+assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
+ const testCollUri = getUriForColl(testColl);
+ const testCollFile = dbpath + testCollUri + ".wt";
+ MongoRunner.stopMongod(mongod);
+ jsTestLog("corrupting collection file: " + testCollFile);
+ corruptFile(testCollFile);
+}, "Fatal Assertion 50882");
- assertErrorOnStartupWhenFilesAreCorruptOrMissing(
- dbpath, baseName, collName, (mongod, testColl) => {
- MongoRunner.stopMongod(mongod);
- const mdbCatalogFile = dbpath + "_mdb_catalog.wt";
- jsTestLog("corrupting catalog file: " + mdbCatalogFile);
- corruptFile(mdbCatalogFile);
- }, "Fatal Assertion 50882");
+/**
+ * Test 2. Corrupt the _mdb_catalog.
+ */
- /**
- * Test 3. Corrupt the WiredTiger.wt.
- */
+assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
+ MongoRunner.stopMongod(mongod);
+ const mdbCatalogFile = dbpath + "_mdb_catalog.wt";
+ jsTestLog("corrupting catalog file: " + mdbCatalogFile);
+ corruptFile(mdbCatalogFile);
+}, "Fatal Assertion 50882");
- assertErrorOnStartupWhenFilesAreCorruptOrMissing(
- dbpath, baseName, collName, (mongod, testColl) => {
- MongoRunner.stopMongod(mongod);
- const WiredTigerWTFile = dbpath + "WiredTiger.wt";
- jsTestLog("corrupting WiredTiger.wt");
- corruptFile(WiredTigerWTFile);
- }, "Fatal Assertion 50944");
+/**
+ * Test 3. Corrupt the WiredTiger.wt.
+ */
- /**
- * Test 4. Corrupt an index file.
- */
+assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
+ MongoRunner.stopMongod(mongod);
+ const WiredTigerWTFile = dbpath + "WiredTiger.wt";
+ jsTestLog("corrupting WiredTiger.wt");
+ corruptFile(WiredTigerWTFile);
+}, "Fatal Assertion 50944");
- assertErrorOnRequestWhenFilesAreCorruptOrMissing(
- dbpath,
- baseName,
- collName,
- (mongod, testColl) => {
- const indexName = "a_1";
- assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
- const indexUri = getUriForIndex(testColl, indexName);
- MongoRunner.stopMongod(mongod);
- const indexFile = dbpath + indexUri + ".wt";
- jsTestLog("corrupting index file: " + indexFile);
- corruptFile(indexFile);
- },
- (testColl) => {
- // This insert will crash the server because it triggers the code path
- // of looking for the index file.
- assert.throws(function() {
- testColl.insert({a: 1});
- });
- },
- "Fatal Assertion 50882");
+/**
+ * Test 4. Corrupt an index file.
+ */
+assertErrorOnRequestWhenFilesAreCorruptOrMissing(
+ dbpath,
+ baseName,
+ collName,
+ (mongod, testColl) => {
+ const indexName = "a_1";
+ assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
+ const indexUri = getUriForIndex(testColl, indexName);
+ MongoRunner.stopMongod(mongod);
+ const indexFile = dbpath + indexUri + ".wt";
+ jsTestLog("corrupting index file: " + indexFile);
+ corruptFile(indexFile);
+ },
+ (testColl) => {
+ // This insert will crash the server because it triggers the code path
+ // of looking for the index file.
+ assert.throws(function() {
+ testColl.insert({a: 1});
+ });
+ },
+ "Fatal Assertion 50882");
})();
diff --git a/jstests/disk/wt_missing_file_errors.js b/jstests/disk/wt_missing_file_errors.js
index 3a9c783aad6..1a28ff17f9c 100644
--- a/jstests/disk/wt_missing_file_errors.js
+++ b/jstests/disk/wt_missing_file_errors.js
@@ -6,73 +6,69 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/disk/libs/wt_file_helper.js');
- const baseName = "wt_missing_file_errors";
- const collName = "test";
- const dbpath = MongoRunner.dataPath + baseName + "/";
+const baseName = "wt_missing_file_errors";
+const collName = "test";
+const dbpath = MongoRunner.dataPath + baseName + "/";
- /**
- * Test 1. Delete a collection's .wt file.
- */
-
- assertErrorOnStartupWhenFilesAreCorruptOrMissing(
- dbpath, baseName, collName, (mongod, testColl) => {
- const testCollUri = getUriForColl(testColl);
- const testCollFile = dbpath + testCollUri + ".wt";
- MongoRunner.stopMongod(mongod);
- jsTestLog("deleting collection file: " + testCollFile);
- removeFile(testCollFile);
- }, "Fatal Assertion 50882");
+/**
+ * Test 1. Delete a collection's .wt file.
+ */
- /**
- * Test 2. Delete the _mdb_catalog.
- */
+assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
+ const testCollUri = getUriForColl(testColl);
+ const testCollFile = dbpath + testCollUri + ".wt";
+ MongoRunner.stopMongod(mongod);
+ jsTestLog("deleting collection file: " + testCollFile);
+ removeFile(testCollFile);
+}, "Fatal Assertion 50882");
- assertErrorOnStartupWhenFilesAreCorruptOrMissing(
- dbpath, baseName, collName, (mongod, testColl) => {
- MongoRunner.stopMongod(mongod);
- let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
- jsTestLog("deleting catalog file: " + mdbCatalogFile);
- removeFile(mdbCatalogFile);
- }, "Fatal Assertion 50882");
+/**
+ * Test 2. Delete the _mdb_catalog.
+ */
- /**
- * Test 3. Delete the WiredTiger.wt.
- */
+assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
+ MongoRunner.stopMongod(mongod);
+ let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
+ jsTestLog("deleting catalog file: " + mdbCatalogFile);
+ removeFile(mdbCatalogFile);
+}, "Fatal Assertion 50882");
- assertErrorOnStartupWhenFilesAreCorruptOrMissing(
- dbpath, baseName, collName, (mongod, testColl) => {
- MongoRunner.stopMongod(mongod);
- let WiredTigerWTFile = dbpath + "WiredTiger.wt";
- jsTestLog("deleting WiredTiger.wt");
- removeFile(WiredTigerWTFile);
- }, "Fatal Assertion 28595");
+/**
+ * Test 3. Delete the WiredTiger.wt.
+ */
- /**
- * Test 4. Delete an index file.
- */
+assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
+ MongoRunner.stopMongod(mongod);
+ let WiredTigerWTFile = dbpath + "WiredTiger.wt";
+ jsTestLog("deleting WiredTiger.wt");
+ removeFile(WiredTigerWTFile);
+}, "Fatal Assertion 28595");
- assertErrorOnRequestWhenFilesAreCorruptOrMissing(
- dbpath,
- baseName,
- collName,
- (mongod, testColl) => {
- const indexName = "a_1";
- assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
- const indexUri = getUriForIndex(testColl, indexName);
- MongoRunner.stopMongod(mongod);
- const indexFile = dbpath + indexUri + ".wt";
- jsTestLog("deleting index file: " + indexFile);
- removeFile(indexFile);
- },
- (testColl) => {
- // This insert will crash the server because it triggers the code path
- // of looking for the index file.
- assert.throws(function() {
- testColl.insert({a: 1});
- });
- },
- "Fatal Assertion 50882");
+/**
+ * Test 4. Delete an index file.
+ */
+assertErrorOnRequestWhenFilesAreCorruptOrMissing(
+ dbpath,
+ baseName,
+ collName,
+ (mongod, testColl) => {
+ const indexName = "a_1";
+ assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
+ const indexUri = getUriForIndex(testColl, indexName);
+ MongoRunner.stopMongod(mongod);
+ const indexFile = dbpath + indexUri + ".wt";
+ jsTestLog("deleting index file: " + indexFile);
+ removeFile(indexFile);
+ },
+ (testColl) => {
+ // This insert will crash the server because it triggers the code path
+ // of looking for the index file.
+ assert.throws(function() {
+ testColl.insert({a: 1});
+ });
+ },
+ "Fatal Assertion 50882");
})();
diff --git a/jstests/disk/wt_repair_corrupt_files.js b/jstests/disk/wt_repair_corrupt_files.js
index c19a6d672d1..839dda32ab7 100644
--- a/jstests/disk/wt_repair_corrupt_files.js
+++ b/jstests/disk/wt_repair_corrupt_files.js
@@ -7,109 +7,109 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/disk/libs/wt_file_helper.js');
- const baseName = "wt_repair_corrupt_files";
- const collName = "test";
- const dbpath = MongoRunner.dataPath + baseName + "/";
+const baseName = "wt_repair_corrupt_files";
+const collName = "test";
+const dbpath = MongoRunner.dataPath + baseName + "/";
+
+/**
+ * Run the test by supplying additional paramters to MongoRunner.runMongod with 'mongodOptions'.
+ */
+let runTest = function(mongodOptions) {
+ resetDbpath(dbpath);
+ jsTestLog("Running test with args: " + tojson(mongodOptions));
/**
- * Run the test by supplying additional paramters to MongoRunner.runMongod with 'mongodOptions'.
+ * Test 1. Create a collection, corrupt its .wt file in an unrecoverable way, run repair.
+ * Verify that repair succeeds at rebuilding it. An empty collection should be visible on
+ * normal startup.
*/
- let runTest = function(mongodOptions) {
- resetDbpath(dbpath);
- jsTestLog("Running test with args: " + tojson(mongodOptions));
-
- /**
- * Test 1. Create a collection, corrupt its .wt file in an unrecoverable way, run repair.
- * Verify that repair succeeds at rebuilding it. An empty collection should be visible on
- * normal startup.
- */
- let mongod = startMongodOnExistingPath(dbpath, mongodOptions);
- let testColl = mongod.getDB(baseName)[collName];
+ let mongod = startMongodOnExistingPath(dbpath, mongodOptions);
+ let testColl = mongod.getDB(baseName)[collName];
- const doc = {a: 1};
- assert.commandWorked(testColl.insert(doc));
+ const doc = {a: 1};
+ assert.commandWorked(testColl.insert(doc));
- let testCollUri = getUriForColl(testColl);
- let testCollFile = dbpath + testCollUri + ".wt";
+ let testCollUri = getUriForColl(testColl);
+ let testCollFile = dbpath + testCollUri + ".wt";
- MongoRunner.stopMongod(mongod);
+ MongoRunner.stopMongod(mongod);
- jsTestLog("corrupting collection file: " + testCollFile);
- corruptFile(testCollFile);
+ jsTestLog("corrupting collection file: " + testCollFile);
+ corruptFile(testCollFile);
- assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
+ assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
- mongod = startMongodOnExistingPath(dbpath, mongodOptions);
- testColl = mongod.getDB(baseName)[collName];
+ mongod = startMongodOnExistingPath(dbpath, mongodOptions);
+ testColl = mongod.getDB(baseName)[collName];
- assert.eq(testCollUri, getUriForColl(testColl));
- assert.eq(testColl.find({}).itcount(), 0);
- assert.eq(testColl.count(), 0);
+ assert.eq(testCollUri, getUriForColl(testColl));
+ assert.eq(testColl.find({}).itcount(), 0);
+ assert.eq(testColl.count(), 0);
- /**
- * Test 2. Corrupt an index file in an unrecoverable way. Verify that repair rebuilds and
- * allows MongoDB to start up normally.
- */
+ /**
+ * Test 2. Corrupt an index file in an unrecoverable way. Verify that repair rebuilds and
+ * allows MongoDB to start up normally.
+ */
- assert.commandWorked(testColl.insert(doc));
+ assert.commandWorked(testColl.insert(doc));
- const indexName = "a_1";
- assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
- assertQueryUsesIndex(testColl, doc, indexName);
+ const indexName = "a_1";
+ assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
+ assertQueryUsesIndex(testColl, doc, indexName);
- let indexUri = getUriForIndex(testColl, indexName);
+ let indexUri = getUriForIndex(testColl, indexName);
- MongoRunner.stopMongod(mongod);
+ MongoRunner.stopMongod(mongod);
- let indexFile = dbpath + indexUri + ".wt";
- jsTestLog("corrupting index file: " + indexFile);
- corruptFile(indexFile);
+ let indexFile = dbpath + indexUri + ".wt";
+ jsTestLog("corrupting index file: " + indexFile);
+ corruptFile(indexFile);
- assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
- mongod = startMongodOnExistingPath(dbpath, mongodOptions);
- testColl = mongod.getDB(baseName)[collName];
+ assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
+ mongod = startMongodOnExistingPath(dbpath, mongodOptions);
+ testColl = mongod.getDB(baseName)[collName];
- // Repair creates new idents.
- assert.neq(indexUri, getUriForIndex(testColl, indexName));
+ // Repair creates new idents.
+ assert.neq(indexUri, getUriForIndex(testColl, indexName));
- assertQueryUsesIndex(testColl, doc, indexName);
- assert.eq(testColl.find(doc).itcount(), 1);
- assert.eq(testColl.count(), 1);
+ assertQueryUsesIndex(testColl, doc, indexName);
+ assert.eq(testColl.find(doc).itcount(), 1);
+ assert.eq(testColl.count(), 1);
- MongoRunner.stopMongod(mongod);
+ MongoRunner.stopMongod(mongod);
- /**
- * Test 3. Corrupt the _mdb_catalog in an unrecoverable way. Verify that repair suceeds
- * in creating an empty catalog and recovers the orphaned testColl, which will still be
- * accessible in the 'local.orphan-' namespace.
- */
+ /**
+ * Test 3. Corrupt the _mdb_catalog in an unrecoverable way. Verify that repair suceeds
+ * in creating an empty catalog and recovers the orphaned testColl, which will still be
+ * accessible in the 'local.orphan-' namespace.
+ */
- let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
- jsTestLog("corrupting catalog file: " + mdbCatalogFile);
- corruptFile(mdbCatalogFile);
+ let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
+ jsTestLog("corrupting catalog file: " + mdbCatalogFile);
+ corruptFile(mdbCatalogFile);
- assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
+ assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
- mongod = startMongodOnExistingPath(dbpath, mongodOptions);
- testColl = mongod.getDB(baseName)[collName];
- assert.isnull(testColl.exists());
- assert.eq(testColl.find(doc).itcount(), 0);
- assert.eq(testColl.count(), 0);
+ mongod = startMongodOnExistingPath(dbpath, mongodOptions);
+ testColl = mongod.getDB(baseName)[collName];
+ assert.isnull(testColl.exists());
+ assert.eq(testColl.find(doc).itcount(), 0);
+ assert.eq(testColl.count(), 0);
- // Ensure the collection orphan was created with the existing document.
- const orphanCollName = "orphan." + testCollUri.replace(/-/g, "_");
- let orphanColl = mongod.getDB('local').getCollection(orphanCollName);
- assert(orphanColl.exists());
- assert.eq(orphanColl.find(doc).itcount(), 1);
- assert.eq(orphanColl.count(), 1);
+ // Ensure the collection orphan was created with the existing document.
+ const orphanCollName = "orphan." + testCollUri.replace(/-/g, "_");
+ let orphanColl = mongod.getDB('local').getCollection(orphanCollName);
+ assert(orphanColl.exists());
+ assert.eq(orphanColl.find(doc).itcount(), 1);
+ assert.eq(orphanColl.count(), 1);
- MongoRunner.stopMongod(mongod);
- };
+ MongoRunner.stopMongod(mongod);
+};
- runTest({});
- runTest({directoryperdb: ""});
- runTest({wiredTigerDirectoryForIndexes: ""});
+runTest({});
+runTest({directoryperdb: ""});
+runTest({wiredTigerDirectoryForIndexes: ""});
})();
diff --git a/jstests/disk/wt_repair_corrupt_metadata.js b/jstests/disk/wt_repair_corrupt_metadata.js
index 0b4bc6a6083..2f8edfe2608 100644
--- a/jstests/disk/wt_repair_corrupt_metadata.js
+++ b/jstests/disk/wt_repair_corrupt_metadata.js
@@ -7,112 +7,112 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
-
- const baseName = "wt_repair_corrupt_metadata";
- const collName = "test";
- const dbpath = MongoRunner.dataPath + baseName + "/";
-
- /**
- * This test runs repair using a version of the WiredTiger.turtle file that has checkpoint
- * information before the collection was created. The turtle file contains checkpoint
- * information about the WiredTiger.wt file, so if these two files become out of sync,
- * WiredTiger will have to attempt a salvage operation on the .wt file and rebuild the .turtle
- * file.
- *
- * The expectation is that the metadata salvage will be successful, and that the collection will
- * be recreated with all of its data.
- */
- let runTest = function(mongodOptions) {
- // Unfortunately using --nojournal triggers a WT_PANIC and aborts in debug builds, which the
- // following test case can exercise.
- // TODO: This return can be removed once WT-4310 is completed.
- let isDebug = db.adminCommand('buildInfo').debug;
- if (isDebug) {
- jsTestLog("Skipping test case because this is a debug build");
- return;
- }
-
- resetDbpath(dbpath);
- jsTestLog("Running test with args: " + tojson(mongodOptions));
+load('jstests/disk/libs/wt_file_helper.js');
- const turtleFile = dbpath + "WiredTiger.turtle";
- const turtleFileWithoutCollection = dbpath + "WiredTiger.turtle.1";
+const baseName = "wt_repair_corrupt_metadata";
+const collName = "test";
+const dbpath = MongoRunner.dataPath + baseName + "/";
- let mongod = startMongodOnExistingPath(dbpath, mongodOptions);
-
- // Force a checkpoint and make a copy of the turtle file.
- assert.commandWorked(mongod.getDB(baseName).adminCommand({fsync: 1}));
- jsTestLog("Making copy of metadata file before creating the collection: " +
- turtleFileWithoutCollection);
- copyFile(turtleFile, turtleFileWithoutCollection);
-
- let testColl = mongod.getDB(baseName)[collName];
- assert.commandWorked(testColl.insert({a: 1}));
+/**
+ * This test runs repair using a version of the WiredTiger.turtle file that has checkpoint
+ * information before the collection was created. The turtle file contains checkpoint
+ * information about the WiredTiger.wt file, so if these two files become out of sync,
+ * WiredTiger will have to attempt a salvage operation on the .wt file and rebuild the .turtle
+ * file.
+ *
+ * The expectation is that the metadata salvage will be successful, and that the collection will
+ * be recreated with all of its data.
+ */
+let runTest = function(mongodOptions) {
+ // Unfortunately using --nojournal triggers a WT_PANIC and aborts in debug builds, which the
+ // following test case can exercise.
+ // TODO: This return can be removed once WT-4310 is completed.
+ let isDebug = db.adminCommand('buildInfo').debug;
+ if (isDebug) {
+ jsTestLog("Skipping test case because this is a debug build");
+ return;
+ }
+
+ resetDbpath(dbpath);
+ jsTestLog("Running test with args: " + tojson(mongodOptions));
+
+ const turtleFile = dbpath + "WiredTiger.turtle";
+ const turtleFileWithoutCollection = dbpath + "WiredTiger.turtle.1";
+
+ let mongod = startMongodOnExistingPath(dbpath, mongodOptions);
+
+ // Force a checkpoint and make a copy of the turtle file.
+ assert.commandWorked(mongod.getDB(baseName).adminCommand({fsync: 1}));
+ jsTestLog("Making copy of metadata file before creating the collection: " +
+ turtleFileWithoutCollection);
+ copyFile(turtleFile, turtleFileWithoutCollection);
+
+ let testColl = mongod.getDB(baseName)[collName];
+ assert.commandWorked(testColl.insert({a: 1}));
+
+ // Force another checkpoint before a clean shutdown.
+ assert.commandWorked(mongod.getDB(baseName).adminCommand({fsync: 1}));
+ MongoRunner.stopMongod(mongod);
+
+ // Guarantee the turtle files changed between checkpoints.
+ assert.neq(md5sumFile(turtleFileWithoutCollection), md5sumFile(turtleFile));
+
+ jsTestLog("Replacing metadata file with a version before the collection existed.");
+ removeFile(turtleFile);
+ copyFile(turtleFileWithoutCollection, turtleFile);
+
+ // This test characterizes the current WiredTiger salvage behaviour, which may be subject to
+ // change in the future. See SERVER-41667.
+ assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
+
+ mongod = startMongodOnExistingPath(dbpath, mongodOptions);
+ testColl = mongod.getDB(baseName)[collName];
+
+ // The collection exists despite using an older turtle file because salvage is able to find
+ // the table in the WiredTiger.wt file.
+ assert(testColl.exists());
+ // We can assert that the data exists because the salvage only took place on the metadata,
+ // not the data.
+ assert.eq(testColl.find({}).itcount(), 1);
+ MongoRunner.stopMongod(mongod);
+
+ // Corrupt the .turtle file in a very specific way such that the log sequence numbers are
+ // invalid.
+ if (mongodOptions.hasOwnProperty('journal')) {
+ // TODO: This return can be removed once WT-4459 is completed.
+ if (_isAddressSanitizerActive()) {
+ jsTestLog("Skipping log file corruption because the address sanitizer is active.");
+ return;
+ }
- // Force another checkpoint before a clean shutdown.
- assert.commandWorked(mongod.getDB(baseName).adminCommand({fsync: 1}));
- MongoRunner.stopMongod(mongod);
+ jsTestLog("Corrupting log file metadata");
- // Guarantee the turtle files changed between checkpoints.
- assert.neq(md5sumFile(turtleFileWithoutCollection), md5sumFile(turtleFile));
+ let data = cat(turtleFile, true /* useBinaryMode */);
+ let re = /checkpoint_lsn=\(([0-9,]+)\)/g;
+ let newData = data.replace(re, "checkpoint_lsn=(1,2)");
- jsTestLog("Replacing metadata file with a version before the collection existed.");
+ print('writing data to new turtle file: \n' + newData);
removeFile(turtleFile);
- copyFile(turtleFileWithoutCollection, turtleFile);
+ writeFile(turtleFile, newData, true /* useBinaryMode */);
- // This test characterizes the current WiredTiger salvage behaviour, which may be subject to
- // change in the future. See SERVER-41667.
assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
mongod = startMongodOnExistingPath(dbpath, mongodOptions);
testColl = mongod.getDB(baseName)[collName];
- // The collection exists despite using an older turtle file because salvage is able to find
- // the table in the WiredTiger.wt file.
+ // The collection exists despite using a salvaged turtle file because salvage is able to
+ // find the table in the WiredTiger.wt file.
assert(testColl.exists());
- // We can assert that the data exists because the salvage only took place on the metadata,
- // not the data.
+
+ // We can assert that the data exists because the salvage only took place on the
+ // metadata, not the data.
assert.eq(testColl.find({}).itcount(), 1);
MongoRunner.stopMongod(mongod);
+ }
+};
- // Corrupt the .turtle file in a very specific way such that the log sequence numbers are
- // invalid.
- if (mongodOptions.hasOwnProperty('journal')) {
- // TODO: This return can be removed once WT-4459 is completed.
- if (_isAddressSanitizerActive()) {
- jsTestLog("Skipping log file corruption because the address sanitizer is active.");
- return;
- }
-
- jsTestLog("Corrupting log file metadata");
-
- let data = cat(turtleFile, true /* useBinaryMode */);
- let re = /checkpoint_lsn=\(([0-9,]+)\)/g;
- let newData = data.replace(re, "checkpoint_lsn=(1,2)");
-
- print('writing data to new turtle file: \n' + newData);
- removeFile(turtleFile);
- writeFile(turtleFile, newData, true /* useBinaryMode */);
-
- assertRepairSucceeds(dbpath, mongod.port, mongodOptions);
-
- mongod = startMongodOnExistingPath(dbpath, mongodOptions);
- testColl = mongod.getDB(baseName)[collName];
-
- // The collection exists despite using a salvaged turtle file because salvage is able to
- // find the table in the WiredTiger.wt file.
- assert(testColl.exists());
-
- // We can assert that the data exists because the salvage only took place on the
- // metadata, not the data.
- assert.eq(testColl.find({}).itcount(), 1);
- MongoRunner.stopMongod(mongod);
- }
- };
-
- // Repair may behave differently with journaling enabled or disabled, but the end result should
- // be the same.
- runTest({journal: ""});
- runTest({nojournal: ""});
+// Repair may behave differently with journaling enabled or disabled, but the end result should
+// be the same.
+runTest({journal: ""});
+runTest({nojournal: ""});
})();
diff --git a/jstests/disk/wt_repair_missing_files.js b/jstests/disk/wt_repair_missing_files.js
index 7e2f2fa2bf8..e9d505458e9 100644
--- a/jstests/disk/wt_repair_missing_files.js
+++ b/jstests/disk/wt_repair_missing_files.js
@@ -7,138 +7,140 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/disk/libs/wt_file_helper.js');
- const baseName = "wt_repair_missing_files";
- const collName = "test";
- const dbpath = MongoRunner.dataPath + baseName + "/";
+const baseName = "wt_repair_missing_files";
+const collName = "test";
+const dbpath = MongoRunner.dataPath + baseName + "/";
- resetDbpath(dbpath);
+resetDbpath(dbpath);
- /**
- * Test 1. Create a collection, delete it's .wt file, run repair. Verify that repair succeeds at
- * re-creating it. The collection should be visible on normal startup.
- */
+/**
+ * Test 1. Create a collection, delete it's .wt file, run repair. Verify that repair succeeds at
+ * re-creating it. The collection should be visible on normal startup.
+ */
- let mongod = startMongodOnExistingPath(dbpath);
- let testColl = mongod.getDB(baseName)[collName];
+let mongod = startMongodOnExistingPath(dbpath);
+let testColl = mongod.getDB(baseName)[collName];
- const doc = {a: 1};
- assert.commandWorked(testColl.insert(doc));
+const doc = {
+ a: 1
+};
+assert.commandWorked(testColl.insert(doc));
- let testCollUri = getUriForColl(testColl);
- let testCollFile = dbpath + testCollUri + ".wt";
+let testCollUri = getUriForColl(testColl);
+let testCollFile = dbpath + testCollUri + ".wt";
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
- jsTestLog("deleting collection file: " + testCollFile);
- removeFile(testCollFile);
+jsTestLog("deleting collection file: " + testCollFile);
+removeFile(testCollFile);
- assertRepairSucceeds(dbpath, mongod.port);
+assertRepairSucceeds(dbpath, mongod.port);
- mongod = startMongodOnExistingPath(dbpath);
- testColl = mongod.getDB(baseName)[collName];
+mongod = startMongodOnExistingPath(dbpath);
+testColl = mongod.getDB(baseName)[collName];
- assert.eq(testCollUri, getUriForColl(testColl));
- assert.eq(testColl.find({}).itcount(), 0);
- assert.eq(testColl.count(), 0);
+assert.eq(testCollUri, getUriForColl(testColl));
+assert.eq(testColl.find({}).itcount(), 0);
+assert.eq(testColl.count(), 0);
- /**
- * Test 2. Delete an index file. Verify that repair rebuilds and allows MongoDB to start up
- * normally.
- */
+/**
+ * Test 2. Delete an index file. Verify that repair rebuilds and allows MongoDB to start up
+ * normally.
+ */
- assert.commandWorked(testColl.insert(doc));
+assert.commandWorked(testColl.insert(doc));
- const indexName = "a_1";
- assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
- assertQueryUsesIndex(testColl, doc, indexName);
+const indexName = "a_1";
+assert.commandWorked(testColl.createIndex({a: 1}, {name: indexName}));
+assertQueryUsesIndex(testColl, doc, indexName);
- let indexUri = getUriForIndex(testColl, indexName);
+let indexUri = getUriForIndex(testColl, indexName);
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
- let indexFile = dbpath + indexUri + ".wt";
- jsTestLog("deleting index file: " + indexFile);
- removeFile(indexFile);
+let indexFile = dbpath + indexUri + ".wt";
+jsTestLog("deleting index file: " + indexFile);
+removeFile(indexFile);
- assertRepairSucceeds(dbpath, mongod.port);
- mongod = startMongodOnExistingPath(dbpath);
- testColl = mongod.getDB(baseName)[collName];
+assertRepairSucceeds(dbpath, mongod.port);
+mongod = startMongodOnExistingPath(dbpath);
+testColl = mongod.getDB(baseName)[collName];
- // Repair creates new idents.
- assert.neq(indexUri, getUriForIndex(testColl, indexName));
+// Repair creates new idents.
+assert.neq(indexUri, getUriForIndex(testColl, indexName));
- assertQueryUsesIndex(testColl, doc, indexName);
- assert.eq(testColl.find(doc).itcount(), 1);
- assert.eq(testColl.count(), 1);
+assertQueryUsesIndex(testColl, doc, indexName);
+assert.eq(testColl.find(doc).itcount(), 1);
+assert.eq(testColl.count(), 1);
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
- /**
- * Test 3. Delete the sizeStorer. Verify that repair suceeds in recreating it.
- */
+/**
+ * Test 3. Delete the sizeStorer. Verify that repair suceeds in recreating it.
+ */
- let sizeStorerFile = dbpath + "sizeStorer.wt";
- jsTestLog("deleting size storer file: " + sizeStorerFile);
- removeFile(sizeStorerFile);
+let sizeStorerFile = dbpath + "sizeStorer.wt";
+jsTestLog("deleting size storer file: " + sizeStorerFile);
+removeFile(sizeStorerFile);
- assertRepairSucceeds(dbpath, mongod.port);
+assertRepairSucceeds(dbpath, mongod.port);
- mongod = startMongodOnExistingPath(dbpath);
- testColl = mongod.getDB(baseName)[collName];
+mongod = startMongodOnExistingPath(dbpath);
+testColl = mongod.getDB(baseName)[collName];
- assert.eq(testColl.find(doc).itcount(), 1);
- assert.eq(testColl.count(), 1);
- MongoRunner.stopMongod(mongod);
+assert.eq(testColl.find(doc).itcount(), 1);
+assert.eq(testColl.count(), 1);
+MongoRunner.stopMongod(mongod);
- /**
- * Test 4. Delete the _mdb_catalog. Verify that repair suceeds in creating an empty catalog and
- * MongoDB starts up normally with no data.
- */
+/**
+ * Test 4. Delete the _mdb_catalog. Verify that repair suceeds in creating an empty catalog and
+ * MongoDB starts up normally with no data.
+ */
- let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
- jsTestLog("deleting catalog file: " + mdbCatalogFile);
- removeFile(mdbCatalogFile);
+let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
+jsTestLog("deleting catalog file: " + mdbCatalogFile);
+removeFile(mdbCatalogFile);
- assertRepairSucceeds(dbpath, mongod.port);
+assertRepairSucceeds(dbpath, mongod.port);
- mongod = startMongodOnExistingPath(dbpath);
- testColl = mongod.getDB(baseName)[collName];
- assert.isnull(testColl.exists());
+mongod = startMongodOnExistingPath(dbpath);
+testColl = mongod.getDB(baseName)[collName];
+assert.isnull(testColl.exists());
- assert.eq(testColl.find(doc).itcount(), 0);
- assert.eq(testColl.count(), 0);
+assert.eq(testColl.find(doc).itcount(), 0);
+assert.eq(testColl.count(), 0);
- /**
- * Test 5. Verify that using repair with --directoryperdb creates a missing directory and its
- * files, allowing MongoDB to start up normally.
- */
+/**
+ * Test 5. Verify that using repair with --directoryperdb creates a missing directory and its
+ * files, allowing MongoDB to start up normally.
+ */
- MongoRunner.stopMongod(mongod);
- resetDbpath(dbpath);
+MongoRunner.stopMongod(mongod);
+resetDbpath(dbpath);
- mongod = startMongodOnExistingPath(dbpath, {directoryperdb: ""});
- testColl = mongod.getDB(baseName)[collName];
+mongod = startMongodOnExistingPath(dbpath, {directoryperdb: ""});
+testColl = mongod.getDB(baseName)[collName];
- assert.commandWorked(testColl.insert(doc));
+assert.commandWorked(testColl.insert(doc));
- testCollUri = getUriForColl(testColl);
+testCollUri = getUriForColl(testColl);
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
- let dataDir = dbpath + baseName;
- jsTestLog("deleting data directory: " + dataDir);
- removeFile(dataDir);
+let dataDir = dbpath + baseName;
+jsTestLog("deleting data directory: " + dataDir);
+removeFile(dataDir);
- assertRepairSucceeds(dbpath, mongod.port, {directoryperdb: ""});
+assertRepairSucceeds(dbpath, mongod.port, {directoryperdb: ""});
- mongod = startMongodOnExistingPath(dbpath, {directoryperdb: ""});
- testColl = mongod.getDB(baseName)[collName];
+mongod = startMongodOnExistingPath(dbpath, {directoryperdb: ""});
+testColl = mongod.getDB(baseName)[collName];
- assert.eq(testCollUri, getUriForColl(testColl));
- assert.eq(testColl.find({}).itcount(), 0);
- assert.eq(testColl.count(), 0);
+assert.eq(testCollUri, getUriForColl(testColl));
+assert.eq(testColl.find({}).itcount(), 0);
+assert.eq(testColl.count(), 0);
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
})();
diff --git a/jstests/disk/wt_repair_orphaned_idents.js b/jstests/disk/wt_repair_orphaned_idents.js
index 43d57f1ff28..83d3bfee424 100644
--- a/jstests/disk/wt_repair_orphaned_idents.js
+++ b/jstests/disk/wt_repair_orphaned_idents.js
@@ -6,83 +6,81 @@
(function() {
- load('jstests/disk/libs/wt_file_helper.js');
-
- const baseName = "wt_repair_orphaned_idents";
- const dbpath = MongoRunner.dataPath + baseName + "/";
-
- resetDbpath(dbpath);
-
- // Create a collection and insert a doc.
- let mongod = MongoRunner.runMongod({dbpath: dbpath});
- const importantCollName = "importantColl";
- const importantDocId = "importantDoc";
- const importantColl = mongod.getDB("test")[importantCollName];
- assert.commandWorked(importantColl.insert({_id: importantDocId}));
- const importantCollIdent = getUriForColl(importantColl);
- MongoRunner.stopMongod(mongod);
-
- // Delete the _mdb_catalog.
- let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
- jsTestLog("deleting catalog file: " + mdbCatalogFile);
- removeFile(mdbCatalogFile);
-
- // Repair crates the _mdb_catalog and catalog entries for all the orphaned idents.
- jsTestLog("running mongod with --repair");
- assert.eq(0, runMongoProgram("mongod", "--repair", "--port", mongod.port, "--dbpath", dbpath));
-
- jsTestLog("restarting mongod");
- mongod = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
-
- let localDb = mongod.getDB("local");
- let res = localDb.runCommand({listCollections: 1});
- assert.commandWorked(res, tojson(res));
-
- // This is the function that 'show collections' uses.
- let collNames = localDb.getCollectionNames();
-
- const orphanPrefix = "orphan.";
- let recoveredCount = 0;
- const orphanedImportantCollName = "orphan." + importantCollIdent.replace(/-/g, "_");
- for (let collName of collNames) {
- if (collName.startsWith(orphanPrefix)) {
- // Manually create the _id index.
- assert.commandWorked(localDb[collName].createIndex({_id: 1}));
-
- if (collName == orphanedImportantCollName) {
- assert.commandWorked(localDb.adminCommand(
- {renameCollection: "local." + collName, to: "test." + importantCollName}));
- } else {
- assert.commandWorked(localDb.adminCommand({
- renameCollection: "local." + collName,
- to: "test.recovered" + recoveredCount
- }));
- }
- recoveredCount++;
+load('jstests/disk/libs/wt_file_helper.js');
+
+const baseName = "wt_repair_orphaned_idents";
+const dbpath = MongoRunner.dataPath + baseName + "/";
+
+resetDbpath(dbpath);
+
+// Create a collection and insert a doc.
+let mongod = MongoRunner.runMongod({dbpath: dbpath});
+const importantCollName = "importantColl";
+const importantDocId = "importantDoc";
+const importantColl = mongod.getDB("test")[importantCollName];
+assert.commandWorked(importantColl.insert({_id: importantDocId}));
+const importantCollIdent = getUriForColl(importantColl);
+MongoRunner.stopMongod(mongod);
+
+// Delete the _mdb_catalog.
+let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
+jsTestLog("deleting catalog file: " + mdbCatalogFile);
+removeFile(mdbCatalogFile);
+
+// Repair crates the _mdb_catalog and catalog entries for all the orphaned idents.
+jsTestLog("running mongod with --repair");
+assert.eq(0, runMongoProgram("mongod", "--repair", "--port", mongod.port, "--dbpath", dbpath));
+
+jsTestLog("restarting mongod");
+mongod = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
+
+let localDb = mongod.getDB("local");
+let res = localDb.runCommand({listCollections: 1});
+assert.commandWorked(res, tojson(res));
+
+// This is the function that 'show collections' uses.
+let collNames = localDb.getCollectionNames();
+
+const orphanPrefix = "orphan.";
+let recoveredCount = 0;
+const orphanedImportantCollName = "orphan." + importantCollIdent.replace(/-/g, "_");
+for (let collName of collNames) {
+ if (collName.startsWith(orphanPrefix)) {
+ // Manually create the _id index.
+ assert.commandWorked(localDb[collName].createIndex({_id: 1}));
+
+ if (collName == orphanedImportantCollName) {
+ assert.commandWorked(localDb.adminCommand(
+ {renameCollection: "local." + collName, to: "test." + importantCollName}));
+ } else {
+ assert.commandWorked(localDb.adminCommand(
+ {renameCollection: "local." + collName, to: "test.recovered" + recoveredCount}));
}
+ recoveredCount++;
}
- assert.gt(recoveredCount, 0);
+}
+assert.gt(recoveredCount, 0);
- let testDb = mongod.getDB("test");
+let testDb = mongod.getDB("test");
- // Assert the recovered collection still has the original document.
- assert.eq(testDb[importantCollName].find({_id: importantDocId}).count(), 1);
+// Assert the recovered collection still has the original document.
+assert.eq(testDb[importantCollName].find({_id: importantDocId}).count(), 1);
- res = testDb.runCommand({listCollections: 1});
- assert.commandWorked(res);
- assert.eq(res.cursor.firstBatch.length, recoveredCount);
- for (let entry of res.cursor.firstBatch) {
- let collName = entry.name;
- assert(collName.startsWith("recovered") || collName == importantCollName);
+res = testDb.runCommand({listCollections: 1});
+assert.commandWorked(res);
+assert.eq(res.cursor.firstBatch.length, recoveredCount);
+for (let entry of res.cursor.firstBatch) {
+ let collName = entry.name;
+ assert(collName.startsWith("recovered") || collName == importantCollName);
- // Assert _id index has been successfully created.
- assert("idIndex" in entry);
+ // Assert _id index has been successfully created.
+ assert("idIndex" in entry);
- // Make sure we can interact with the recovered collections.
- assert.commandWorked(testDb.runCommand({find: collName}));
- assert.commandWorked(testDb[collName].insert({x: 1}));
- assert(testDb[collName].drop());
- }
+ // Make sure we can interact with the recovered collections.
+ assert.commandWorked(testDb.runCommand({find: collName}));
+ assert.commandWorked(testDb[collName].insert({x: 1}));
+ assert(testDb[collName].drop());
+}
- MongoRunner.stopMongod(mongod);
+MongoRunner.stopMongod(mongod);
})();