2015-01-27 06:35:29 -05:00
|
|
|
#ifndef SHARED_DATAFACADE_HPP
|
|
|
|
#define SHARED_DATAFACADE_HPP
|
|
|
|
|
|
|
|
// implements all data storage when shared memory _IS_ used
|
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "engine/datafacade/datafacade_base.hpp"
|
2016-01-07 13:19:55 -05:00
|
|
|
#include "storage/shared_datatype.hpp"
|
|
|
|
#include "storage/shared_memory.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
|
|
|
|
#include "engine/geospatial_query.hpp"
|
|
|
|
#include "util/range_table.hpp"
|
|
|
|
#include "util/static_graph.hpp"
|
|
|
|
#include "util/static_rtree.hpp"
|
|
|
|
#include "util/make_unique.hpp"
|
|
|
|
#include "util/simple_logger.hpp"
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-12-09 16:34:22 -05:00
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
2015-01-27 06:35:29 -05:00
|
|
|
#include <algorithm>
|
2015-02-26 04:11:33 -05:00
|
|
|
#include <limits>
|
2015-01-27 06:35:29 -05:00
|
|
|
#include <memory>
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
namespace datafacade
|
|
|
|
{
|
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<EdgeDataT>
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
2015-03-23 12:06:10 -04:00
|
|
|
using EdgeData = EdgeDataT;
|
|
|
|
using super = BaseDataFacade<EdgeData>;
|
2016-01-05 10:51:13 -05:00
|
|
|
using QueryGraph = util::StaticGraph<EdgeData, true>;
|
|
|
|
using GraphNode = typename QueryGraph::NodeArrayEntry;
|
|
|
|
using GraphEdge = typename QueryGraph::EdgeArrayEntry;
|
|
|
|
using NameIndexBlock = typename util::RangeTable<16, true>::BlockT;
|
2015-03-23 12:06:10 -04:00
|
|
|
using InputEdge = typename QueryGraph::InputEdge;
|
|
|
|
using RTreeLeaf = typename super::RTreeLeaf;
|
2016-01-07 19:31:57 -05:00
|
|
|
using SharedRTree =
|
|
|
|
util::StaticRTree<RTreeLeaf, util::ShM<util::FixedPointCoordinate, true>::vector, true>;
|
2015-12-03 14:04:23 -05:00
|
|
|
using SharedGeospatialQuery = GeospatialQuery<SharedRTree>;
|
2015-01-27 06:35:29 -05:00
|
|
|
using TimeStampedRTreePair = std::pair<unsigned, std::shared_ptr<SharedRTree>>;
|
|
|
|
using RTreeNode = typename SharedRTree::TreeNode;
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
storage::SharedDataLayout *data_layout;
|
2015-01-27 06:35:29 -05:00
|
|
|
char *shared_memory;
|
2016-01-07 13:19:55 -05:00
|
|
|
storage::SharedDataTimestamp *data_timestamp_ptr;
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
storage::SharedDataType CURRENT_LAYOUT;
|
|
|
|
storage::SharedDataType CURRENT_DATA;
|
2015-01-27 06:35:29 -05:00
|
|
|
unsigned CURRENT_TIMESTAMP;
|
|
|
|
|
|
|
|
unsigned m_check_sum;
|
|
|
|
std::unique_ptr<QueryGraph> m_query_graph;
|
2016-01-07 13:19:55 -05:00
|
|
|
std::unique_ptr<storage::SharedMemory> m_layout_memory;
|
|
|
|
std::unique_ptr<storage::SharedMemory> m_large_memory;
|
2015-01-27 06:35:29 -05:00
|
|
|
std::string m_timestamp;
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
std::shared_ptr<util::ShM<util::FixedPointCoordinate, true>::vector> m_coordinate_list;
|
|
|
|
util::ShM<NodeID, true>::vector m_via_node_list;
|
|
|
|
util::ShM<unsigned, true>::vector m_name_ID_list;
|
|
|
|
util::ShM<extractor::TurnInstruction, true>::vector m_turn_instruction_list;
|
|
|
|
util::ShM<extractor::TravelMode, true>::vector m_travel_mode_list;
|
|
|
|
util::ShM<char, true>::vector m_names_char_list;
|
|
|
|
util::ShM<unsigned, true>::vector m_name_begin_indices;
|
|
|
|
util::ShM<bool, true>::vector m_edge_is_compressed;
|
|
|
|
util::ShM<unsigned, true>::vector m_geometry_indices;
|
|
|
|
util::ShM<unsigned, true>::vector m_geometry_list;
|
|
|
|
util::ShM<bool, true>::vector m_is_core_node;
|
2015-01-27 06:35:29 -05:00
|
|
|
|
|
|
|
boost::thread_specific_ptr<std::pair<unsigned, std::shared_ptr<SharedRTree>>> m_static_rtree;
|
2015-12-03 14:04:23 -05:00
|
|
|
boost::thread_specific_ptr<SharedGeospatialQuery> m_geospatial_query;
|
2015-01-27 06:35:29 -05:00
|
|
|
boost::filesystem::path file_index_path;
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
std::shared_ptr<util::RangeTable<16, true>> m_name_table;
|
2015-01-27 06:35:29 -05:00
|
|
|
|
|
|
|
void LoadChecksum()
|
|
|
|
{
|
2016-01-21 07:07:24 -05:00
|
|
|
m_check_sum = *data_layout->GetBlockPtr<unsigned>(shared_memory,
|
|
|
|
storage::SharedDataLayout::HSGR_CHECKSUM);
|
2016-01-05 10:51:13 -05:00
|
|
|
util::SimpleLogger().Write() << "set checksum: " << m_check_sum;
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadTimestamp()
|
|
|
|
{
|
2016-01-25 23:10:50 -05:00
|
|
|
auto timestamp_ptr =
|
2016-01-07 13:19:55 -05:00
|
|
|
data_layout->GetBlockPtr<char>(shared_memory, storage::SharedDataLayout::TIMESTAMP);
|
|
|
|
m_timestamp.resize(data_layout->GetBlockSize(storage::SharedDataLayout::TIMESTAMP));
|
2015-01-27 06:35:29 -05:00
|
|
|
std::copy(timestamp_ptr,
|
2016-01-07 13:19:55 -05:00
|
|
|
timestamp_ptr + data_layout->GetBlockSize(storage::SharedDataLayout::TIMESTAMP),
|
2015-01-27 06:35:29 -05:00
|
|
|
m_timestamp.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadRTree()
|
|
|
|
{
|
|
|
|
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto tree_ptr = data_layout->GetBlockPtr<RTreeNode>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::R_SEARCH_TREE);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_static_rtree.reset(new TimeStampedRTreePair(
|
|
|
|
CURRENT_TIMESTAMP,
|
2016-01-05 10:51:13 -05:00
|
|
|
util::make_unique<SharedRTree>(
|
2016-01-07 13:19:55 -05:00
|
|
|
tree_ptr, data_layout->num_entries[storage::SharedDataLayout::R_SEARCH_TREE],
|
2015-01-27 06:35:29 -05:00
|
|
|
file_index_path, m_coordinate_list)));
|
2016-01-05 06:04:04 -05:00
|
|
|
m_geospatial_query.reset(
|
|
|
|
new SharedGeospatialQuery(*m_static_rtree->second, m_coordinate_list));
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadGraph()
|
|
|
|
{
|
2016-01-25 23:10:50 -05:00
|
|
|
auto graph_nodes_ptr = data_layout->GetBlockPtr<GraphNode>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::GRAPH_NODE_LIST);
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto graph_edges_ptr = data_layout->GetBlockPtr<GraphEdge>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::GRAPH_EDGE_LIST);
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<GraphNode, true>::vector node_list(
|
2016-01-07 13:19:55 -05:00
|
|
|
graph_nodes_ptr, data_layout->num_entries[storage::SharedDataLayout::GRAPH_NODE_LIST]);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<GraphEdge, true>::vector edge_list(
|
2016-01-07 13:19:55 -05:00
|
|
|
graph_edges_ptr, data_layout->num_entries[storage::SharedDataLayout::GRAPH_EDGE_LIST]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_query_graph.reset(new QueryGraph(node_list, edge_list));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadNodeAndEdgeInformation()
|
|
|
|
{
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto coordinate_list_ptr =
|
2016-01-21 07:07:24 -05:00
|
|
|
data_layout->GetBlockPtr<util::FixedPointCoordinate>(
|
|
|
|
shared_memory, storage::SharedDataLayout::COORDINATE_LIST);
|
2016-01-05 10:51:13 -05:00
|
|
|
m_coordinate_list = util::make_unique<util::ShM<util::FixedPointCoordinate, true>::vector>(
|
2016-01-21 07:07:24 -05:00
|
|
|
coordinate_list_ptr,
|
|
|
|
data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto travel_mode_list_ptr =
|
2016-01-07 19:31:57 -05:00
|
|
|
data_layout->GetBlockPtr<extractor::TravelMode>(shared_memory,
|
2016-01-07 13:19:55 -05:00
|
|
|
storage::SharedDataLayout::TRAVEL_MODE);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<extractor::TravelMode, true>::vector travel_mode_list(
|
2016-01-07 13:19:55 -05:00
|
|
|
travel_mode_list_ptr, data_layout->num_entries[storage::SharedDataLayout::TRAVEL_MODE]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_travel_mode_list.swap(travel_mode_list);
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto turn_instruction_list_ptr =
|
2016-01-07 19:31:57 -05:00
|
|
|
data_layout->GetBlockPtr<extractor::TurnInstruction>(
|
2016-01-07 13:19:55 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::TURN_INSTRUCTION);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<extractor::TurnInstruction, true>::vector turn_instruction_list(
|
2015-01-27 06:35:29 -05:00
|
|
|
turn_instruction_list_ptr,
|
2016-01-07 13:19:55 -05:00
|
|
|
data_layout->num_entries[storage::SharedDataLayout::TURN_INSTRUCTION]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_turn_instruction_list.swap(turn_instruction_list);
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto name_id_list_ptr = data_layout->GetBlockPtr<unsigned>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::NAME_ID_LIST);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<unsigned, true>::vector name_id_list(
|
2016-01-07 13:19:55 -05:00
|
|
|
name_id_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_ID_LIST]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_name_ID_list.swap(name_id_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadViaNodeList()
|
|
|
|
{
|
2016-01-25 23:10:50 -05:00
|
|
|
auto via_node_list_ptr = data_layout->GetBlockPtr<NodeID>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::VIA_NODE_LIST);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<NodeID, true>::vector via_node_list(
|
2016-01-07 13:19:55 -05:00
|
|
|
via_node_list_ptr, data_layout->num_entries[storage::SharedDataLayout::VIA_NODE_LIST]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_via_node_list.swap(via_node_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadNames()
|
|
|
|
{
|
2016-01-25 23:10:50 -05:00
|
|
|
auto offsets_ptr = data_layout->GetBlockPtr<unsigned>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::NAME_OFFSETS);
|
2016-01-25 23:10:50 -05:00
|
|
|
auto blocks_ptr = data_layout->GetBlockPtr<NameIndexBlock>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::NAME_BLOCKS);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<unsigned, true>::vector name_offsets(
|
2016-01-07 13:19:55 -05:00
|
|
|
offsets_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_OFFSETS]);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<NameIndexBlock, true>::vector name_blocks(
|
2016-01-07 13:19:55 -05:00
|
|
|
blocks_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_BLOCKS]);
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto names_list_ptr = data_layout->GetBlockPtr<char>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::NAME_CHAR_LIST);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<char, true>::vector names_char_list(
|
2016-01-07 13:19:55 -05:00
|
|
|
names_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_CHAR_LIST]);
|
2016-01-05 10:51:13 -05:00
|
|
|
m_name_table = util::make_unique<util::RangeTable<16, true>>(
|
2015-01-27 06:35:29 -05:00
|
|
|
name_offsets, name_blocks, static_cast<unsigned>(names_char_list.size()));
|
|
|
|
|
|
|
|
m_names_char_list.swap(names_char_list);
|
|
|
|
}
|
|
|
|
|
2015-08-19 05:44:49 -04:00
|
|
|
void LoadCoreInformation()
|
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
if (data_layout->num_entries[storage::SharedDataLayout::CORE_MARKER] <= 0)
|
2015-08-19 05:44:49 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto core_marker_ptr = data_layout->GetBlockPtr<unsigned>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::CORE_MARKER);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<bool, true>::vector is_core_node(
|
2016-01-07 13:19:55 -05:00
|
|
|
core_marker_ptr, data_layout->num_entries[storage::SharedDataLayout::CORE_MARKER]);
|
2015-08-19 05:44:49 -04:00
|
|
|
m_is_core_node.swap(is_core_node);
|
|
|
|
}
|
|
|
|
|
2015-01-27 06:35:29 -05:00
|
|
|
void LoadGeometries()
|
|
|
|
{
|
2016-01-25 23:10:50 -05:00
|
|
|
auto geometries_compressed_ptr = data_layout->GetBlockPtr<unsigned>(
|
2016-01-07 13:19:55 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::GEOMETRIES_INDICATORS);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<bool, true>::vector edge_is_compressed(
|
2015-01-27 06:35:29 -05:00
|
|
|
geometries_compressed_ptr,
|
2016-01-07 13:19:55 -05:00
|
|
|
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDICATORS]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_edge_is_compressed.swap(edge_is_compressed);
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto geometries_index_ptr = data_layout->GetBlockPtr<unsigned>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::GEOMETRIES_INDEX);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<unsigned, true>::vector geometry_begin_indices(
|
2016-01-21 07:07:24 -05:00
|
|
|
geometries_index_ptr,
|
|
|
|
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDEX]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_geometry_indices.swap(geometry_begin_indices);
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
auto geometries_list_ptr = data_layout->GetBlockPtr<unsigned>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST);
|
2016-01-05 10:51:13 -05:00
|
|
|
typename util::ShM<unsigned, true>::vector geometry_list(
|
2016-01-21 07:07:24 -05:00
|
|
|
geometries_list_ptr,
|
|
|
|
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]);
|
2015-01-27 06:35:29 -05:00
|
|
|
m_geometry_list.swap(geometry_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SharedDataFacade() {}
|
|
|
|
|
2016-01-15 03:57:36 -05:00
|
|
|
boost::shared_mutex data_mutex;
|
|
|
|
|
2015-01-27 06:35:29 -05:00
|
|
|
SharedDataFacade()
|
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
if (!storage::SharedMemory::RegionExists(storage::CURRENT_REGIONS))
|
2016-01-13 20:42:50 -05:00
|
|
|
{
|
2016-01-21 07:07:24 -05:00
|
|
|
throw util::exception(
|
|
|
|
"No shared memory blocks found, have you forgotten to run osrm-datastore?");
|
2016-01-13 20:42:50 -05:00
|
|
|
}
|
2016-01-07 13:19:55 -05:00
|
|
|
data_timestamp_ptr = static_cast<storage::SharedDataTimestamp *>(
|
|
|
|
storage::makeSharedMemory(storage::CURRENT_REGIONS,
|
2016-01-25 23:10:50 -05:00
|
|
|
sizeof(storage::SharedDataTimestamp), false, false)
|
|
|
|
->Ptr());
|
2016-01-07 13:19:55 -05:00
|
|
|
CURRENT_LAYOUT = storage::LAYOUT_NONE;
|
|
|
|
CURRENT_DATA = storage::DATA_NONE;
|
2015-01-27 06:35:29 -05:00
|
|
|
CURRENT_TIMESTAMP = 0;
|
|
|
|
|
|
|
|
// load data
|
|
|
|
CheckAndReloadFacade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckAndReloadFacade()
|
|
|
|
{
|
|
|
|
if (CURRENT_LAYOUT != data_timestamp_ptr->layout ||
|
2016-01-15 03:57:36 -05:00
|
|
|
CURRENT_DATA != data_timestamp_ptr->data ||
|
|
|
|
CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp)
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
2016-01-15 03:57:36 -05:00
|
|
|
// Get exclusive lock
|
|
|
|
util::SimpleLogger().Write(logDEBUG) << "Updates available, getting exclusive lock";
|
|
|
|
boost::unique_lock<boost::shared_mutex> lock(data_mutex);
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-15 03:57:36 -05:00
|
|
|
if (CURRENT_LAYOUT != data_timestamp_ptr->layout ||
|
|
|
|
CURRENT_DATA != data_timestamp_ptr->data)
|
|
|
|
{
|
|
|
|
// release the previous shared memory segments
|
2016-01-07 13:19:55 -05:00
|
|
|
storage::SharedMemory::Remove(CURRENT_LAYOUT);
|
|
|
|
storage::SharedMemory::Remove(CURRENT_DATA);
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-15 03:57:36 -05:00
|
|
|
CURRENT_LAYOUT = data_timestamp_ptr->layout;
|
|
|
|
CURRENT_DATA = data_timestamp_ptr->data;
|
2016-01-21 07:07:24 -05:00
|
|
|
CURRENT_TIMESTAMP = 0; // Force trigger a reload
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-21 07:07:24 -05:00
|
|
|
util::SimpleLogger().Write(logDEBUG)
|
|
|
|
<< "Current layout was different to new layout, swapping";
|
2016-01-15 03:57:36 -05:00
|
|
|
}
|
|
|
|
else
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
2016-01-21 07:07:24 -05:00
|
|
|
util::SimpleLogger().Write(logDEBUG)
|
|
|
|
<< "Current layout was same to new layout, not swapping";
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
2016-01-15 03:57:36 -05:00
|
|
|
if (CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp)
|
|
|
|
{
|
|
|
|
CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp;
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-15 03:57:36 -05:00
|
|
|
util::SimpleLogger().Write(logDEBUG) << "Performing data reload";
|
2016-01-07 13:19:55 -05:00
|
|
|
m_layout_memory.reset(storage::makeSharedMemory(CURRENT_LAYOUT));
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2016-01-26 10:53:48 -05:00
|
|
|
data_layout = static_cast<storage::SharedDataLayout*>(m_layout_memory->Ptr());
|
2016-01-15 03:57:36 -05:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
m_large_memory.reset(storage::makeSharedMemory(CURRENT_DATA));
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory = (char *)(m_large_memory->Ptr());
|
2016-01-15 03:57:36 -05:00
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
const auto file_index_ptr = data_layout->GetBlockPtr<char>(
|
2016-01-21 07:07:24 -05:00
|
|
|
shared_memory, storage::SharedDataLayout::FILE_INDEX_PATH);
|
2016-01-15 03:57:36 -05:00
|
|
|
file_index_path = boost::filesystem::path(file_index_ptr);
|
2016-01-21 07:07:24 -05:00
|
|
|
if (!boost::filesystem::exists(file_index_path))
|
|
|
|
{
|
2016-01-15 03:57:36 -05:00
|
|
|
util::SimpleLogger().Write(logDEBUG) << "Leaf file name "
|
2016-01-21 07:07:24 -05:00
|
|
|
<< file_index_path.string();
|
2016-01-15 03:57:36 -05:00
|
|
|
throw util::exception("Could not load leaf index file. "
|
2016-01-21 07:07:24 -05:00
|
|
|
"Is any data loaded into shared memory?");
|
2016-01-15 03:57:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
LoadGraph();
|
|
|
|
LoadChecksum();
|
|
|
|
LoadNodeAndEdgeInformation();
|
|
|
|
LoadGeometries();
|
|
|
|
LoadTimestamp();
|
|
|
|
LoadViaNodeList();
|
|
|
|
LoadNames();
|
|
|
|
LoadCoreInformation();
|
|
|
|
|
2016-01-25 23:10:50 -05:00
|
|
|
util::SimpleLogger().Write() << "number of geometries: "
|
|
|
|
<< m_coordinate_list->size();
|
2016-01-15 03:57:36 -05:00
|
|
|
for (unsigned i = 0; i < m_coordinate_list->size(); ++i)
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
2016-01-15 03:57:36 -05:00
|
|
|
if (!GetCoordinateOfNode(i).IsValid())
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write() << "coordinate " << i << " not valid";
|
|
|
|
}
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
}
|
2016-01-15 03:57:36 -05:00
|
|
|
util::SimpleLogger().Write(logDEBUG) << "Releasing exclusive lock";
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// search graph access
|
2015-01-28 04:10:28 -05:00
|
|
|
unsigned GetNumberOfNodes() const override final { return m_query_graph->GetNumberOfNodes(); }
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
unsigned GetNumberOfEdges() const override final { return m_query_graph->GetNumberOfEdges(); }
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
unsigned GetOutDegree(const NodeID n) const override final
|
|
|
|
{
|
|
|
|
return m_query_graph->GetOutDegree(n);
|
|
|
|
}
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
NodeID GetTarget(const EdgeID e) const override final { return m_query_graph->GetTarget(e); }
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
EdgeDataT &GetEdgeData(const EdgeID e) const override final
|
|
|
|
{
|
|
|
|
return m_query_graph->GetEdgeData(e);
|
|
|
|
}
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
EdgeID BeginEdges(const NodeID n) const override final { return m_query_graph->BeginEdges(n); }
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
EdgeID EndEdges(const NodeID n) const override final { return m_query_graph->EndEdges(n); }
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
EdgeRange GetAdjacentEdgeRange(const NodeID node) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_query_graph->GetAdjacentEdgeRange(node);
|
|
|
|
};
|
|
|
|
|
|
|
|
// searches for a specific edge
|
2015-01-28 04:10:28 -05:00
|
|
|
EdgeID FindEdge(const NodeID from, const NodeID to) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_query_graph->FindEdge(from, to);
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_query_graph->FindEdgeInEitherDirection(from, to);
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
EdgeID
|
|
|
|
FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_query_graph->FindEdgeIndicateIfReverse(from, to, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// node and edge information access
|
2016-01-05 10:51:13 -05:00
|
|
|
util::FixedPointCoordinate GetCoordinateOfNode(const NodeID id) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_coordinate_list->at(id);
|
|
|
|
};
|
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
virtual bool EdgeIsCompressed(const unsigned id) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_edge_is_compressed.at(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetUncompressedGeometry(const unsigned id,
|
2015-01-28 04:10:28 -05:00
|
|
|
std::vector<unsigned> &result_nodes) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
const unsigned begin = m_geometry_indices.at(id);
|
|
|
|
const unsigned end = m_geometry_indices.at(id + 1);
|
|
|
|
|
|
|
|
result_nodes.clear();
|
|
|
|
result_nodes.insert(result_nodes.begin(), m_geometry_list.begin() + begin,
|
|
|
|
m_geometry_list.begin() + end);
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_via_node_list.at(id);
|
|
|
|
}
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
extractor::TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_turn_instruction_list.at(id);
|
|
|
|
}
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
extractor::TravelMode GetTravelModeForEdgeID(const unsigned id) const override final
|
2015-02-05 08:58:07 -05:00
|
|
|
{
|
|
|
|
return m_travel_mode_list.at(id);
|
|
|
|
}
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-12-09 16:34:22 -05:00
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-01-21 07:07:24 -05:00
|
|
|
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
|
2015-12-03 14:04:23 -05:00
|
|
|
const float max_distance,
|
|
|
|
const int bearing = 0,
|
|
|
|
const int bearing_range = 180) override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
|
|
|
|
{
|
|
|
|
LoadRTree();
|
2015-12-03 14:04:23 -05:00
|
|
|
BOOST_ASSERT(m_geospatial_query.get());
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance,
|
|
|
|
bearing, bearing_range);
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
2015-12-09 16:34:22 -05:00
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-01-21 07:07:24 -05:00
|
|
|
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
|
2015-12-03 14:04:23 -05:00
|
|
|
const unsigned max_results,
|
|
|
|
const int bearing = 0,
|
|
|
|
const int bearing_range = 180) override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
|
|
|
|
{
|
|
|
|
LoadRTree();
|
2015-12-03 14:04:23 -05:00
|
|
|
BOOST_ASSERT(m_geospatial_query.get());
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing,
|
|
|
|
bearing_range);
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:31:57 -05:00
|
|
|
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
|
2016-01-21 07:07:24 -05:00
|
|
|
const util::FixedPointCoordinate input_coordinate,
|
2016-01-07 19:31:57 -05:00
|
|
|
const int bearing = 0,
|
|
|
|
const int bearing_range = 180) override final
|
2014-09-23 12:46:14 -04:00
|
|
|
{
|
|
|
|
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
|
|
|
|
{
|
|
|
|
LoadRTree();
|
2015-12-03 14:04:23 -05:00
|
|
|
BOOST_ASSERT(m_geospatial_query.get());
|
2014-09-23 12:46:14 -04:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
|
|
|
|
input_coordinate, bearing, bearing_range);
|
2014-09-23 12:46:14 -04:00
|
|
|
}
|
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
unsigned GetCheckSum() const override final { return m_check_sum; }
|
2015-01-27 06:35:29 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
unsigned GetNameIndexFromEdgeID(const unsigned id) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
|
|
|
return m_name_ID_list.at(id);
|
|
|
|
};
|
|
|
|
|
2015-02-26 04:11:33 -05:00
|
|
|
std::string get_name_for_id(const unsigned name_id) const override final
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
2015-02-26 04:11:33 -05:00
|
|
|
if (std::numeric_limits<unsigned>::max() == name_id)
|
2015-01-27 06:35:29 -05:00
|
|
|
{
|
2015-02-26 04:11:33 -05:00
|
|
|
return "";
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
auto range = m_name_table->GetRange(name_id);
|
|
|
|
|
2015-02-26 04:11:33 -05:00
|
|
|
std::string result;
|
|
|
|
result.reserve(range.size());
|
2015-01-27 06:35:29 -05:00
|
|
|
if (range.begin() != range.end())
|
|
|
|
{
|
|
|
|
result.resize(range.back() - range.front() + 1);
|
|
|
|
std::copy(m_names_char_list.begin() + range.front(),
|
|
|
|
m_names_char_list.begin() + range.back() + 1, result.begin());
|
|
|
|
}
|
2015-02-26 04:11:33 -05:00
|
|
|
return result;
|
2015-01-27 06:35:29 -05:00
|
|
|
}
|
|
|
|
|
2015-08-09 12:31:11 -04:00
|
|
|
bool IsCoreNode(const NodeID id) const override final
|
|
|
|
{
|
2015-08-19 05:44:49 -04:00
|
|
|
if (m_is_core_node.size() > 0)
|
|
|
|
{
|
|
|
|
return m_is_core_node.at(id);
|
|
|
|
}
|
|
|
|
|
2015-08-09 12:31:11 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
virtual std::size_t GetCoreSize() const override final { return m_is_core_node.size(); }
|
2015-11-25 15:45:09 -05:00
|
|
|
|
2015-01-28 04:10:28 -05:00
|
|
|
std::string GetTimestamp() const override final { return m_timestamp; }
|
2015-01-27 06:35:29 -05:00
|
|
|
};
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 06:35:29 -05:00
|
|
|
#endif // SHARED_DATAFACADE_HPP
|