forked from mongodb/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SERVER-15111 Treat corruption of final journal section as an expected…
- Loading branch information
1 parent
e4a5649
commit e96f298
Showing
7 changed files
with
139 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Test checksum validation of journal files. | ||
|
||
var testname = "dur_checksum"; | ||
var path = MongoRunner.dataPath + testname; | ||
|
||
if (0) { | ||
// This is used to create the prototype journal file. | ||
jsTest.log("Just creating prototype journal, not testing anything"); | ||
var conn = startMongodEmpty("--port", 30001, "--dbpath", path, "--dur"); | ||
var db = conn.getDB("test"); | ||
|
||
// each insert is in it's own commit. | ||
db.foo.insert({a: 1}); | ||
db.runCommand({getlasterror:1, j:1}) | ||
|
||
db.foo.insert({a: 2}); | ||
db.runCommand({getlasterror:1, j:1}) | ||
|
||
stopMongod(30001, /*signal*/9); | ||
|
||
jsTest.log("Journal file left at " + path + "/journal/j._0"); | ||
quit(); | ||
// A hex editor must be used to replace the checksums of specific journal sections with | ||
// "0BADC0DE 1BADC0DE 2BADC0DE 3BADCD0E" | ||
} | ||
|
||
function startMongodWithJournal() { | ||
return startMongodNoReset("--port", 30001, | ||
"--dbpath", path, | ||
"--dur", | ||
"--smallfiles", | ||
"--durOptions", 1 /*DurDumpJournal*/); | ||
} | ||
|
||
|
||
jsTest.log("Starting with good.journal to make sure everything works"); | ||
resetDbpath(path); | ||
mkdir(path + '/journal'); | ||
copyFile("jstests/libs/dur_checksum_good.journal", path + "/journal/j._0"); | ||
var conn = startMongodWithJournal(); | ||
var db = conn.getDB('test'); | ||
assert.eq(db.foo.count(), 2); | ||
stopMongod(30001); | ||
|
||
|
||
// dur_checksum_bad_last.journal is good.journal with the bad checksum on the last section. | ||
jsTest.log("Starting with bad_last.journal"); | ||
resetDbpath(path); | ||
mkdir(path + '/journal'); | ||
copyFile("jstests/libs/dur_checksum_bad_last.journal", path + "/journal/j._0"); | ||
conn = startMongodWithJournal(); | ||
var db = conn.getDB('test'); | ||
assert.eq(db.foo.count(), 1); // 2nd insert "never happened" | ||
stopMongod(30001); | ||
|
||
|
||
// dur_checksum_bad_first.journal is good.journal with the bad checksum on the prior section. | ||
// This means there is a good commit after the bad one. We currently ignore this, but a future | ||
// version of the server may be able to detect this case. | ||
jsTest.log("Starting with bad_first.journal"); | ||
resetDbpath(path); | ||
mkdir(path + '/journal'); | ||
copyFile("jstests/libs/dur_checksum_bad_first.journal", path + "/journal/j._0"); | ||
conn = startMongodWithJournal(); | ||
var db = conn.getDB('test'); | ||
assert.eq(db.foo.count(), 0); // Neither insert happened. | ||
stopMongod(30001); | ||
|
||
// If we detect an error in a non-final journal file, that is considered an error. | ||
jsTest.log("Starting with bad_last.journal followed by good.journal"); | ||
resetDbpath(path); | ||
mkdir(path + '/journal'); | ||
copyFile("jstests/libs/dur_checksum_bad_first.journal", path + "/journal/j._0"); | ||
copyFile("jstests/libs/dur_checksum_good.journal", path + "/journal/j._1"); | ||
|
||
exitCode = runMongoProgram("mongod", | ||
"--port", 30001, | ||
"--dbpath", path, | ||
"--dur", | ||
"--smallfiles", | ||
"--durOptions", 1 /*DurDumpJournal*/ | ||
+ 2 /*DurScanOnly*/); | ||
|
||
assert.eq(exitCode, 100 /*EXIT_UNCAUGHT*/); | ||
|
||
// TODO Possibly we could check the mongod log to verify that the correct type of exception was | ||
// thrown. But that would introduce a dependency on the mongod log format, which we may not want. | ||
|
||
jsTest.log("SUCCESS checksum.js"); |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters