Make initialization fail with a specific exception if the dataset isn't compatible with the algorithm being used, rather than crashing when a query occurs.

This commit is contained in:
Daniel Patterson
2017-06-05 15:58:50 -07:00
committed by Patrick Niklaus
parent 3d77714c36
commit 5026741652
10 changed files with 138 additions and 47 deletions
+37 -1
View File
@@ -22,10 +22,33 @@ OSRM::OSRM(engine::EngineConfig &config)
using CoreCH = engine::routing_algorithms::corech::Algorithm;
using MLD = engine::routing_algorithms::mld::Algorithm;
// First, check that necessary core data is available
if (!config.use_shared_memory && !config.storage_config.IsValid())
{
throw util::exception("Required files are missing, cannot continue. Have all the "
"pre-processing steps been run?");
}
else 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);
auto layout = reinterpret_cast<storage::DataLayout *>(mem->Ptr());
if (layout->GetBlockSize(storage::DataLayout::NAME_CHAR_DATA) == 0)
throw util::exception(
"No name data loaded, cannot continue. Have you run osrm-datastore to load data?");
}
// Now, check that the algorithm requested can be used with the data
// that's available.
if (config.algorithm == EngineConfig::Algorithm::CoreCH ||
config.algorithm == EngineConfig::Algorithm::CH)
{
bool corech_compatible = engine::Engine<CoreCH>::CheckCompability(config);
bool ch_compatible = engine::Engine<CH>::CheckCompability(config);
// Activate CoreCH if we can because it is faster
if (config.algorithm == EngineConfig::Algorithm::CH && corech_compatible)
@@ -33,13 +56,26 @@ OSRM::OSRM(engine::EngineConfig &config)
config.algorithm = EngineConfig::Algorithm::CoreCH;
}
// throw error if dataset is not usable with CoreCH
// throw error if dataset is not usable with CoreCH or CH
if (config.algorithm == EngineConfig::Algorithm::CoreCH && !corech_compatible)
{
throw util::RuntimeError("Dataset is not compatible with CoreCH.",
ErrorCode::IncompatibleDataset,
SOURCE_REF);
}
else 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>::CheckCompability(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)
+2 -10
View File
@@ -14,9 +14,9 @@ bool CheckFileList(const std::vector<boost::filesystem::path> &files)
bool success = true;
for (auto &path : files)
{
if (!boost::filesystem::is_regular_file(path))
if (!boost::filesystem::exists(path))
{
util::Log(logWARNING) << "Missing/Broken File: " << path.string();
util::Log(logERROR) << "Missing File: " << path.string();
success = false;
}
}
@@ -62,14 +62,6 @@ bool StorageConfig::IsValid() const
return false;
}
// TODO: add algorithm checks
// CH files
CheckFileList({hsgr_data_path, core_data_path});
// MLD files
CheckFileList({mld_partition_path, mld_storage_path, mld_graph_path});
return true;
}
}
+5 -21
View File
@@ -223,33 +223,17 @@ int main(int argc, const char *argv[]) try
{
config.storage_config = storage::StorageConfig(base_path);
}
if (!config.use_shared_memory && !config.storage_config.IsValid())
{
util::Log(logERROR) << "Required files are missing, cannot continue";
return EXIT_FAILURE;
}
if (!config.IsValid())
{
if (base_path.empty() != config.use_shared_memory)
{
util::Log(logWARNING) << "Path settings and shared memory conflicts.";
}
else
{
auto required_files = {config.storage_config.ram_index_path,
config.storage_config.file_index_path,
config.storage_config.hsgr_data_path,
config.storage_config.node_based_nodes_data_path,
config.storage_config.edge_based_nodes_data_path,
config.storage_config.edges_data_path,
config.storage_config.core_data_path,
config.storage_config.geometries_path,
config.storage_config.datasource_indexes_path,
config.storage_config.names_data_path,
config.storage_config.properties_path};
for (auto file : required_files)
{
if (!boost::filesystem::is_regular_file(file))
{
util::Log(logWARNING) << file << " is not found";
}
}
}
return EXIT_FAILURE;
}
config.algorithm = stringToAlgorithm(algorithm);