diff options
author | clang-format-7.0.1 <adam.martin@10gen.com> | 2019-07-26 18:20:35 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-07-27 11:02:23 -0400 |
commit | 134a4083953270e8a11430395357fb70a29047ad (patch) | |
tree | dd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /jstests/disk/wt_repair_corrupt_metadata.js | |
parent | 1e46b5049003f427047e723ea5fab15b5a9253ca (diff) | |
download | mongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz |
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'jstests/disk/wt_repair_corrupt_metadata.js')
-rw-r--r-- | jstests/disk/wt_repair_corrupt_metadata.js | 184 |
1 files changed, 92 insertions, 92 deletions
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: ""}); })(); |