diff options
Diffstat (limited to 'searchcorespi/src')
14 files changed, 0 insertions, 460 deletions
diff --git a/searchcorespi/src/tests/plugin/.gitignore b/searchcorespi/src/tests/plugin/.gitignore deleted file mode 100644 index e49000038ad..00000000000 --- a/searchcorespi/src/tests/plugin/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -Makefile -.depend -*_test -searchcorespi_factoryregistry_test_app -searchcorespi_plugin_test_app diff --git a/searchcorespi/src/tests/plugin/CMakeLists.txt b/searchcorespi/src/tests/plugin/CMakeLists.txt deleted file mode 100644 index da785b09b6a..00000000000 --- a/searchcorespi/src/tests/plugin/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_library(searchcorespi_tplugin - SOURCES - plugin.cpp - DEPENDS - searchcorespi -) -vespa_add_library(searchcorespi_illegal-plugin - SOURCES - empty.cpp - DEPENDS - searchcorespi -) -vespa_add_executable(searchcorespi_plugin_test_app TEST - SOURCES - plugin_test.cpp - DEPENDS - searchcorespi -) -vespa_add_test( - NAME searchcorespi_plugin_test_app - COMMAND searchcorespi_plugin_test_app - ENVIRONMENT "LD_LIBRARY_PATH=." - DEPENDS searchcorespi_tplugin searchcorespi_illegal-plugin -) -vespa_add_executable(searchcorespi_factoryregistry_test_app TEST - SOURCES - factoryregistry_test.cpp - DEPENDS - searchcorespi -) -vespa_add_test(NAME searchcorespi_factoryregistry_test_app COMMAND searchcorespi_factoryregistry_test_app) diff --git a/searchcorespi/src/tests/plugin/empty.cpp b/searchcorespi/src/tests/plugin/empty.cpp deleted file mode 100644 index c7c47fc98c5..00000000000 --- a/searchcorespi/src/tests/plugin/empty.cpp +++ /dev/null @@ -1 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. diff --git a/searchcorespi/src/tests/plugin/factoryregistry_test.cpp b/searchcorespi/src/tests/plugin/factoryregistry_test.cpp deleted file mode 100644 index 10a1c95f191..00000000000 --- a/searchcorespi/src/tests/plugin/factoryregistry_test.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/searchcorespi/plugin/factoryregistry.h> -#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h> -#include <vespa/vespalib/stllike/string.h> -#include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/util/exceptions.h> - -using vespalib::string; -using namespace searchcorespi; - -namespace { - -struct MyFactory : IIndexManagerFactory { - - virtual IIndexManager::UP createIndexManager(const IndexManagerConfig &, - const index::IndexMaintainerConfig &, - const index::IndexMaintainerContext &) override { - return IIndexManager::UP(); - } - virtual config::ConfigKeySet getConfigKeys( - const string &, - const search::index::Schema &, - const config::ConfigInstance &) override { - return config::ConfigKeySet(); - } -}; - -const string name = "factory"; - -TEST("require that factories can be added and removed") { - FactoryRegistry registry; - EXPECT_FALSE(registry.isRegistered(name)); - registry.add(name, IIndexManagerFactory::SP(new MyFactory)); - EXPECT_TRUE(registry.get(name).get()); - EXPECT_TRUE(registry.isRegistered(name)); - registry.remove(name); - EXPECT_EXCEPTION(registry.get(name), vespalib::IllegalArgumentException, - "No factory is registered with the name"); -} - -TEST("require that two factories with the same name cannot be added") { - FactoryRegistry registry; - registry.add(name, IIndexManagerFactory::SP(new MyFactory)); - EXPECT_EXCEPTION( - registry.add(name, IIndexManagerFactory::SP(new MyFactory)), - vespalib::IllegalArgumentException, - "A factory is already registered with the same name"); -} - -TEST("require that a non-existent factory cannot be removed") { - FactoryRegistry registry; - EXPECT_EXCEPTION(registry.remove(name), vespalib::IllegalArgumentException, - "No factory is registered with the name"); -} - -} // namespace - -TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchcorespi/src/tests/plugin/plugin.cpp b/searchcorespi/src/tests/plugin/plugin.cpp deleted file mode 100644 index d32b02f45fd..00000000000 --- a/searchcorespi/src/tests/plugin/plugin.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h> - -using namespace search; -using namespace search::index; -using namespace vespalib; -using namespace config; - -namespace searchcorespi { -class IndexManager : public searchcorespi::IIndexManager -{ -public: - - typedef search::SerialNum SerialNum; - typedef search::index::Schema Schema; - typedef document::Document Document; - using OnWriteDoneType = - const std::shared_ptr<search::IDestructorCallback> &; - virtual void putDocument(uint32_t, const Document &, SerialNum) override { } - virtual void removeDocument(uint32_t, SerialNum) override { } - virtual void commit(SerialNum, OnWriteDoneType) override { } - virtual void heartBeat(SerialNum ) override {} - void compactLidSpace(uint32_t, SerialNum) override {} - virtual SerialNum getCurrentSerialNum() const override { return 0; } - virtual SerialNum getFlushedSerialNum() const override { return 0; } - virtual IndexSearchable::SP getSearchable() const override { - IndexSearchable::SP s; - return s; - } - virtual SearchableStats getSearchableStats() const override { - SearchableStats s; - return s; - } - virtual searchcorespi::IFlushTarget::List getFlushTargets() override { - searchcorespi::IFlushTarget::List l; - return l; - } - virtual void setSchema(const Schema &, SerialNum) override { } - virtual void setMaxFlushed(uint32_t) override { } -}; - -class IndexManagerFactory : public searchcorespi::IIndexManagerFactory -{ -public: - virtual IIndexManager::UP createIndexManager(const IndexManagerConfig &managerCfg, - const index::IndexMaintainerConfig &maintainerConfig, - const index::IndexMaintainerContext &maintainerContext) override; - - virtual ConfigKeySet getConfigKeys(const string &configId, - const Schema &schema, - const ConfigInstance &rootConfig) override; -}; - -IIndexManager::UP -IndexManagerFactory::createIndexManager(const IndexManagerConfig &, - const index::IndexMaintainerConfig &, - const index::IndexMaintainerContext &) -{ - return IIndexManager::UP(new IndexManager()); -} - -ConfigKeySet -IndexManagerFactory::getConfigKeys(const string &, - const Schema &, - const ConfigInstance &) -{ - ConfigKeySet keys; - return keys; -} - -} - -searchcorespi::IIndexManagerFactory * -createIndexManagerFactory() -{ - return new searchcorespi::IndexManagerFactory(); -} - diff --git a/searchcorespi/src/tests/plugin/plugin_test.cpp b/searchcorespi/src/tests/plugin/plugin_test.cpp deleted file mode 100644 index 733c2834c24..00000000000 --- a/searchcorespi/src/tests/plugin/plugin_test.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/vespalib/testkit/testapp.h> -#include <vespa/searchcorespi/plugin/factoryloader.h> -#include <vespa/vespalib/util/exceptions.h> - -using namespace searchcorespi; - -namespace { -TEST("require that plugins can be loaded.") { - FactoryLoader fl; - IIndexManagerFactory::UP f = fl.create("searchcorespi_tplugin"); - ASSERT_TRUE(f.get()); -} - -TEST("require that non-existent plugin causes failure") { - FactoryLoader fl; -#ifdef __APPLE__ - EXPECT_EXCEPTION(fl.create("no-such-plugin"), - vespalib::IllegalArgumentException, - "image not found"); -#else - EXPECT_EXCEPTION(fl.create("no-such-plugin"), - vespalib::IllegalArgumentException, - "cannot open shared object file"); -#endif -} - -TEST("require that missing factory function causes failure") { - FactoryLoader fl; - EXPECT_EXCEPTION(fl.create("searchcorespi_illegal-plugin"), - vespalib::IllegalArgumentException, - "Failed locating symbol 'createIndexManagerFactory'"); -} -} // namespace - -TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchcorespi/src/vespa/searchcorespi/CMakeLists.txt b/searchcorespi/src/vespa/searchcorespi/CMakeLists.txt index 3cbe1265136..bee83a7f936 100644 --- a/searchcorespi/src/vespa/searchcorespi/CMakeLists.txt +++ b/searchcorespi/src/vespa/searchcorespi/CMakeLists.txt @@ -3,7 +3,6 @@ vespa_add_library(searchcorespi SOURCES $<TARGET_OBJECTS:searchcorespi_flush> $<TARGET_OBJECTS:searchcorespi_index> - $<TARGET_OBJECTS:searchcorespi_plugin> INSTALL lib64 DEPENDS ) diff --git a/searchcorespi/src/vespa/searchcorespi/plugin/.gitignore b/searchcorespi/src/vespa/searchcorespi/plugin/.gitignore deleted file mode 100644 index 7e7c0fe7fae..00000000000 --- a/searchcorespi/src/vespa/searchcorespi/plugin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/.depend -/Makefile diff --git a/searchcorespi/src/vespa/searchcorespi/plugin/CMakeLists.txt b/searchcorespi/src/vespa/searchcorespi/plugin/CMakeLists.txt deleted file mode 100644 index b564a593e4e..00000000000 --- a/searchcorespi/src/vespa/searchcorespi/plugin/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_library(searchcorespi_plugin OBJECT - SOURCES - factoryregistry.cpp - factoryloader.cpp - DEPENDS -) diff --git a/searchcorespi/src/vespa/searchcorespi/plugin/factoryloader.cpp b/searchcorespi/src/vespa/searchcorespi/plugin/factoryloader.cpp deleted file mode 100644 index ba2b0b962f6..00000000000 --- a/searchcorespi/src/vespa/searchcorespi/plugin/factoryloader.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "factoryloader.h" -#include <vespa/vespalib/util/exceptions.h> - -using vespalib::stringref; -using vespalib::make_string; -using vespalib::IllegalArgumentException; - -namespace searchcorespi { - -FactoryLoader::FactoryLoader() : - _libraries() -{ -} - -FactoryLoader::~FactoryLoader() = default; - -IIndexManagerFactory::UP -FactoryLoader::create(stringref factory) -{ - typedef IIndexManagerFactory* (*FuncT)(); - _libraries.loadLibrary(factory); - const FastOS_DynamicLibrary & lib = *_libraries.get(factory); - FuncT registrationMethod = reinterpret_cast<FuncT>(lib.GetSymbol("createIndexManagerFactory")); - if (registrationMethod == nullptr) { - throw IllegalArgumentException(make_string("Failed locating symbol 'createIndexManagerFactory' in library '%s' for factory '%s'.", - lib.GetLibName(), vespalib::string(factory).c_str())); - } - return IIndexManagerFactory::UP(registrationMethod()); -} - -} diff --git a/searchcorespi/src/vespa/searchcorespi/plugin/factoryloader.h b/searchcorespi/src/vespa/searchcorespi/plugin/factoryloader.h deleted file mode 100644 index 3eda6557fa0..00000000000 --- a/searchcorespi/src/vespa/searchcorespi/plugin/factoryloader.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h> -#include <vespa/vespalib/util/librarypool.h> - -namespace searchcorespi { - -class FactoryLoader -{ -public: - FactoryLoader(); - ~FactoryLoader(); - /** - * Will load the library containing the factory. It will then locate the 'createIndexManagerFactory' - * symbol and run it to create the factory. - * @param the name of the library. Like 'vesparise'. - * @return the factory that is created. - */ - IIndexManagerFactory::UP create(vespalib::stringref factory); -private: - vespalib::LibraryPool _libraries; -}; - -} // namespace searchcorespi - diff --git a/searchcorespi/src/vespa/searchcorespi/plugin/factoryregistry.cpp b/searchcorespi/src/vespa/searchcorespi/plugin/factoryregistry.cpp deleted file mode 100644 index bd1b914cf39..00000000000 --- a/searchcorespi/src/vespa/searchcorespi/plugin/factoryregistry.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/searchcorespi/plugin/factoryregistry.h> -#include <vespa/vespalib/util/exceptions.h> - -using vespalib::LockGuard; -using vespalib::IllegalArgumentException; -using vespalib::stringref; -using vespalib::string; - -namespace searchcorespi { - -FactoryRegistry::FactoryRegistry() = default; - -FactoryRegistry::~FactoryRegistry() = default; - -void FactoryRegistry::add(stringref uniqueName, const IIndexManagerFactory::SP & factory) -{ - LockGuard guard(_lock); - if (_registry.find(uniqueName) == _registry.end()) { - _registry[uniqueName] = factory; - } else { - throw IllegalArgumentException("A factory is already registered with the same name as '" + uniqueName + "'.", VESPA_STRLOC); - } -} - -void FactoryRegistry::remove(stringref uniqueName) -{ - LockGuard guard(_lock); - if (_registry.find(uniqueName) == _registry.end()) { - throw IllegalArgumentException("No factory is registered with the name of '" + uniqueName + "'.", VESPA_STRLOC); - } - _registry.erase(uniqueName); -} - -const IIndexManagerFactory::SP & -FactoryRegistry::get(stringref uniqueName) const -{ - LockGuard guard(_lock); - Registry::const_iterator found = _registry.find(uniqueName); - if (found == _registry.end()) { - throw IllegalArgumentException("No factory is registered with the name of '" + uniqueName + "'.", VESPA_STRLOC); - } - return found->second; -} - -bool -FactoryRegistry::isRegistered(vespalib::stringref uniqueName) const -{ - LockGuard guard(_lock); - Registry::const_iterator found = _registry.find(uniqueName); - return found != _registry.end(); -} - -} diff --git a/searchcorespi/src/vespa/searchcorespi/plugin/factoryregistry.h b/searchcorespi/src/vespa/searchcorespi/plugin/factoryregistry.h deleted file mode 100644 index feb27d62950..00000000000 --- a/searchcorespi/src/vespa/searchcorespi/plugin/factoryregistry.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h> - -namespace searchcorespi { - -/** - */ -class FactoryRegistry -{ -public: - FactoryRegistry(); - ~FactoryRegistry(); - /** - * This will register the plugged in factory under its official - * name. The plugin should call this method when it is loaded. E.g. - * by using either '__attribute__((constructor))' or using a - * global static object that will use its constructor to register - * the factory. - * @param uniqueName This is a name that is unique over all IndexManager factories. - * @param factory The factory instance for producing IndexManagers. - * @throws vespalib::IllegalArgument if factory is already registered. - */ - void add(vespalib::stringref uniqueName, const IIndexManagerFactory::SP & factory); - /** - * Will unregister a factory. Should be called when a sharedlibrary is being unloaded. - * @param uniqueName Unique name of factory to remove from registry. - * @throws vespalib::IllegalArgument if factory is already registered. - */ - void remove(vespalib::stringref uniqueName); - /** - * This method will fetch a factory given its unique name. - * @param name The name of the factory to return. - * @return The factory. - */ - const IIndexManagerFactory::SP & get(vespalib::stringref uniqueName) const; - /** - * Returns true if a factory with the given name has been registered. - */ - bool isRegistered(vespalib::stringref uniqueName) const; - -private: - typedef std::map<vespalib::string, IIndexManagerFactory::SP> Registry; - Registry _registry; - vespalib::Lock _lock; -}; - -} // namespace searchcorespi - diff --git a/searchcorespi/src/vespa/searchcorespi/plugin/iindexmanagerfactory.h b/searchcorespi/src/vespa/searchcorespi/plugin/iindexmanagerfactory.h deleted file mode 100644 index c2eddc15cde..00000000000 --- a/searchcorespi/src/vespa/searchcorespi/plugin/iindexmanagerfactory.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include <vespa/searchcorespi/index/iindexmanager.h> -#include <vespa/searchcorespi/index/indexmaintainerconfig.h> -#include <vespa/searchcorespi/index/indexmaintainercontext.h> -#include <vespa/searchcorespi/index/indexmanagerconfig.h> -#include <vespa/config/configgen/configinstance.h> -#include <vespa/config/retriever/configsnapshot.h> -#include <vespa/config/retriever/configkeyset.h> - -namespace searchcorespi { - -/** - * Interface for an index manager factory. Every provider of an index manager is supposed to provide a - * factory for producing them. It is given the basedir, the schema and a collection of configs. - * The factory implementation must pick the config it needs and return an IIndexManager instance. - * The factory is registered by using the registerFactory() method. - */ -class IIndexManagerFactory -{ -public: - typedef std::shared_ptr<IIndexManagerFactory> SP; - typedef std::unique_ptr<IIndexManagerFactory> UP; - - virtual ~IIndexManagerFactory() {} - - /** - * This method will be called by a document db when it needs to create an index manager that - * uses an index maintainer (with source selector) in its implementation. - * The factory implementation must use RTTI to figure out what configs are what. - * It should receive all configs it needs, but wise to do sanity checking. - * - * @param managerConfig The config that will be used to construct an index manager. - * Note that if the factory used a different config id when populating the - * ConfigKeySet compared to the one in this config instance, it must - * also override the config id when fetching from the config snapshot. - * The root config received in the @ref getConfigKeys() call will also be - * part of the config snapshot in this config instance. - * @param maintainerConfig The config needed to construct an index maintainer. - * @param maintainerContext The context object used by an index maintainer during its lifetime. - * @return The index manager created or NULL if not, fx if configs are not as expected. - */ - virtual IIndexManager::UP createIndexManager(const IndexManagerConfig &managerConfig, - const index::IndexMaintainerConfig &maintainerConfig, - const index::IndexMaintainerContext &maintainerContext) = 0; - - /** - * The factory must return the set of config keys that it will require the config from. - * This will facilitate that the searchcore can fetch all configs needed in a pluggable way. - * - * @param configId The config id to use when generating the config keys. - * @param schema This is the initial index schema to be used. - * @param rootConfig This is an config instance that is the root config for the factory. - * Based on this config it must be able to tell if it needs any other config, - * and in that case provide the config keys. - * @return The set containing keys for all configs required. - */ - virtual config::ConfigKeySet getConfigKeys(const vespalib::string &configId, - const search::index::Schema &schema, - const config::ConfigInstance &rootConfig) = 0; -}; - -} // namespace searchcorespi - -extern "C" { -/** - * This is a method that each shared library must have in order provide a factory. - * This will be called by the one loading the library. - * @return The created factory that the caller will take ownership of. - */ -searchcorespi::IIndexManagerFactory * createIndexManagerFactory(); - -} - - |