mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
85 lines
2.3 KiB
JavaScript
85 lines
2.3 KiB
JavaScript
/**
|
|
* Tests that MongoDB gives errors when certain data files are missing.
|
|
*
|
|
* @tags: [requires_wiredtiger]
|
|
*/
|
|
|
|
(function() {
|
|
|
|
load('jstests/disk/libs/wt_file_helper.js');
|
|
|
|
const baseName = "wt_missing_file_errors";
|
|
const collName = "test";
|
|
const dbpath = MongoRunner.dataPath + baseName + "/";
|
|
|
|
/**
|
|
* Test 1. Delete a collection's .wt file.
|
|
*/
|
|
|
|
assertErrorOnRequestWhenFilesAreCorruptOrMissing(
|
|
dbpath,
|
|
baseName,
|
|
collName,
|
|
(mongod, testColl) => {
|
|
const testCollUri = getUriForColl(testColl);
|
|
const testCollFile = dbpath + testCollUri + ".wt";
|
|
MongoRunner.stopMongod(mongod);
|
|
jsTestLog("deleting collection file: " + testCollFile);
|
|
removeFile(testCollFile);
|
|
},
|
|
(testColl) => {
|
|
assert.throws(() => {
|
|
testColl.insert({a: 1});
|
|
});
|
|
},
|
|
new RegExp("Fatal assertion.*50883"));
|
|
|
|
/**
|
|
* Test 2. Delete the _mdb_catalog.
|
|
*/
|
|
|
|
assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
|
|
MongoRunner.stopMongod(mongod);
|
|
let mdbCatalogFile = dbpath + "_mdb_catalog.wt";
|
|
jsTestLog("deleting catalog file: " + mdbCatalogFile);
|
|
removeFile(mdbCatalogFile);
|
|
}, new RegExp("Fatal assertion.*50883"));
|
|
|
|
/**
|
|
* Test 3. Delete the WiredTiger.wt.
|
|
*/
|
|
|
|
assertErrorOnStartupWhenFilesAreCorruptOrMissing(dbpath, baseName, collName, (mongod, testColl) => {
|
|
MongoRunner.stopMongod(mongod);
|
|
let WiredTigerWTFile = dbpath + "WiredTiger.wt";
|
|
jsTestLog("deleting WiredTiger.wt");
|
|
removeFile(WiredTigerWTFile);
|
|
}, new RegExp("Fatal assertion.*50944"));
|
|
|
|
/**
|
|
* 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});
|
|
});
|
|
},
|
|
new RegExp("Fatal assertion.*50883"));
|
|
})();
|