diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e914cfcd..5da1fa776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,7 @@ add_executable(osrm-extract src/tools/extract.cpp) add_executable(osrm-contract src/tools/contract.cpp) add_executable(osrm-routed src/tools/routed.cpp $ $) add_executable(osrm-datastore src/tools/store.cpp $) -add_library(osrm src/osrm/osrm.cpp $ $) +add_library(osrm src/osrm/osrm.cpp $ $ $) add_library(osrm_extract $ $) add_library(osrm_contract $ $) add_library(osrm_store $ $) diff --git a/example/example.cpp b/example/example.cpp index b2f1a1543..fe1de360a 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -29,7 +29,8 @@ int main(int argc, const char *argv[]) try using namespace osrm; // Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore - EngineConfig config{argv[1]}; + EngineConfig config; + config.storage_config = {argv[1]}; config.use_shared_memory = false; // Routing machine with several services (such as Route, Table, Nearest, Trip, Match) diff --git a/include/engine/datafacade/internal_datafacade.hpp b/include/engine/datafacade/internal_datafacade.hpp index 1189e7dd4..16ab0769c 100644 --- a/include/engine/datafacade/internal_datafacade.hpp +++ b/include/engine/datafacade/internal_datafacade.hpp @@ -228,31 +228,36 @@ class InternalDataFacade final : public BaseDataFacade } } - void LoadDatasourceInfo(const boost::filesystem::path &datasource_names_file, - const boost::filesystem::path &datasource_indexes_file) + void LoadDatasourceInfo(const std::string &datasource_names_file, + const std::string &datasource_indexes_file) { - std::ifstream datasources_stream(datasource_indexes_file.c_str(), std::ios::binary); - if (datasources_stream) + boost::filesystem::ifstream datasources_stream(datasource_indexes_file, std::ios::binary); + if (!datasources_stream) { - std::size_t number_of_datasources = 0; - datasources_stream.read(reinterpret_cast(&number_of_datasources), - sizeof(std::size_t)); - if (number_of_datasources > 0) - { - m_datasource_list.resize(number_of_datasources); - datasources_stream.read(reinterpret_cast(&(m_datasource_list[0])), - number_of_datasources * sizeof(uint8_t)); - } + throw util::exception("Could not open " + datasource_indexes_file + " for reading!"); + } + BOOST_ASSERT(datasources_stream); + + std::size_t number_of_datasources = 0; + datasources_stream.read(reinterpret_cast(&number_of_datasources), + sizeof(std::size_t)); + if (number_of_datasources > 0) + { + m_datasource_list.resize(number_of_datasources); + datasources_stream.read(reinterpret_cast(&(m_datasource_list[0])), + number_of_datasources * sizeof(uint8_t)); } - std::ifstream datasourcenames_stream(datasource_names_file.c_str(), std::ios::binary); - if (datasourcenames_stream) + boost::filesystem::ifstream datasourcenames_stream(datasource_names_file, std::ios::binary); + if (!datasourcenames_stream) { - std::string name; - while (std::getline(datasourcenames_stream, name)) - { - m_datasource_names.push_back(name); - } + throw util::exception("Could not open " + datasource_names_file + " for reading!"); + } + BOOST_ASSERT(datasourcenames_stream); + std::string name; + while (std::getline(datasourcenames_stream, name)) + { + m_datasource_names.push_back(name); } } @@ -289,55 +294,35 @@ class InternalDataFacade final : public BaseDataFacade m_geospatial_query.reset(); } - explicit InternalDataFacade( - const std::unordered_map &server_paths) + explicit InternalDataFacade(const storage::StorageConfig& config) { - // cache end iterator to quickly check .find against - const auto end_it = end(server_paths); - - const auto file_for = [&server_paths, &end_it](const std::string &path) - { - const auto it = server_paths.find(path); - if (it == end_it || !boost::filesystem::is_regular_file(it->second)) - throw util::exception("no valid " + path + " file given in ini file"); - return it->second; - }; - - const auto optional_file_for = [&server_paths, &end_it](const std::string &path) - { - const auto it = server_paths.find(path); - if (it == end_it) - throw util::exception("no valid " + path + " file given in ini file"); - return it->second; - }; - - ram_index_path = file_for("ramindex"); - file_index_path = file_for("fileindex"); + ram_index_path = config.ram_index_path; + file_index_path = config.file_index_path; util::SimpleLogger().Write() << "loading graph data"; - LoadGraph(file_for("hsgrdata")); + LoadGraph(config.hsgr_data_path); util::SimpleLogger().Write() << "loading edge information"; - LoadNodeAndEdgeInformation(file_for("nodesdata"), file_for("edgesdata")); + LoadNodeAndEdgeInformation(config.nodes_data_path, config.edges_data_path); util::SimpleLogger().Write() << "loading core information"; - LoadCoreInformation(file_for("coredata")); + LoadCoreInformation(config.core_data_path); util::SimpleLogger().Write() << "loading geometries"; - LoadGeometries(file_for("geometries")); + LoadGeometries(config.geometries_path); util::SimpleLogger().Write() << "loading datasource info"; - LoadDatasourceInfo(optional_file_for("datasource_names"), - optional_file_for("datasource_indexes")); + LoadDatasourceInfo(config.datasource_names_path, + config.datasource_indexes_path); util::SimpleLogger().Write() << "loading timestamp"; - LoadTimestamp(file_for("timestamp")); + LoadTimestamp(config.timestamp_path); util::SimpleLogger().Write() << "loading profile properties"; - LoadProfileProperties(file_for("properties")); + LoadProfileProperties(config.properties_path); util::SimpleLogger().Write() << "loading street names"; - LoadStreetNames(file_for("namesdata")); + LoadStreetNames(config.names_data_path); } // search graph access @@ -668,12 +653,8 @@ class InternalDataFacade final : public BaseDataFacade virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const override final { - if (m_datasource_names.empty() || datasource_name_id > m_datasource_names.size()) - { - if (datasource_name_id == 0) - return "lua profile"; - return "UNKNOWN"; - } + BOOST_ASSERT(m_datasource_names.size() >= 1); + BOOST_ASSERT(m_datasource_names.size() > datasource_name_id); return m_datasource_names[datasource_name_id]; } diff --git a/include/engine/datafacade/shared_datafacade.hpp b/include/engine/datafacade/shared_datafacade.hpp index 2d2611763..9e62e01ce 100644 --- a/include/engine/datafacade/shared_datafacade.hpp +++ b/include/engine/datafacade/shared_datafacade.hpp @@ -693,16 +693,10 @@ class SharedDataFacade final : public BaseDataFacade virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const override final { + BOOST_ASSERT(m_datasource_name_offsets.size() >= 1); + BOOST_ASSERT(m_datasource_name_offsets.size() > datasource_name_id); + std::string result; - - if (m_datasource_name_offsets.empty() || - datasource_name_id > m_datasource_name_offsets.size()) - { - if (datasource_name_id == 0) - return "lua profile"; - return "UNKNOWN"; - } - std::copy(m_datasource_name_data.begin() + m_datasource_name_offsets[datasource_name_id], m_datasource_name_data.begin() + m_datasource_name_offsets[datasource_name_id] + m_datasource_name_lengths[datasource_name_id], diff --git a/include/engine/engine_config.hpp b/include/engine/engine_config.hpp index 182ef805a..e17d2ef3e 100644 --- a/include/engine/engine_config.hpp +++ b/include/engine/engine_config.hpp @@ -28,9 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ENGINE_CONFIG_HPP #define ENGINE_CONFIG_HPP +#include "storage/storage_config.hpp" + #include -#include #include namespace osrm @@ -41,24 +42,9 @@ namespace engine struct EngineConfig { - EngineConfig() = default; + bool IsValid() const; - EngineConfig(const boost::filesystem::path &base) - : server_paths{{"ramindex", base.string() + ".ramIndex"}, - {"fileindex", base.string() + ".fileIndex"}, - {"hsgrdata", base.string() + ".hsgr"}, - {"nodesdata", base.string() + ".nodes"}, - {"edgesdata", base.string() + ".edges"}, - {"coredata", base.string() + ".core"}, - {"geometries", base.string() + ".geometry"}, - {"timestamp", base.string() + ".timestamp"}, - {"datasource_names", base.string() + ".datasource_names"}, - {"datasource_indexes", base.string() + ".datasource_indexes"}, - {"namesdata", base.string() + ".names"}} - { - } - - std::unordered_map server_paths; + storage::StorageConfig storage_config; int max_locations_trip = -1; int max_locations_viaroute = -1; int max_locations_distance_table = -1; diff --git a/include/osrm/storage_config.hpp b/include/osrm/storage_config.hpp new file mode 100644 index 000000000..353c75eed --- /dev/null +++ b/include/osrm/storage_config.hpp @@ -0,0 +1,38 @@ +/* + +Copyright (c) 2016, Project OSRM contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef GLOBAL_STORAGE_CONFIG_HPP +#define GLOBAL_STORAGE_CONFIG_HPP + +#include "storage/storage_config.hpp" + +namespace osrm +{ +using storage::StorageConfig; +} + +#endif diff --git a/include/storage/storage.hpp b/include/storage/storage.hpp index 1508cab2a..31278aaa2 100644 --- a/include/storage/storage.hpp +++ b/include/storage/storage.hpp @@ -1,24 +1,24 @@ #ifndef STORAGE_HPP #define STORAGE_HPP +#include "storage/storage_config.hpp" + #include -#include #include namespace osrm { namespace storage { -using DataPaths = std::unordered_map; class Storage { public: - Storage(const DataPaths &data_paths); + Storage(StorageConfig config); int Run(); private: - DataPaths paths; + StorageConfig config; }; } } diff --git a/include/storage/storage_config.hpp b/include/storage/storage_config.hpp new file mode 100644 index 000000000..29dd3cbc5 --- /dev/null +++ b/include/storage/storage_config.hpp @@ -0,0 +1,34 @@ +#ifndef STORAGE_CONFIG_HPP +#define STORAGE_CONFIG_HPP + +#include + +#include + +namespace osrm +{ +namespace storage +{ +struct StorageConfig +{ + StorageConfig() = default; + StorageConfig(const boost::filesystem::path &base); + bool IsValid() const; + + std::string ram_index_path; + std::string file_index_path; + std::string hsgr_data_path; + std::string nodes_data_path; + std::string edges_data_path; + std::string core_data_path; + std::string geometries_path; + std::string timestamp_path; + std::string datasource_names_path; + std::string datasource_indexes_path; + std::string names_data_path; + std::string properties_path; +}; +} +} + +#endif diff --git a/include/util/routed_options.hpp b/include/util/routed_options.hpp deleted file mode 100644 index 3a91b8d55..000000000 --- a/include/util/routed_options.hpp +++ /dev/null @@ -1,253 +0,0 @@ -#ifndef ROUTED_OPTIONS_HPP -#define ROUTED_OPTIONS_HPP - -#include "util/version.hpp" -#include "util/exception.hpp" -#include "util/simple_logger.hpp" - -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace osrm -{ -namespace util -{ -const static unsigned INIT_OK_START_ENGINE = 0; -const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1; -const static unsigned INIT_FAILED = -1; - -inline void -populate_base_path(std::unordered_map &server_paths) -{ - // populate the server_path object - auto path_iterator = server_paths.find("base"); - - // if a base path has been set, we populate it. - if (path_iterator != server_paths.end()) - { - const std::string base_string = path_iterator->second.string(); - SimpleLogger().Write() << "populating base path: " << base_string; - - server_paths["hsgrdata"] = base_string + ".hsgr"; - BOOST_ASSERT(server_paths.find("hsgrdata") != server_paths.end()); - server_paths["nodesdata"] = base_string + ".nodes"; - BOOST_ASSERT(server_paths.find("nodesdata") != server_paths.end()); - server_paths["coredata"] = base_string + ".core"; - BOOST_ASSERT(server_paths.find("coredata") != server_paths.end()); - server_paths["edgesdata"] = base_string + ".edges"; - BOOST_ASSERT(server_paths.find("edgesdata") != server_paths.end()); - server_paths["geometries"] = base_string + ".geometry"; - BOOST_ASSERT(server_paths.find("geometries") != server_paths.end()); - server_paths["ramindex"] = base_string + ".ramIndex"; - BOOST_ASSERT(server_paths.find("ramindex") != server_paths.end()); - server_paths["fileindex"] = base_string + ".fileIndex"; - BOOST_ASSERT(server_paths.find("fileindex") != server_paths.end()); - server_paths["namesdata"] = base_string + ".names"; - BOOST_ASSERT(server_paths.find("namesdata") != server_paths.end()); - server_paths["timestamp"] = base_string + ".timestamp"; - BOOST_ASSERT(server_paths.find("timestamp") != server_paths.end()); - server_paths["properties"] = base_string + ".properties"; - BOOST_ASSERT(server_paths.find("properties") != server_paths.end()); - server_paths["datasource_indexes"] = base_string + ".datasource_indexes"; - BOOST_ASSERT(server_paths.find("datasource_indexes") != server_paths.end()); - server_paths["datasource_names"] = base_string + ".datasource_names"; - BOOST_ASSERT(server_paths.find("datasource_names") != server_paths.end()); - } - - // check if files are give and whether they exist at all - path_iterator = server_paths.find("hsgrdata"); - if (path_iterator == server_paths.end() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw exception(".hsgr not found"); - } - - path_iterator = server_paths.find("nodesdata"); - if (path_iterator == server_paths.end() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw exception(".nodes not found"); - } - - path_iterator = server_paths.find("edgesdata"); - if (path_iterator == server_paths.end() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw exception(".edges not found"); - } - - path_iterator = server_paths.find("geometries"); - if (path_iterator == server_paths.end() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw exception(".geometry not found"); - } - - path_iterator = server_paths.find("ramindex"); - if (path_iterator == server_paths.end() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw exception(".ramIndex not found"); - } - - path_iterator = server_paths.find("fileindex"); - if (path_iterator == server_paths.end() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw exception(".fileIndex not found"); - } - - path_iterator = server_paths.find("namesdata"); - if (path_iterator == server_paths.end() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw exception(".namesIndex not found"); - } - - SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"]; - SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"]; - SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"]; - SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"]; - SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"]; - SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"]; - SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"]; - SimpleLogger().Write(logDEBUG) << "Timestamp file:\t" << server_paths["timestamp"]; -} - -// generate boost::program_options object for the routing part -inline unsigned -GenerateServerProgramOptions(const int argc, - const char *argv[], - std::unordered_map &paths, - std::string &ip_address, - int &ip_port, - int &requested_num_threads, - bool &use_shared_memory, - bool &trial, - int &max_locations_trip, - int &max_locations_viaroute, - int &max_locations_distance_table, - int &max_locations_map_matching) -{ - using boost::program_options::value; - using boost::filesystem::path; - - // declare a group of options that will be allowed only on command line - boost::program_options::options_description generic_options("Options"); - generic_options.add_options() // - ("version,v", "Show version")("help,h", "Show this help message") // - ("config,c", value(&paths["config"])->default_value("server.ini"), - "Path to a configuration file") // - ("trial", value(&trial)->implicit_value(true), "Quit after initialization"); - - // declare a group of options that will be allowed on command line - boost::program_options::options_description config_options("Configuration"); - config_options.add_options() // - ("hsgrdata", value(&paths["hsgrdata"]), ".hsgr file") // - ("nodesdata", value(&paths["nodesdata"]), ".nodes file") // - ("edgesdata", value(&paths["edgesdata"]), ".edges file") // - ("geometry", value(&paths["geometries"]), ".geometry file") // - ("ramindex", value(&paths["ramindex"]), ".ramIndex file") // - ("fileindex", value(&paths["fileindex"]), - "File index file") // - ("namesdata", value(&paths["namesdata"]), - ".names file") // - ("timestamp", value(&paths["timestamp"]), - ".timestamp file") // - ("ip,i", value(&ip_address)->default_value("0.0.0.0"), - "IP address") // - ("port,p", value(&ip_port)->default_value(5000), - "TCP/IP port") // - ("threads,t", value(&requested_num_threads)->default_value(8), - "Number of threads to use") // - ("shared-memory,s", - value(&use_shared_memory)->implicit_value(true)->default_value(false), - "Load data from shared memory") // - ("max-viaroute-size", value(&max_locations_viaroute)->default_value(500), - "Max. locations supported in viaroute query") // - ("max-trip-size", value(&max_locations_trip)->default_value(100), - "Max. locations supported in trip query") // - ("max-table-size", value(&max_locations_distance_table)->default_value(100), - "Max. locations supported in distance table query") // - ("max-matching-size", value(&max_locations_map_matching)->default_value(100), - "Max. locations supported in map matching query"); - - // hidden options, will be allowed on command line, but will not be shown to the user - boost::program_options::options_description hidden_options("Hidden options"); - hidden_options.add_options()("base,b", value(&paths["base"]), - "base path to .osrm file"); - - // positional option - boost::program_options::positional_options_description positional_options; - positional_options.add("base", 1); - - // combine above options for parsing - boost::program_options::options_description cmdline_options; - cmdline_options.add(generic_options).add(config_options).add(hidden_options); - - boost::program_options::options_description visible_options( - boost::filesystem::basename(argv[0]) + " []"); - visible_options.add(generic_options).add(config_options); - - // parse command line options - boost::program_options::variables_map option_variables; - boost::program_options::store(boost::program_options::command_line_parser(argc, argv) - .options(cmdline_options) - .positional(positional_options) - .run(), - option_variables); - - if (option_variables.count("version")) - { - SimpleLogger().Write() << OSRM_VERSION; - return INIT_OK_DO_NOT_START_ENGINE; - } - - if (option_variables.count("help")) - { - SimpleLogger().Write() << visible_options; - return INIT_OK_DO_NOT_START_ENGINE; - } - - boost::program_options::notify(option_variables); - - if (1 > requested_num_threads) - { - throw exception("Number of threads must be a positive number"); - } - if (2 > max_locations_distance_table) - { - throw exception("Max location for distance table must be at least two"); - } - if (max_locations_map_matching > 0 && 2 > max_locations_map_matching) - { - throw exception("Max location for map matching must be at least two"); - } - - if (!use_shared_memory && option_variables.count("base")) - { - return INIT_OK_START_ENGINE; - } - else if (use_shared_memory && !option_variables.count("base")) - { - return INIT_OK_START_ENGINE; - } - else if (use_shared_memory && option_variables.count("base")) - { - SimpleLogger().Write(logWARNING) << "Shared memory settings conflict with path settings."; - } - - SimpleLogger().Write() << visible_options; - return INIT_OK_DO_NOT_START_ENGINE; -} -} -} - -#endif // ROUTED_OPTIONS_HPP diff --git a/src/contractor/contractor.cpp b/src/contractor/contractor.cpp index 824adb99e..39d6f4815 100644 --- a/src/contractor/contractor.cpp +++ b/src/contractor/contractor.cpp @@ -173,6 +173,10 @@ std::size_t Contractor::LoadEdgeExpandedGraph( std::unordered_map, std::pair> segment_speed_lookup; + // If we update the edge weights, this file will hold the datasource information + // for each segment + std::vector m_geometry_datasource; + if (update_edge_weights) { uint8_t file_id = 1; @@ -264,7 +268,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph( // CSV file that supplied the value that gets used for that segment, then // we write out this list so that it can be returned by the debugging // vector tiles later on. - std::vector m_geometry_datasource(m_geometry_list.size(), 0); + m_geometry_datasource.resize(m_geometry_list.size(), 0); // Now, we iterate over all the segments stored in the StaticRTree, updating // the packed geometry weights in the `.geometries` file (note: we do not @@ -402,33 +406,36 @@ std::size_t Contractor::LoadEdgeExpandedGraph( number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); } + } + { + std::ofstream datasource_stream(datasource_indexes_filename, std::ios::binary); + if (!datasource_stream) + { + throw util::exception("Failed to open " + datasource_indexes_filename + + " for writing"); + } + auto number_of_datasource_entries = m_geometry_datasource.size(); + datasource_stream.write(reinterpret_cast(&number_of_datasource_entries), + sizeof(number_of_datasource_entries)); + if (number_of_datasource_entries > 0) { - std::ofstream datasource_stream(datasource_indexes_filename, std::ios::binary); - if (!datasource_stream) - { - throw util::exception("Failed to open " + datasource_indexes_filename + - " for writing"); - } - auto number_of_datasource_entries = m_geometry_datasource.size(); - datasource_stream.write(reinterpret_cast(&number_of_datasource_entries), - sizeof(number_of_datasource_entries)); datasource_stream.write(reinterpret_cast(&(m_geometry_datasource[0])), number_of_datasource_entries * sizeof(uint8_t)); } + } + { + std::ofstream datasource_stream(datasource_names_filename, std::ios::binary); + if (!datasource_stream) { - std::ofstream datasource_stream(datasource_names_filename, std::ios::binary); - if (!datasource_stream) - { - throw util::exception("Failed to open " + datasource_names_filename + - " for writing"); - } - datasource_stream << "lua profile" << std::endl; - for (auto const &name : segment_speed_filenames) - { - datasource_stream << name << std::endl; - } + throw util::exception("Failed to open " + datasource_names_filename + + " for writing"); + } + datasource_stream << "lua profile" << std::endl; + for (auto const &name : segment_speed_filenames) + { + datasource_stream << name << std::endl; } } diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index a75ec5030..63f601c56 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -18,7 +18,6 @@ #include "storage/shared_barriers.hpp" #include "util/make_unique.hpp" -#include "util/routed_options.hpp" #include "util/simple_logger.hpp" #include @@ -136,8 +135,11 @@ Engine::Engine(EngineConfig &config) } else { - util::populate_base_path(config.server_paths); - query_data_facade = util::make_unique(config.server_paths); + if (!config.storage_config.IsValid()) + { + throw util::exception("Invalid file paths given!"); + } + query_data_facade = util::make_unique(config.storage_config); } // Register plugins diff --git a/src/engine/engine_config.cpp b/src/engine/engine_config.cpp new file mode 100644 index 000000000..e26a67eed --- /dev/null +++ b/src/engine/engine_config.cpp @@ -0,0 +1,27 @@ +#include "engine/engine_config.hpp" + +namespace osrm +{ +namespace engine +{ + +bool EngineConfig::IsValid() const +{ + const bool all_path_are_empty = + storage_config.ram_index_path.empty() && storage_config.file_index_path.empty() && + storage_config.hsgr_data_path.empty() && storage_config.nodes_data_path.empty() && + storage_config.edges_data_path.empty() && storage_config.core_data_path.empty() && + storage_config.geometries_path.empty() && storage_config.timestamp_path.empty() && + storage_config.datasource_names_path.empty() && + storage_config.datasource_indexes_path.empty() && storage_config.names_data_path.empty(); + + const bool limits_valid = + (max_locations_distance_table == -1 || max_locations_distance_table > 2) && + (max_locations_map_matching == -1 || max_locations_map_matching > 2) && + (max_locations_trip == -1 || max_locations_trip > 2) && + (max_locations_viaroute == -1 || max_locations_viaroute > 2); + + return ((use_shared_memory && all_path_are_empty) || storage_config.IsValid()) && limits_valid; +} +} +} diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 184609362..4dea95b1a 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -73,10 +73,12 @@ void deleteRegion(const SharedDataType region) } } -Storage::Storage(const DataPaths &paths_) : paths(paths_) {} +Storage::Storage(StorageConfig config_) : config(std::move(config_)) {} int Storage::Run() { + BOOST_ASSERT_MSG(config.IsValid(), "Invalid storage config"); + util::LogPolicy::GetInstance().Unmute(); SharedBarriers barrier; @@ -100,98 +102,6 @@ int Storage::Run() barrier.pending_update_mutex.unlock(); } - if (paths.find("hsgrdata") == paths.end()) - { - throw util::exception("no hsgr file found"); - } - if (paths.find("ramindex") == paths.end()) - { - throw util::exception("no ram index file found"); - } - if (paths.find("fileindex") == paths.end()) - { - throw util::exception("no leaf index file found"); - } - if (paths.find("nodesdata") == paths.end()) - { - throw util::exception("no nodes file found"); - } - if (paths.find("edgesdata") == paths.end()) - { - throw util::exception("no edges file found"); - } - if (paths.find("namesdata") == paths.end()) - { - throw util::exception("no names file found"); - } - if (paths.find("geometry") == paths.end()) - { - throw util::exception("no geometry file found"); - } - if (paths.find("core") == paths.end()) - { - throw util::exception("no core file found"); - } - if (paths.find("datasource_indexes") == paths.end()) - { - throw util::exception("no datasource_indexes file found"); - } - if (paths.find("datasource_names") == paths.end()) - { - throw util::exception("no datasource_names file found"); - } - - auto paths_iterator = paths.find("hsgrdata"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &hsgr_path = paths_iterator->second; - paths_iterator = paths.find("timestamp"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path ×tamp_path = paths_iterator->second; - paths_iterator = paths.find("properties"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &properties_path = paths_iterator->second; - paths_iterator = paths.find("ramindex"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &ram_index_path = paths_iterator->second; - paths_iterator = paths.find("fileindex"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path index_file_path_absolute = - boost::filesystem::canonical(paths_iterator->second); - const std::string &file_index_path = index_file_path_absolute.string(); - paths_iterator = paths.find("nodesdata"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &nodes_data_path = paths_iterator->second; - paths_iterator = paths.find("edgesdata"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &edges_data_path = paths_iterator->second; - paths_iterator = paths.find("namesdata"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &names_data_path = paths_iterator->second; - paths_iterator = paths.find("geometry"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &geometries_data_path = paths_iterator->second; - paths_iterator = paths.find("core"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &core_marker_path = paths_iterator->second; - paths_iterator = paths.find("datasource_indexes"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &datasource_indexes_path = paths_iterator->second; - paths_iterator = paths.find("datasource_names"); - BOOST_ASSERT(paths.end() != paths_iterator); - BOOST_ASSERT(!paths_iterator->second.empty()); - const boost::filesystem::path &datasource_names_path = paths_iterator->second; - // determine segment to use bool segment2_in_use = SharedMemory::RegionExists(LAYOUT_2); const storage::SharedDataType layout_region = [&] @@ -216,12 +126,12 @@ int Storage::Run() auto shared_layout_ptr = new (layout_memory->Ptr()) SharedDataLayout(); shared_layout_ptr->SetBlockSize(SharedDataLayout::FILE_INDEX_PATH, - file_index_path.length() + 1); + config.file_index_path.length() + 1); // collect number of elements to store in shared memory object - util::SimpleLogger().Write() << "load names from: " << names_data_path; + util::SimpleLogger().Write() << "load names from: " << config.names_data_path; // number of entries in name index - boost::filesystem::ifstream name_stream(names_data_path, std::ios::binary); + boost::filesystem::ifstream name_stream(config.names_data_path, std::ios::binary); unsigned name_blocks = 0; name_stream.read((char *)&name_blocks, sizeof(unsigned)); shared_layout_ptr->SetBlockSize(SharedDataLayout::NAME_OFFSETS, name_blocks); @@ -235,7 +145,7 @@ int Storage::Run() shared_layout_ptr->SetBlockSize(SharedDataLayout::NAME_CHAR_LIST, number_of_chars); // Loading information for original edges - boost::filesystem::ifstream edges_input_stream(edges_data_path, std::ios::binary); + boost::filesystem::ifstream edges_input_stream(config.edges_data_path, std::ios::binary); unsigned number_of_original_edges = 0; edges_input_stream.read((char *)&number_of_original_edges, sizeof(unsigned)); @@ -249,7 +159,7 @@ int Storage::Run() shared_layout_ptr->SetBlockSize( SharedDataLayout::TURN_INSTRUCTION, number_of_original_edges); - boost::filesystem::ifstream hsgr_input_stream(hsgr_path, std::ios::binary); + boost::filesystem::ifstream hsgr_input_stream(config.hsgr_data_path, std::ios::binary); util::FingerPrint fingerprint_valid = util::FingerPrint::GetValid(); util::FingerPrint fingerprint_loaded; @@ -284,7 +194,7 @@ int Storage::Run() number_of_graph_edges); // load rsearch tree size - boost::filesystem::ifstream tree_node_file(ram_index_path, std::ios::binary); + boost::filesystem::ifstream tree_node_file(config.ram_index_path, std::ios::binary); uint32_t tree_size = 0; tree_node_file.read((char *)&tree_size, sizeof(uint32_t)); @@ -295,12 +205,12 @@ int Storage::Run() // load timestamp size std::string m_timestamp; - if (boost::filesystem::exists(timestamp_path)) + if (boost::filesystem::exists(config.timestamp_path)) { - boost::filesystem::ifstream timestamp_stream(timestamp_path); + boost::filesystem::ifstream timestamp_stream(config.timestamp_path); if (!timestamp_stream) { - util::SimpleLogger().Write(logWARNING) << timestamp_path + util::SimpleLogger().Write(logWARNING) << config.timestamp_path << " not found. setting to default"; } else @@ -319,7 +229,7 @@ int Storage::Run() shared_layout_ptr->SetBlockSize(SharedDataLayout::TIMESTAMP, m_timestamp.length()); // load core marker size - boost::filesystem::ifstream core_marker_file(core_marker_path, std::ios::binary); + boost::filesystem::ifstream core_marker_file(config.core_data_path, std::ios::binary); uint32_t number_of_core_markers = 0; core_marker_file.read((char *)&number_of_core_markers, sizeof(uint32_t)); @@ -327,14 +237,14 @@ int Storage::Run() number_of_core_markers); // load coordinate size - boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary); + boost::filesystem::ifstream nodes_input_stream(config.nodes_data_path, std::ios::binary); unsigned coordinate_list_size = 0; nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned)); shared_layout_ptr->SetBlockSize(SharedDataLayout::COORDINATE_LIST, coordinate_list_size); // load geometries sizes - std::ifstream geometry_input_stream(geometries_data_path.string().c_str(), std::ios::binary); + boost::filesystem::ifstream geometry_input_stream(config.geometries_path, std::ios::binary); unsigned number_of_geometries_indices = 0; unsigned number_of_compressed_geometries = 0; @@ -349,8 +259,8 @@ int Storage::Run() // load datasource sizes. This file is optional, and it's non-fatal if it doesn't // exist. - std::ifstream geometry_datasource_input_stream(datasource_indexes_path.c_str(), - std::ios::binary); + boost::filesystem::ifstream geometry_datasource_input_stream(config.datasource_indexes_path, + std::ios::binary); std::size_t number_of_compressed_datasources = 0; if (geometry_datasource_input_stream) { @@ -362,7 +272,8 @@ int Storage::Run() // Load datasource name sizes. This file is optional, and it's non-fatal if it doesn't // exist - std::ifstream datasource_names_input_stream(datasource_names_path.c_str(), std::ios::binary); + boost::filesystem::ifstream datasource_names_input_stream(config.datasource_names_path, + std::ios::binary); std::vector m_datasource_name_data; std::vector m_datasource_name_offsets; std::vector m_datasource_name_lengths; @@ -378,11 +289,11 @@ int Storage::Run() } } shared_layout_ptr->SetBlockSize(SharedDataLayout::DATASOURCE_NAME_DATA, - m_datasource_name_data.size()); + m_datasource_name_data.size()); shared_layout_ptr->SetBlockSize(SharedDataLayout::DATASOURCE_NAME_OFFSETS, - m_datasource_name_offsets.size()); + m_datasource_name_offsets.size()); shared_layout_ptr->SetBlockSize(SharedDataLayout::DATASOURCE_NAME_LENGTHS, - m_datasource_name_lengths.size()); + m_datasource_name_lengths.size()); // allocate shared memory block util::SimpleLogger().Write() << "allocating shared memory of " @@ -405,7 +316,7 @@ int Storage::Run() file_index_path_ptr + shared_layout_ptr->GetBlockSize(SharedDataLayout::FILE_INDEX_PATH), 0); - std::copy(file_index_path.begin(), file_index_path.end(), file_index_path_ptr); + std::copy(config.file_index_path.begin(), config.file_index_path.end(), file_index_path_ptr); // Loading street names unsigned *name_offsets_ptr = shared_layout_ptr->GetBlockPtr( @@ -512,8 +423,7 @@ int Storage::Run() shared_memory_ptr, SharedDataLayout::DATASOURCE_NAME_DATA); if (shared_layout_ptr->GetBlockSize(SharedDataLayout::DATASOURCE_NAME_DATA) > 0) { - std::cout << "Copying " - << (m_datasource_name_data.end() - m_datasource_name_data.begin()) + std::cout << "Copying " << (m_datasource_name_data.end() - m_datasource_name_data.begin()) << " chars into name data ptr\n"; std::copy(m_datasource_name_data.begin(), m_datasource_name_data.end(), datasource_name_data_ptr); @@ -615,10 +525,10 @@ int Storage::Run() // load profile properties auto profile_properties_ptr = shared_layout_ptr->GetBlockPtr(shared_memory_ptr, SharedDataLayout::PROPERTIES); - boost::filesystem::ifstream profile_properties_stream(properties_path); + boost::filesystem::ifstream profile_properties_stream(config.properties_path); if (!profile_properties_stream) { - util::exception("Could not open " + properties_path.string() + " for reading!"); + util::exception("Could not open " + config.properties_path + " for reading!"); } profile_properties_stream.read(reinterpret_cast(profile_properties_ptr), sizeof(extractor::ProfileProperties)); diff --git a/src/storage/storage_config.cpp b/src/storage/storage_config.cpp new file mode 100644 index 000000000..6ade34a0c --- /dev/null +++ b/src/storage/storage_config.cpp @@ -0,0 +1,38 @@ +#include "storage/storage_config.hpp" + +#include + +namespace osrm +{ +namespace storage +{ + +StorageConfig::StorageConfig(const boost::filesystem::path &base) + : ram_index_path{base.string() + ".ramIndex"}, file_index_path{base.string() + ".fileIndex"}, + hsgr_data_path{base.string() + ".hsgr"}, nodes_data_path{base.string() + ".nodes"}, + edges_data_path{base.string() + ".edges"}, core_data_path{base.string() + ".core"}, + geometries_path{base.string() + ".geometry"}, timestamp_path{base.string() + ".timestamp"}, + datasource_names_path{base.string() + ".datasource_names"}, + datasource_indexes_path{base.string() + ".datasource_indexes"}, + names_data_path{base.string() + ".names"}, + properties_path{base.string() + ".properties"} +{ +} + +bool StorageConfig::IsValid() const +{ + return boost::filesystem::is_regular_file(ram_index_path) && + boost::filesystem::is_regular_file(file_index_path) && + boost::filesystem::is_regular_file(hsgr_data_path) && + boost::filesystem::is_regular_file(nodes_data_path) && + boost::filesystem::is_regular_file(edges_data_path) && + boost::filesystem::is_regular_file(core_data_path) && + boost::filesystem::is_regular_file(geometries_path) && + boost::filesystem::is_regular_file(timestamp_path) && + boost::filesystem::is_regular_file(datasource_names_path) && + boost::filesystem::is_regular_file(datasource_indexes_path) && + boost::filesystem::is_regular_file(names_data_path) && + boost::filesystem::is_regular_file(properties_path); +} +} +} diff --git a/src/tools/routed.cpp b/src/tools/routed.cpp index c91530850..b15e9dca7 100644 --- a/src/tools/routed.cpp +++ b/src/tools/routed.cpp @@ -1,10 +1,14 @@ #include "server/server.hpp" -#include "util/routed_options.hpp" #include "util/make_unique.hpp" #include "util/simple_logger.hpp" +#include "util/version.hpp" #include "osrm/osrm.hpp" #include "osrm/engine_config.hpp" +#include "osrm/storage_config.hpp" + +#include +#include #ifdef __linux__ #include @@ -19,6 +23,7 @@ #include #include #include +#include #ifdef _WIN32 boost::function0 console_ctrl_function; @@ -41,6 +46,111 @@ BOOL WINAPI console_ctrl_handler(DWORD ctrl_type) using namespace osrm; +const static unsigned INIT_OK_START_ENGINE = 0; +const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1; +const static unsigned INIT_FAILED = -1; + +// generate boost::program_options object for the routing part +inline unsigned +generateServerProgramOptions(const int argc, + const char *argv[], + boost::filesystem::path &base_path, + std::string &ip_address, + int &ip_port, + int &requested_num_threads, + bool &use_shared_memory, + bool &trial, + int &max_locations_trip, + int &max_locations_viaroute, + int &max_locations_distance_table, + int &max_locations_map_matching) +{ + using boost::program_options::value; + using boost::filesystem::path; + + // declare a group of options that will be allowed only on command line + boost::program_options::options_description generic_options("Options"); + generic_options.add_options() // + ("version,v", "Show version")("help,h", "Show this help message") // + ("trial", value(&trial)->implicit_value(true), "Quit after initialization"); + + // declare a group of options that will be allowed on command line + boost::program_options::options_description config_options("Configuration"); + config_options.add_options() // + ("ip,i", value(&ip_address)->default_value("0.0.0.0"), + "IP address") // + ("port,p", value(&ip_port)->default_value(5000), + "TCP/IP port") // + ("threads,t", value(&requested_num_threads)->default_value(8), + "Number of threads to use") // + ("shared-memory,s", + value(&use_shared_memory)->implicit_value(true)->default_value(false), + "Load data from shared memory") // + ("max-viaroute-size", value(&max_locations_viaroute)->default_value(500), + "Max. locations supported in viaroute query") // + ("max-trip-size", value(&max_locations_trip)->default_value(100), + "Max. locations supported in trip query") // + ("max-table-size", value(&max_locations_distance_table)->default_value(100), + "Max. locations supported in distance table query") // + ("max-matching-size", value(&max_locations_map_matching)->default_value(100), + "Max. locations supported in map matching query"); + + // hidden options, will be allowed on command line, but will not be shown to the user + boost::program_options::options_description hidden_options("Hidden options"); + hidden_options.add_options()("base,b", value(&base_path), + "base path to .osrm file"); + + // positional option + boost::program_options::positional_options_description positional_options; + positional_options.add("base", 1); + + // combine above options for parsing + boost::program_options::options_description cmdline_options; + cmdline_options.add(generic_options).add(config_options).add(hidden_options); + + boost::program_options::options_description visible_options( + boost::filesystem::path(argv[0]).stem().string() + " []"); + visible_options.add(generic_options).add(config_options); + + // parse command line options + boost::program_options::variables_map option_variables; + boost::program_options::store(boost::program_options::command_line_parser(argc, argv) + .options(cmdline_options) + .positional(positional_options) + .run(), + option_variables); + + if (option_variables.count("version")) + { + util::SimpleLogger().Write() << OSRM_VERSION; + return INIT_OK_DO_NOT_START_ENGINE; + } + + if (option_variables.count("help")) + { + util::SimpleLogger().Write() << visible_options; + return INIT_OK_DO_NOT_START_ENGINE; + } + + boost::program_options::notify(option_variables); + + if (!use_shared_memory && option_variables.count("base")) + { + return INIT_OK_START_ENGINE; + } + else if (use_shared_memory && !option_variables.count("base")) + { + return INIT_OK_START_ENGINE; + } + else if (use_shared_memory && option_variables.count("base")) + { + util::SimpleLogger().Write(logWARNING) << "Shared memory settings conflict with path settings."; + } + + util::SimpleLogger().Write() << visible_options; + return INIT_OK_DO_NOT_START_ENGINE; +} + int main(int argc, const char *argv[]) try { util::LogPolicy::GetInstance().Unmute(); @@ -50,19 +160,36 @@ int main(int argc, const char *argv[]) try int ip_port, requested_thread_num; EngineConfig config; - const unsigned init_result = util::GenerateServerProgramOptions( - argc, argv, config.server_paths, ip_address, ip_port, requested_thread_num, + boost::filesystem::path base_path; + const unsigned init_result = generateServerProgramOptions( + argc, argv, base_path, ip_address, ip_port, requested_thread_num, config.use_shared_memory, trial_run, config.max_locations_trip, config.max_locations_viaroute, config.max_locations_distance_table, config.max_locations_map_matching); - if (init_result == util::INIT_OK_DO_NOT_START_ENGINE) + if (init_result == INIT_OK_DO_NOT_START_ENGINE) { return EXIT_SUCCESS; } - if (init_result == util::INIT_FAILED) + if (init_result == INIT_FAILED) { return EXIT_FAILURE; } + if (!base_path.empty()) + { + config.storage_config = storage::StorageConfig(base_path); + } + if(!config.IsValid()) + { + if (base_path.empty() != config.use_shared_memory) + { + util::SimpleLogger().Write(logWARNING) << "Path settings and shared memory conflicts."; + } + else + { + util::SimpleLogger().Write(logWARNING) << "Invalid config options."; + } + return EXIT_FAILURE; + } #ifdef __linux__ struct MemoryLocker final diff --git a/src/tools/store.cpp b/src/tools/store.cpp index 31e01cf2c..7866cf3be 100644 --- a/src/tools/store.cpp +++ b/src/tools/store.cpp @@ -10,7 +10,7 @@ using namespace osrm; // generate boost::program_options object for the routing part -bool generateDataStoreOptions(const int argc, const char *argv[], storage::DataPaths &paths) +bool generateDataStoreOptions(const int argc, const char *argv[], boost::filesystem::path& base_path) { // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); @@ -20,38 +20,11 @@ bool generateDataStoreOptions(const int argc, const char *argv[], storage::DataP // declare a group of options that will be allowed both on command line // as well as in a config file boost::program_options::options_description config_options("Configuration"); - config_options.add_options()( - "hsgrdata", boost::program_options::value(&paths["hsgrdata"]), - ".hsgr file")("nodesdata", - boost::program_options::value(&paths["nodesdata"]), - ".nodes file")( - "edgesdata", boost::program_options::value(&paths["edgesdata"]), - ".edges file")("geometry", - boost::program_options::value(&paths["geometry"]), - ".geometry file")( - "ramindex", boost::program_options::value(&paths["ramindex"]), - ".ramIndex file")( - "fileindex", boost::program_options::value(&paths["fileindex"]), - ".fileIndex file")("core", - boost::program_options::value(&paths["core"]), - ".core file")( - "namesdata", boost::program_options::value(&paths["namesdata"]), - ".names file")("timestamp", - boost::program_options::value(&paths["timestamp"]), - ".timestamp file")( - "datasource_names", - boost::program_options::value(&paths["datasource_names"]), - ".datasource_names file")( - "datasource_indexes", - boost::program_options::value(&paths["datasource_indexes"]), - ".datasource_indexes file")( - "properties", boost::program_options::value(&paths["properties"]), - ".properties file"); // hidden options, will be allowed on command line but will not be shown to the user boost::program_options::options_description hidden_options("Hidden options"); hidden_options.add_options()( - "base,b", boost::program_options::value(&paths["base"]), + "base,b", boost::program_options::value(&base_path), "base path to .osrm file"); // positional option @@ -95,145 +68,6 @@ bool generateDataStoreOptions(const int argc, const char *argv[], storage::DataP boost::program_options::notify(option_variables); - auto path_iterator = paths.find("base"); - BOOST_ASSERT(paths.end() != path_iterator); - std::string base_string = path_iterator->second.string(); - - path_iterator = paths.find("hsgrdata"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".hsgr"; - } - - path_iterator = paths.find("nodesdata"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".nodes"; - } - - path_iterator = paths.find("edgesdata"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".edges"; - } - - path_iterator = paths.find("geometry"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".geometry"; - } - - path_iterator = paths.find("ramindex"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".ramIndex"; - } - - path_iterator = paths.find("fileindex"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".fileIndex"; - } - - path_iterator = paths.find("core"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".core"; - } - - path_iterator = paths.find("namesdata"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".names"; - } - - path_iterator = paths.find("timestamp"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".timestamp"; - } - - path_iterator = paths.find("properties"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".properties"; - } - - path_iterator = paths.find("datasource_indexes"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".datasource_indexes"; - } - - path_iterator = paths.find("datasource_names"); - if (path_iterator != paths.end()) - { - path_iterator->second = base_string + ".datasource_names"; - } - - path_iterator = paths.find("hsgrdata"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .hsgr file must be specified"); - } - - path_iterator = paths.find("nodesdata"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .nodes file must be specified"); - } - - path_iterator = paths.find("edgesdata"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .edges file must be specified"); - } - - path_iterator = paths.find("geometry"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .geometry file must be specified"); - } - - path_iterator = paths.find("ramindex"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .ramindex file must be specified"); - } - - path_iterator = paths.find("fileindex"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .fileindex file must be specified"); - } - - path_iterator = paths.find("namesdata"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .names file must be specified"); - } - - path_iterator = paths.find("timestamp"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .timestamp file must be specified"); - } - - path_iterator = paths.find("properties"); - if (path_iterator == paths.end() || path_iterator->second.string().empty() || - !boost::filesystem::is_regular_file(path_iterator->second)) - { - throw util::exception("valid .properties file must be specified"); - } - return true; } @@ -241,13 +75,18 @@ int main(const int argc, const char *argv[]) try { util::LogPolicy::GetInstance().Unmute(); - storage::DataPaths paths; - if (!generateDataStoreOptions(argc, argv, paths)) + boost::filesystem::path base_path; + if (!generateDataStoreOptions(argc, argv, base_path)) { return EXIT_SUCCESS; } - - storage::Storage storage(paths); + storage::StorageConfig config(base_path); + if (!config.IsValid()) + { + util::SimpleLogger().Write(logWARNING) << "Invalid file path given!"; + return EXIT_FAILURE; + } + storage::Storage storage(std::move(config)); return storage.Run(); } catch (const std::bad_alloc &e)