mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
2d2c7d0b9e
8 changed files with 66 additions and 17 deletions
|
@ -57,7 +57,7 @@ if ("${DINDEXER_CONFIG_FILE}" STREQUAL "")
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Config file set to \"${DINDEXER_CONFIG_FILE}\"")
|
message(STATUS "Config file set to \"${DINDEXER_CONFIG_FILE}\"")
|
||||||
|
|
||||||
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem)
|
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem system)
|
||||||
find_package(PostgreSQL 8.3 REQUIRED)
|
find_package(PostgreSQL 8.3 REQUIRED)
|
||||||
find_package(YamlCpp 0.5.1 REQUIRED)
|
find_package(YamlCpp 0.5.1 REQUIRED)
|
||||||
import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}" "-O3 ${march_flag}")
|
import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}" "-O3 ${march_flag}")
|
||||||
|
|
|
@ -7,3 +7,4 @@ postgresql_settings:
|
||||||
dbname: dindexer
|
dbname: dindexer
|
||||||
port: 5432
|
port: 5432
|
||||||
address: 200.100.200.100
|
address: 200.100.200.100
|
||||||
|
backend_paths: path to your build_dir/src/backend
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "helpers/compatibility.h"
|
#include "helpers/compatibility.h"
|
||||||
|
|
||||||
namespace dinlib {
|
namespace dinlib {
|
||||||
|
std::vector<boost::string_ref> split_and_trim ( const std::string& parList, char parSeparator ) a_pure;
|
||||||
std::vector<boost::string_ref> split_tags ( const std::string& parCommaSeparatedList ) a_pure;
|
std::vector<boost::string_ref> split_tags ( const std::string& parCommaSeparatedList ) a_pure;
|
||||||
} //namespace dinlib
|
} //namespace dinlib
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
project(${bare_name}-backend CXX)
|
project(${bare_name}-backend CXX)
|
||||||
|
|
||||||
|
set(BACKEND_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
function(ln_backend backend_name)
|
||||||
|
add_custom_command(TARGET "${backend_name}" POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:${backend_name}> ${BACKEND_BINARY_DIR}/$<TARGET_FILE_NAME:${backend_name}>
|
||||||
|
DEPENDS ${BACKEND_BINARY_DIR}/$<TARGET_FILE_NAME:${backend_name}>
|
||||||
|
COMMENT "Creating symlink to ${backend_name}"
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC
|
add_library(${PROJECT_NAME} STATIC
|
||||||
backend_loader.cpp
|
backend_loader.cpp
|
||||||
)
|
)
|
||||||
|
@ -26,6 +35,5 @@ target_link_libraries(${PROJECT_NAME}
|
||||||
|
|
||||||
add_subdirectory(postgresql)
|
add_subdirectory(postgresql)
|
||||||
add_subdirectory(redis)
|
add_subdirectory(redis)
|
||||||
|
|
||||||
add_dependencies(${PROJECT_NAME} ${bare_name}-backend-postgresql)
|
add_dependencies(${PROJECT_NAME} ${bare_name}-backend-postgresql)
|
||||||
add_dependencies(${PROJECT_NAME} ${bare_name}-backend-redis)
|
add_dependencies(${PROJECT_NAME} ${bare_name}-backend-redis)
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace dindb {
|
namespace dindb {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -34,9 +35,22 @@ namespace dindb {
|
||||||
assert(parSOHandle);
|
assert(parSOHandle);
|
||||||
assert(parConfig);
|
assert(parConfig);
|
||||||
|
|
||||||
auto create = reinterpret_cast<CreateBackendFun>(dlsym(parSOHandle, "dindexer_create_backend"));
|
const char* const fun_name_create = "dindexer_create_backend";
|
||||||
auto destroy = reinterpret_cast<DeleteBackendFun>(dlsym(parSOHandle, "dindexer_destroy_backend"));
|
const char* const fun_name_destroy = "dindexer_destroy_backend";
|
||||||
|
|
||||||
|
auto create = reinterpret_cast<CreateBackendFun>(dlsym(parSOHandle, fun_name_create));
|
||||||
|
auto destroy = reinterpret_cast<DeleteBackendFun>(dlsym(parSOHandle, fun_name_destroy));
|
||||||
|
|
||||||
|
if (not create) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Unable to find function " << fun_name_create;
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
if (not destroy) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Unable to find function " << fun_name_destroy;
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
return BackendPtr(create(parConfig), destroy);
|
return BackendPtr(create(parConfig), destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +79,10 @@ namespace dindb {
|
||||||
using SoHandle = std::unique_ptr<void, int(*)(void*)>;
|
using SoHandle = std::unique_ptr<void, int(*)(void*)>;
|
||||||
|
|
||||||
auto handle = SoHandle(dlopen(parSOPath.c_str(), RTLD_LAZY), &dlclose);
|
auto handle = SoHandle(dlopen(parSOPath.c_str(), RTLD_LAZY), &dlclose);
|
||||||
return backend_name(handle.get());
|
if (handle)
|
||||||
|
return backend_name(handle.get());
|
||||||
|
else
|
||||||
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendPlugin::BackendPlugin() :
|
BackendPlugin::BackendPlugin() :
|
||||||
|
|
|
@ -23,3 +23,4 @@ install(TARGETS ${PROJECT_NAME}
|
||||||
RUNTIME DESTINATION bin
|
RUNTIME DESTINATION bin
|
||||||
ARCHIVE DESTINATION lib/static
|
ARCHIVE DESTINATION lib/static
|
||||||
)
|
)
|
||||||
|
ln_backend(${PROJECT_NAME})
|
||||||
|
|
|
@ -16,33 +16,40 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dindexer-common/settings.hpp"
|
#include "dindexer-common/settings.hpp"
|
||||||
|
#include "dindexer-common/split_tags.hpp"
|
||||||
#include "dindexerConfig.h"
|
#include "dindexerConfig.h"
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/range/iterator_range_core.hpp>
|
||||||
|
|
||||||
namespace dinlib {
|
namespace dinlib {
|
||||||
namespace {
|
namespace {
|
||||||
std::string expand ( const char* parString );
|
std::string expand ( const char* parString );
|
||||||
std::string find_plugin_by_name ( const std::string& parName );
|
std::string find_plugin_by_name ( const std::vector<boost::string_ref>& parSearchPaths, const std::string& parName );
|
||||||
void throw_if_plugin_failed ( const dindb::BackendPlugin& parPlugin, const std::string& parPluginPath, const std::string& parIntendedName );
|
void throw_if_plugin_failed ( const dindb::BackendPlugin& parPlugin, const std::string& parPluginPath, const std::string& parIntendedName );
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
void load_settings (const std::string& parPath, dinlib::Settings& parOut, bool parExpand) {
|
void load_settings (const std::string& parPath, dinlib::Settings& parOut, bool parExpand) {
|
||||||
const std::string path = (parExpand ? expand(parPath.c_str()) : parPath);
|
const std::string path = (parExpand ? expand(parPath.c_str()) : parPath);
|
||||||
|
std::string search_paths;
|
||||||
|
|
||||||
auto settings = YAML::LoadFile(path);
|
auto settings = YAML::LoadFile(path);
|
||||||
|
|
||||||
if (not settings["backend_name"]) {
|
if (not settings["backend_name"])
|
||||||
throw std::runtime_error("No backend_name given in the config file");
|
throw std::runtime_error("No backend_name given in the config file");
|
||||||
}
|
if (settings["backend_paths"])
|
||||||
|
search_paths += ":" + settings["backend_paths"].as<std::string>();
|
||||||
parOut.backend_name = settings["backend_name"].as<std::string>();
|
parOut.backend_name = settings["backend_name"].as<std::string>();
|
||||||
const std::string backend_settings_section = parOut.backend_name + "_settings";
|
const std::string backend_settings_section = parOut.backend_name + "_settings";
|
||||||
if (settings[backend_settings_section]) {
|
if (settings[backend_settings_section]) {
|
||||||
auto settings_node = settings[backend_settings_section];
|
auto settings_node = settings[backend_settings_section];
|
||||||
const std::string plugin_path = find_plugin_by_name(parOut.backend_name);
|
const std::string plugin_path = find_plugin_by_name(split_and_trim(search_paths, ':'), parOut.backend_name);
|
||||||
|
if (plugin_path.empty())
|
||||||
|
throw std::runtime_error(std::string("Unable to find any suitable plugin with the specified name \"") + parOut.backend_name + "\"");
|
||||||
parOut.backend_plugin = dindb::BackendPlugin(plugin_path, &settings_node);
|
parOut.backend_plugin = dindb::BackendPlugin(plugin_path, &settings_node);
|
||||||
throw_if_plugin_failed(parOut.backend_plugin, plugin_path, parOut.backend_name);
|
throw_if_plugin_failed(parOut.backend_plugin, plugin_path, parOut.backend_name);
|
||||||
}
|
}
|
||||||
|
@ -61,14 +68,24 @@ namespace dinlib {
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_plugin_by_name (const std::string& parName) {
|
std::string find_plugin_by_name (const std::vector<boost::string_ref>& parSearchPaths, const std::string& parName) {
|
||||||
//assert(false); //not implemented
|
using boost::filesystem::path;
|
||||||
//TODO: write a proper implementation
|
using boost::filesystem::is_directory;
|
||||||
std::string path = ACTIONS_SEARCH_PATH;
|
using boost::filesystem::directory_iterator;
|
||||||
path += "/backends/postgresql/libdindexer-backend-postgresql.so";
|
using boost::filesystem::directory_entry;
|
||||||
|
using boost::make_iterator_range;
|
||||||
|
|
||||||
assert(dindb::backend_name(path) == parName);
|
for (auto search_path : parSearchPaths) {
|
||||||
return path;
|
const std::string search_path_cpy(search_path.begin(), search_path.end());
|
||||||
|
path curr_path(search_path_cpy);
|
||||||
|
auto listing = make_iterator_range(directory_iterator(curr_path), directory_iterator());
|
||||||
|
for (const directory_entry& entry : listing) {
|
||||||
|
auto current_full_path = entry.path().string();
|
||||||
|
if (not is_directory(entry) and dindb::backend_name(current_full_path) == parName)
|
||||||
|
return current_full_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void throw_if_plugin_failed (const dindb::BackendPlugin& parPlugin, const std::string& parPluginPath, const std::string& parIntendedName) {
|
void throw_if_plugin_failed (const dindb::BackendPlugin& parPlugin, const std::string& parPluginPath, const std::string& parIntendedName) {
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
|
|
||||||
namespace dinlib {
|
namespace dinlib {
|
||||||
std::vector<boost::string_ref> split_tags (const std::string& parCommaSeparatedList) {
|
std::vector<boost::string_ref> split_tags (const std::string& parCommaSeparatedList) {
|
||||||
|
return split_and_trim(parCommaSeparatedList, ',');
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<boost::string_ref> split_and_trim (const std::string& parList, char parSeparator) {
|
||||||
using OutRange = boost::iterator_range<std::string::const_iterator>;
|
using OutRange = boost::iterator_range<std::string::const_iterator>;
|
||||||
using boost::token_finder;
|
using boost::token_finder;
|
||||||
using boost::adaptors::transformed;
|
using boost::adaptors::transformed;
|
||||||
|
@ -42,7 +46,7 @@ namespace dinlib {
|
||||||
//http://www.boost.org/doc/libs/1_60_0/doc/html/boost/algorithm/token_finder.html
|
//http://www.boost.org/doc/libs/1_60_0/doc/html/boost/algorithm/token_finder.html
|
||||||
//https://stackoverflow.com/questions/20781090/difference-between-boostsplit-vs-boostiter-split
|
//https://stackoverflow.com/questions/20781090/difference-between-boostsplit-vs-boostiter-split
|
||||||
return boost::copy_range<std::vector<string_ref>>(
|
return boost::copy_range<std::vector<string_ref>>(
|
||||||
iter_split(out_range, parCommaSeparatedList, token_finder([](char c){return ','==c;})) |
|
iter_split(out_range, parList, token_finder([parSeparator](char c){return parSeparator==c;})) |
|
||||||
transformed([](const OutRange& r){return trim_copy(r);}) |
|
transformed([](const OutRange& r){return trim_copy(r);}) |
|
||||||
transformed([](const OutRange& r){return string_ref(&*r.begin(), r.size());}) |
|
transformed([](const OutRange& r){return string_ref(&*r.begin(), r.size());}) |
|
||||||
filtered([](const string_ref& r){return not r.empty();})
|
filtered([](const string_ref& r){return not r.empty();})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue