1
0
Fork 0

handle empty logfiles on startup

This commit is contained in:
Jan Steemann 2014-07-02 09:31:00 +02:00
parent ae8ae04cc8
commit 7fa01da9b4
3 changed files with 73 additions and 1 deletions

View File

@ -208,6 +208,7 @@ unittests-recovery:
@echo "================================================================================"
@echo
$(MAKE) execute-recovery-test PID=$(PID) RECOVERY_SCRIPT="empty-logfiles"
$(MAKE) execute-recovery-test PID=$(PID) RECOVERY_SCRIPT="many-logs"
$(MAKE) execute-recovery-test PID=$(PID) RECOVERY_SCRIPT="multiple-logs"
$(MAKE) execute-recovery-test PID=$(PID) RECOVERY_SCRIPT="collection-recreate"

View File

@ -131,7 +131,14 @@ Logfile* Logfile::openExisting (std::string const& filename,
////////////////////////////////////////////////////////////////////////////////
int Logfile::judge (std::string const& filename) {
if (basics::FileUtils::size(filename) < static_cast<off_t>(256 * sizeof(uint64_t))) {
off_t filesize = basics::FileUtils::size(filename);
if (filesize == 0) {
// empty logfile
return TRI_ERROR_ARANGO_DATAFILE_EMPTY;
}
if (filesize < static_cast<off_t>(256 * sizeof(uint64_t))) {
// too small
return TRI_ERROR_ARANGO_DATAFILE_UNREADABLE;
}

View File

@ -0,0 +1,64 @@
var db = require("org/arangodb").db;
var internal = require("internal");
var jsunity = require("jsunity");
var fs = require("fs");
function runSetup () {
internal.debugClearFailAt();
var i, num = 9999999999;
for (i = 0; i < 4; ++i) {
var filename = fs.join(db._path(), "../../journals/logfile-" + num + ".db");
num++;
// save an empty file
fs.write(filename, "");
}
db._drop("UnitTestsRecovery");
var c = db._create("UnitTestsRecovery");
c.save({ _key: "crashme" }, true); // wait for sync
internal.debugSegfault("crashing server");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite
////////////////////////////////////////////////////////////////////////////////
function recoverySuite () {
jsunity.jsUnity.attachAssertions();
return {
setUp: function () {
},
tearDown: function () {
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test whether we can start the server
////////////////////////////////////////////////////////////////////////////////
testEmptyLogfiles : function () {
// nothing to do - the server must start even in the face of empty logfiles
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suite
////////////////////////////////////////////////////////////////////////////////
function main (argv) {
if (argv[1] === "setup") {
runSetup();
return 0;
}
else {
jsunity.run(recoverySuite);
return jsunity.done() ? 0 : 1;
}
}