Remove CheckCompability because it now duplicates logic in the datafacade

This commit is contained in:
Patrick Niklaus 2018-03-28 11:27:07 +00:00 committed by Patrick Niklaus
parent c334d11e95
commit 24e0028afb
3 changed files with 4 additions and 112 deletions

View File

@ -7,8 +7,6 @@
#include "engine/api/table_parameters.hpp" #include "engine/api/table_parameters.hpp"
#include "engine/api/tile_parameters.hpp" #include "engine/api/tile_parameters.hpp"
#include "engine/api/trip_parameters.hpp" #include "engine/api/trip_parameters.hpp"
#include "engine/data_watchdog.hpp"
#include "engine/datafacade/contiguous_block_allocator.hpp"
#include "engine/datafacade_provider.hpp" #include "engine/datafacade_provider.hpp"
#include "engine/engine_config.hpp" #include "engine/engine_config.hpp"
#include "engine/plugins/match.hpp" #include "engine/plugins/match.hpp"
@ -20,11 +18,6 @@
#include "engine/routing_algorithms.hpp" #include "engine/routing_algorithms.hpp"
#include "engine/status.hpp" #include "engine/status.hpp"
#include "storage/serialization.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/fingerprint.hpp"
#include "util/json_container.hpp" #include "util/json_container.hpp"
#include <memory> #include <memory>
@ -126,8 +119,6 @@ template <typename Algorithm> class Engine final : public EngineInterface
return tile_plugin.HandleRequest(GetAlgorithms(params), params, result); return tile_plugin.HandleRequest(GetAlgorithms(params), params, result);
} }
static bool CheckCompatibility(const EngineConfig &config);
private: private:
template <typename ParametersT> auto GetAlgorithms(const ParametersT &params) const template <typename ParametersT> auto GetAlgorithms(const ParametersT &params) const
{ {
@ -143,84 +134,6 @@ template <typename Algorithm> class Engine final : public EngineInterface
const plugins::MatchPlugin match_plugin; const plugins::MatchPlugin match_plugin;
const plugins::TilePlugin tile_plugin; const plugins::TilePlugin tile_plugin;
}; };
template <>
bool Engine<routing_algorithms::ch::Algorithm>::CheckCompatibility(const EngineConfig &config)
{
if (config.use_shared_memory)
{
storage::SharedMonitor<storage::SharedDataTimestamp> barrier;
using mutex_type = typename decltype(barrier)::mutex_type;
boost::interprocess::scoped_lock<mutex_type> current_region_lock(barrier.get_mutex());
auto mem = storage::makeSharedMemory(barrier.data().region);
storage::DataLayout layout;
storage::io::BufferReader reader(reinterpret_cast<const char *>(mem->Ptr()), mem->Size());
storage::serialization::read(reader, layout);
std::vector<std::string> metric_prefixes;
layout.List("/ch/metrics/", std::back_inserter(metric_prefixes));
bool has_graph = false;
for (const auto &metric_prefix : metric_prefixes)
{
has_graph |= layout.HasBlock(metric_prefix + "/contracted_graph/node_array") &&
layout.HasBlock(metric_prefix + "/contracted_graph/edge_array");
}
return has_graph;
}
else
{
return boost::filesystem::exists(config.storage_config.GetPath(".osrm.hsgr"));
}
}
template <>
bool Engine<routing_algorithms::mld::Algorithm>::CheckCompatibility(const EngineConfig &config)
{
if (config.use_shared_memory)
{
storage::SharedMonitor<storage::SharedDataTimestamp> barrier;
using mutex_type = typename decltype(barrier)::mutex_type;
boost::interprocess::scoped_lock<mutex_type> current_region_lock(barrier.get_mutex());
auto mem = storage::makeSharedMemory(barrier.data().region);
storage::DataLayout layout;
storage::io::BufferReader reader(reinterpret_cast<const char *>(mem->Ptr()), mem->Size());
storage::serialization::read(reader, layout);
std::vector<std::string> metric_prefixes;
layout.List("/mld/metrics/", std::back_inserter(metric_prefixes));
bool has_cells = false;
for (const auto &metric_prefix : metric_prefixes)
{
has_cells |= layout.HasBlock(metric_prefix + "/exclude/0/durations") &&
layout.HasBlock(metric_prefix + "/exclude/0/weights");
}
// checks that all the needed memory blocks are populated
// "/mld/cellstorage/source_boundary" and "/mld/cellstorage/destination_boundary"
// are not checked, because in situations where there are so few nodes in the graph that
// they all fit into one cell, they can be empty.
bool has_data = has_cells && layout.HasBlock("/mld/multilevelpartition/level_data") &&
layout.HasBlock("/mld/multilevelpartition/partition") &&
layout.HasBlock("/mld/multilevelpartition/cell_to_children") &&
layout.HasBlock("/mld/cellstorage/cells") &&
layout.HasBlock("/mld/cellstorage/level_to_cell_offset") &&
layout.HasBlock("/mld/multilevelgraph/node_array") &&
layout.HasBlock("/mld/multilevelgraph/edge_array") &&
layout.HasBlock("/mld/multilevelgraph/node_to_edge_offset");
return has_data;
}
else
{
return boost::filesystem::exists(config.storage_config.GetPath(".osrm.partition")) &&
boost::filesystem::exists(config.storage_config.GetPath(".osrm.cells")) &&
boost::filesystem::exists(config.storage_config.GetPath(".osrm.mldgr")) &&
boost::filesystem::exists(config.storage_config.GetPath(".osrm.cell_metrics"));
}
}
} }
} }

View File

@ -1,4 +1,5 @@
#include "osrm/osrm.hpp" #include "osrm/osrm.hpp"
#include "engine/algorithm.hpp" #include "engine/algorithm.hpp"
#include "engine/api/match_parameters.hpp" #include "engine/api/match_parameters.hpp"
#include "engine/api/nearest_parameters.hpp" #include "engine/api/nearest_parameters.hpp"
@ -37,30 +38,10 @@ OSRM::OSRM(engine::EngineConfig &config)
// Now, check that the algorithm requested can be used with the data // Now, check that the algorithm requested can be used with the data
// that's available. // that's available.
if (config.algorithm == EngineConfig::Algorithm::CH || if (config.algorithm == EngineConfig::Algorithm::CoreCH)
config.algorithm == EngineConfig::Algorithm::CoreCH)
{ {
if (config.algorithm == EngineConfig::Algorithm::CoreCH) util::Log(logWARNING) << "Using CoreCH is deprecated. Falling back to CH";
{ config.algorithm = EngineConfig::Algorithm::CH;
util::Log(logWARNING) << "Using CoreCH is deprecated. Falling back to CH";
config.algorithm = EngineConfig::Algorithm::CH;
}
bool ch_compatible = engine::Engine<CH>::CheckCompatibility(config);
// throw error if dataset is not usable with CH
if (config.algorithm == EngineConfig::Algorithm::CH && !ch_compatible)
{
throw util::exception("Dataset is not compatible with CH");
}
}
else if (config.algorithm == EngineConfig::Algorithm::MLD)
{
bool mld_compatible = engine::Engine<MLD>::CheckCompatibility(config);
// throw error if dataset is not usable with MLD
if (!mld_compatible)
{
throw util::exception("Dataset is not compatible with MLD.");
}
} }
switch (config.algorithm) switch (config.algorithm)

View File

@ -89,8 +89,6 @@ inline void readBlocks(const boost::filesystem::path &path, DataLayout &layout)
} }
} }
static constexpr std::size_t NUM_METRICS = 8;
using RTreeLeaf = engine::datafacade::BaseDataFacade::RTreeLeaf; using RTreeLeaf = engine::datafacade::BaseDataFacade::RTreeLeaf;
using RTreeNode = util::StaticRTree<RTreeLeaf, storage::Ownership::View>::TreeNode; using RTreeNode = util::StaticRTree<RTreeLeaf, storage::Ownership::View>::TreeNode;
using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>; using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>;