Skip to content

Commit

Permalink
Restore the connectivity checksum check
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarex committed Apr 6, 2018
1 parent fb1540e commit 8a7e392
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/engine/datafacade/mmap_memory_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ MMapMemoryAllocator::MMapMemoryAllocator(const storage::StorageConfig &config,
mapped_memory = util::mmapFile<char>(memory_file, mapped_memory_file);

storage::DataLayout layout;
storage::io::BufferReader reader(mapped_memory.data());
storage::io::BufferReader reader(mapped_memory.data(), mapped_memory.size());
storage::serialization::read(reader, layout);
auto layout_size = reader.GetPosition();

Expand Down
49 changes: 48 additions & 1 deletion src/storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,32 @@ int Storage::Run(int max_wait, const std::string &dataset_name, bool only_metric
std::vector<SharedDataIndex::AllocatedRegion> regions;
std::map<std::string, RegionHandle> handles;

if (!only_metric)
// We keep this handles to read-only regions
// that we don't update to be able to cross-validate
// data when loading it
std::vector<RegionHandle> readonly_handles;

if (only_metric)
{
auto region_id = shared_register.Find(dataset_name + "/static");
if (region_id == storage::SharedRegionRegister::INVALID_REGION_ID)
{
throw util::exception("Cannot update the metric to a dataset that does not exist yet.");
}
auto static_region = shared_register.GetRegion(region_id);
auto static_memory = makeSharedMemory(static_region.shm_key);

DataLayout static_layout;
io::BufferReader reader(reinterpret_cast<char *>(static_memory->Ptr()),
static_memory->Size());
serialization::read(reader, static_layout);
auto layout_size = reader.GetPosition();
auto *data_ptr = reinterpret_cast<char *>(static_memory->Ptr()) + layout_size;

regions.push_back({data_ptr, static_layout});
readonly_handles.push_back({std::move(static_memory), data_ptr, static_region.shm_key});
}
else
{
DataLayout static_layout;
PopulateStaticLayout(static_layout);
Expand Down Expand Up @@ -503,6 +528,17 @@ void Storage::PopulateUpdatableData(const SharedDataIndex &index)
std::uint32_t graph_connectivity_checksum = 0;
contractor::files::readGraph(
config.GetPath(".osrm.hsgr"), metrics, graph_connectivity_checksum);

auto turns_connectivity_checksum =
*index.GetBlockPtr<std::uint32_t>("/common/connectivity_checksum");
if (turns_connectivity_checksum != graph_connectivity_checksum)
{
throw util::exception(
"Connectivity checksum " + std::to_string(graph_connectivity_checksum) + " in " +
config.GetPath(".osrm.hsgr").string() + " does not equal to checksum " +
std::to_string(turns_connectivity_checksum) + " in " +
config.GetPath(".osrm.edges").string());
}
}

if (boost::filesystem::exists(config.GetPath(".osrm.cell_metrics")))
Expand All @@ -520,6 +556,17 @@ void Storage::PopulateUpdatableData(const SharedDataIndex &index)
std::uint32_t graph_connectivity_checksum = 0;
partitioner::files::readGraph(
config.GetPath(".osrm.mldgr"), graph_view, graph_connectivity_checksum);

auto turns_connectivity_checksum =
*index.GetBlockPtr<std::uint32_t>("/common/connectivity_checksum");
if (turns_connectivity_checksum != graph_connectivity_checksum)
{
throw util::exception(
"Connectivity checksum " + std::to_string(graph_connectivity_checksum) + " in " +
config.GetPath(".osrm.hsgr").string() + " does not equal to checksum " +
std::to_string(turns_connectivity_checksum) + " in " +
config.GetPath(".osrm.edges").string());
}
}
}
}
Expand Down

0 comments on commit 8a7e392

Please sign in to comment.