1
0
Fork 0

fix `--database.check-version`

This commit is contained in:
jsteemann 2018-07-18 12:18:42 +02:00
parent 1ed2ac27ad
commit f60fe97b28
3 changed files with 104 additions and 8 deletions

View File

@ -22,6 +22,7 @@
#include "CheckVersionFeature.h"
#include "Basics/FileUtils.h"
#include "Basics/exitcodes.h"
#include "Logger/Logger.h"
#include "Logger/LoggerFeature.h"
@ -29,6 +30,7 @@
#include "ProgramOptions/Section.h"
#include "Replication/ReplicationFeature.h"
#include "RestServer/DatabaseFeature.h"
#include "RestServer/DatabasePathFeature.h"
#include "VocBase/Methods/Version.h"
#include "VocBase/vocbase.h"
@ -48,7 +50,9 @@ CheckVersionFeature::CheckVersionFeature(
startsAfter("BasicsPhase");
startsAfter("Database");
startsAfter("DatabasePath");
startsAfter("EngineSelector");
startsAfter("ServerId");
}
void CheckVersionFeature::collectOptions(
@ -68,6 +72,10 @@ void CheckVersionFeature::validateOptions(
return;
}
// hard-code our role to a single server instance, because
// noone else will set our role
ServerState::instance()->setRole(ServerState::ROLE_SINGLE);
ApplicationServer::forceDisableFeatures(_nonServerFeatures);
LoggerFeature* logger =
@ -90,6 +98,7 @@ void CheckVersionFeature::start() {
// check the version
if (DatabaseFeature::DATABASE->isInitiallyEmpty()) {
LOG_TOPIC(TRACE, arangodb::Logger::STARTUP) << "skipping version check because database directory was initially empty";
*_result = EXIT_SUCCESS;
} else {
checkVersion();
@ -98,7 +107,7 @@ void CheckVersionFeature::start() {
// and force shutdown
server()->beginShutdown();
std::this_thread::sleep_for(std::chrono::microseconds(1 * 1000 * 1000));
std::this_thread::sleep_for(std::chrono::seconds(1));
TRI_EXIT_FUNCTION(EXIT_SUCCESS, nullptr);
}
@ -106,7 +115,14 @@ void CheckVersionFeature::checkVersion() {
*_result = 1;
// run version check
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << "starting version check";
LOG_TOPIC(TRACE, arangodb::Logger::STARTUP) << "starting version check";
DatabasePathFeature* databasePathFeature =
application_features::ApplicationServer::getFeature<DatabasePathFeature>(
"DatabasePath");
LOG_TOPIC(TRACE, arangodb::Logger::STARTUP) << "database path is: '" << databasePathFeature->directory() << "'";
// can do this without a lock as this is the startup
DatabaseFeature* databaseFeature =
application_features::ApplicationServer::getFeature<DatabaseFeature>(
@ -146,7 +162,7 @@ void CheckVersionFeature::checkVersion() {
if (res.status < 0) {
LOG_TOPIC(FATAL, arangodb::Logger::FIXME)
<< "Database version check failed for '" << vocbase->name()
<< "'. Please inspect the logs for any errors";
<< "'. Please inspect the logs for any errors. If there are no obvious issues in the logs, please retry with option `--log.level startup=trace`";
FATAL_ERROR_EXIT_CODE(TRI_EXIT_VERSION_CHECK_FAILED);
} else if (res.status == methods::VersionResult::DOWNGRADE_NEEDED) {
// this is safe to do even if further databases will be checked

View File

@ -139,11 +139,11 @@ static int runServer(int argc, char** argv, ArangoGlobalContext &context) {
std::vector<std::string> nonServerFeatures = {
"Action", "Agency",
"Cluster", "Daemon",
"EngineEqualityCheck", "FoxxQueues",
"GeneralServer", "Greetings",
"LoggerBufferFeature", "Server",
"SslServer", "Statistics",
"Supervisor"};
"Endpoint", "EngineEqualityCheck",
"FoxxQueues", "GeneralServer",
"Greetings", "LoggerBufferFeature",
"Server", "SslServer",
"Statistics", "Supervisor"};
int ret = EXIT_FAILURE;

View File

@ -0,0 +1,80 @@
/* jshint strict: false, sub: true */
/* global print */
'use strict';
// //////////////////////////////////////////////////////////////////////////////
// / DISCLAIMER
// /
// / Copyright 2016 ArangoDB GmbH, Cologne, Germany
// / Copyright 2014 triagens GmbH, Cologne, Germany
// /
// / Licensed under the Apache License, Version 2.0 (the "License")
// / you may not use this file except in compliance with the License.
// / You may obtain a copy of the License at
// /
// / http://www.apache.org/licenses/LICENSE-2.0
// /
// / Unless required by applicable law or agreed to in writing, software
// / distributed under the License is distributed on an "AS IS" BASIS,
// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// / See the License for the specific language governing permissions and
// / limitations under the License.
// /
// / Copyright holder is ArangoDB GmbH, Cologne, Germany
// /
// / @author Jan Steemann
// //////////////////////////////////////////////////////////////////////////////
const functionsDocumentation = {
'version': 'version check test'
};
const fs = require('fs');
const pu = require('@arangodb/process-utils');
const testPaths = {
'version': []
};
// //////////////////////////////////////////////////////////////////////////////
// / @brief TEST: version
// //////////////////////////////////////////////////////////////////////////////
function version(options) {
// create empty data directory
const dataDir = fs.join(fs.getTempPath(), 'version');
// use same configuration as dfdb, works here.
const args = ['-c', fs.join(pu.CONFIG_DIR, 'arango-dfdb.conf'), dataDir];
if (options.storageEngine !== undefined) {
args.push('--server.storage-engine');
args.push(options.storageEngine);
}
args.push('--database.check-version');
args.push('true');
args.push('--server.rest-server');
args.push('false');
fs.makeDirectoryRecursive(dataDir);
pu.cleanupDBDirectoriesAppend(dataDir);
let results = { failed: 0 };
results.version = pu.executeAndWait(pu.ARANGOD_BIN, args, options, 'version', dataDir, false, options.coreCheck);
print();
results.version.failed = results.version.status ? 0 : 1;
if (!results.version.status) {
results.failed += 1;
}
return results;
}
exports.setup = function (testFns, defaultFns, opts, fnDocs, optionsDoc, allTestPaths) {
Object.assign(allTestPaths, testPaths);
testFns['version'] = version;
defaultFns.push('version');
for (var attrname in functionsDocumentation) { fnDocs[attrname] = functionsDocumentation[attrname]; }
};