diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index f9c93fede2..75878f825c 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -52,6 +52,7 @@ add_library(${LIB_ARANGO_IRESEARCH} IResearch/ApplicationServerHelper.h IResearch/ApplicationServerHelper.cpp IResearch/Containers.cpp IResearch/Containers.h IResearch/IResearchAnalyzerFeature.cpp IResearch/IResearchAnalyzerFeature.h + IResearch/IResearchAnalyzerCollectionFeature.cpp IResearch/IResearchCommon.cpp IResearch/IResearchCommon.h IResearch/IResearchKludge.cpp IResearch/IResearchKludge.h IResearch/IResearchLink.cpp IResearch/IResearchLink.h diff --git a/arangod/IResearch/IResearchAnalyzerCollectionFeature.cpp b/arangod/IResearch/IResearchAnalyzerCollectionFeature.cpp new file mode 100644 index 0000000000..9a0c0071a1 --- /dev/null +++ b/arangod/IResearch/IResearchAnalyzerCollectionFeature.cpp @@ -0,0 +1,68 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2017 ArangoDB 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 +//////////////////////////////////////////////////////////////////////////////// + +#include "ApplicationServerHelper.h" +#include "Basics/StaticStrings.h" +#include "Cluster/ServerState.h" +#include "IResearch/IResearchAnalyzerCollectionFeature.h" +#include "IResearch/IResearchCommon.h" +#include "Logger/Logger.h" +#include "RestServer/DatabaseFeature.h" +#include "VocBase/Methods/Collections.h" + +using namespace arangodb; + +IResearchAnalyzerCollectionFeature::IResearchAnalyzerCollectionFeature(application_features::ApplicationServer& server) + : ApplicationFeature(server, "ArangoSearchAnalyzerCollection") { + setOptional(true); + startsAfter("DatabasePhase"); + // should be relatively late in startup sequence + startsAfter("ClusterPhase"); + startsAfter("ServerPhase"); + startsAfter("Bootstrap"); +} + +void IResearchAnalyzerCollectionFeature::start() { + if (ServerState::instance()->isDBServer()) { + // no need to execute this in DB server + return; + } + + DatabaseFeature* databaseFeature = DatabaseFeature::DATABASE; + TRI_ASSERT(databaseFeature != nullptr); + + databaseFeature->enumerateDatabases([](TRI_vocbase_t& vocbase) { + Result res = methods::Collections::lookup(vocbase, StaticStrings::AnalyzersCollection, [](std::shared_ptr const&) { + }); + + if (res.is(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND)) { + // collection does not yet exist, so let's create it now + auto res = methods::Collections::createSystem(vocbase, StaticStrings::AnalyzersCollection, false); + if (res.first.ok()) { + LOG_TOPIC("c2e33", DEBUG, arangodb::iresearch::TOPIC) << "successfully created '" << StaticStrings::AnalyzersCollection << "' collection in database '" << vocbase.name() << "'"; + } else if (res.first.fail() && !res.first.is(TRI_ERROR_ARANGO_CONFLICT)) { + LOG_TOPIC("ecc23", WARN, arangodb::iresearch::TOPIC) << "unable to create '" << StaticStrings::AnalyzersCollection << "' collection: " << res.first.errorMessage(); + // don't abort startup here. the next startup may fix this + } + } + }); +} diff --git a/arangod/IResearch/IResearchAnalyzerCollectionFeature.h b/arangod/IResearch/IResearchAnalyzerCollectionFeature.h new file mode 100644 index 0000000000..572522b9da --- /dev/null +++ b/arangod/IResearch/IResearchAnalyzerCollectionFeature.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2017 ArangoDB 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 +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ARANGOD_IRESEARCH__IRESEARCH_ANALYZER_COLLECTION_FEATURE_H +#define ARANGOD_IRESEARCH__IRESEARCH_ANALYZER_COLLECTION_FEATURE_H 1 + +#include "ApplicationFeatures/ApplicationFeature.h" + +namespace arangodb { + +/// @brief the sole purpose of this feature is to create potentially +/// missing `_analyzers` collection after startup. It can be removed +/// eventually once the entire upgrading logic has been revised +class IResearchAnalyzerCollectionFeature final : public arangodb::application_features::ApplicationFeature { + public: + explicit IResearchAnalyzerCollectionFeature(arangodb::application_features::ApplicationServer& server); + + void start() override; +}; + +} // namespace arangodb + +#endif diff --git a/arangod/RestServer/arangod.cpp b/arangod/RestServer/arangod.cpp index 07534bd9c1..5409c51db6 100644 --- a/arangod/RestServer/arangod.cpp +++ b/arangod/RestServer/arangod.cpp @@ -116,6 +116,7 @@ #endif #include "IResearch/IResearchAnalyzerFeature.h" +#include "IResearch/IResearchAnalyzerCollectionFeature.h" #include "IResearch/IResearchFeature.h" // storage engines @@ -245,6 +246,7 @@ static int runServer(int argc, char** argv, ArangoGlobalContext& context) { server.addFeature(new arangodb::iresearch::IResearchAnalyzerFeature(server)); server.addFeature(new arangodb::iresearch::IResearchFeature(server)); + server.addFeature(new arangodb::IResearchAnalyzerCollectionFeature(server)); // storage engines server.addFeature(new ClusterEngine(server));