Make DataFacade local to every request
This is the first step to having fine grained locking on data updates, see issue #2570.
This commit is contained in:
committed by
Patrick Niklaus
parent
66f2cc5184
commit
1c2ead8fb8
+19
-26
@@ -15,7 +15,6 @@
|
||||
#include "engine/datafacade/shared_datafacade.hpp"
|
||||
|
||||
#include "storage/shared_barriers.hpp"
|
||||
#include "util/make_unique.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
@@ -86,37 +85,31 @@ namespace
|
||||
// Works the same for every plugin.
|
||||
template <typename ParameterT, typename PluginT, typename ResultT>
|
||||
osrm::engine::Status RunQuery(const std::unique_ptr<osrm::engine::Engine::EngineLock> &lock,
|
||||
osrm::engine::datafacade::BaseDataFacade &facade,
|
||||
const std::shared_ptr<osrm::engine::datafacade::BaseDataFacade> &facade,
|
||||
const ParameterT ¶meters,
|
||||
PluginT &plugin,
|
||||
ResultT &result)
|
||||
{
|
||||
if (!lock)
|
||||
{
|
||||
return plugin.HandleRequest(parameters, result);
|
||||
return plugin.HandleRequest(facade, parameters, result);
|
||||
}
|
||||
|
||||
BOOST_ASSERT(lock);
|
||||
lock->IncreaseQueryCount();
|
||||
|
||||
auto &shared_facade = static_cast<osrm::engine::datafacade::SharedDataFacade &>(facade);
|
||||
auto &shared_facade = static_cast<osrm::engine::datafacade::SharedDataFacade &>(*facade);
|
||||
shared_facade.CheckAndReloadFacade();
|
||||
// Get a shared data lock so that other threads won't update
|
||||
// things while the query is running
|
||||
boost::shared_lock<boost::shared_mutex> data_lock{shared_facade.data_mutex};
|
||||
|
||||
osrm::engine::Status status = plugin.HandleRequest(parameters, result);
|
||||
osrm::engine::Status status = plugin.HandleRequest(facade, parameters, result);
|
||||
|
||||
lock->DecreaseQueryCount();
|
||||
return status;
|
||||
}
|
||||
|
||||
template <typename Plugin, typename Facade, typename... Args>
|
||||
std::unique_ptr<Plugin> create(Facade &facade, Args... args)
|
||||
{
|
||||
return osrm::util::make_unique<Plugin>(facade, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
} // anon. ns
|
||||
|
||||
namespace osrm
|
||||
@@ -128,8 +121,8 @@ Engine::Engine(const EngineConfig &config)
|
||||
{
|
||||
if (config.use_shared_memory)
|
||||
{
|
||||
lock = util::make_unique<EngineLock>();
|
||||
query_data_facade = util::make_unique<datafacade::SharedDataFacade>();
|
||||
lock = std::make_unique<EngineLock>();
|
||||
query_data_facade = std::make_shared<datafacade::SharedDataFacade>();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -138,18 +131,18 @@ Engine::Engine(const EngineConfig &config)
|
||||
throw util::exception("Invalid file paths given!");
|
||||
}
|
||||
query_data_facade =
|
||||
util::make_unique<datafacade::InternalDataFacade>(config.storage_config);
|
||||
std::make_shared<datafacade::InternalDataFacade>(config.storage_config);
|
||||
}
|
||||
|
||||
// Register plugins
|
||||
using namespace plugins;
|
||||
|
||||
route_plugin = create<ViaRoutePlugin>(*query_data_facade, config.max_locations_viaroute);
|
||||
table_plugin = create<TablePlugin>(*query_data_facade, config.max_locations_distance_table);
|
||||
nearest_plugin = create<NearestPlugin>(*query_data_facade, config.max_results_nearest);
|
||||
trip_plugin = create<TripPlugin>(*query_data_facade, config.max_locations_trip);
|
||||
match_plugin = create<MatchPlugin>(*query_data_facade, config.max_locations_map_matching);
|
||||
tile_plugin = create<TilePlugin>(*query_data_facade);
|
||||
route_plugin = std::make_unique<ViaRoutePlugin>(config.max_locations_viaroute);
|
||||
table_plugin = std::make_unique<TablePlugin>(config.max_locations_distance_table);
|
||||
nearest_plugin = std::make_unique<NearestPlugin>(config.max_results_nearest);
|
||||
trip_plugin = std::make_unique<TripPlugin>(config.max_locations_trip);
|
||||
match_plugin = std::make_unique<MatchPlugin>(config.max_locations_map_matching);
|
||||
tile_plugin = std::make_unique<TilePlugin>();
|
||||
}
|
||||
|
||||
// make sure we deallocate the unique ptr at a position where we know the size of the plugins
|
||||
@@ -159,32 +152,32 @@ Engine &Engine::operator=(Engine &&) noexcept = default;
|
||||
|
||||
Status Engine::Route(const api::RouteParameters ¶ms, util::json::Object &result) const
|
||||
{
|
||||
return RunQuery(lock, *query_data_facade, params, *route_plugin, result);
|
||||
return RunQuery(lock, query_data_facade, params, *route_plugin, result);
|
||||
}
|
||||
|
||||
Status Engine::Table(const api::TableParameters ¶ms, util::json::Object &result) const
|
||||
{
|
||||
return RunQuery(lock, *query_data_facade, params, *table_plugin, result);
|
||||
return RunQuery(lock, query_data_facade, params, *table_plugin, result);
|
||||
}
|
||||
|
||||
Status Engine::Nearest(const api::NearestParameters ¶ms, util::json::Object &result) const
|
||||
{
|
||||
return RunQuery(lock, *query_data_facade, params, *nearest_plugin, result);
|
||||
return RunQuery(lock, query_data_facade, params, *nearest_plugin, result);
|
||||
}
|
||||
|
||||
Status Engine::Trip(const api::TripParameters ¶ms, util::json::Object &result) const
|
||||
{
|
||||
return RunQuery(lock, *query_data_facade, params, *trip_plugin, result);
|
||||
return RunQuery(lock, query_data_facade, params, *trip_plugin, result);
|
||||
}
|
||||
|
||||
Status Engine::Match(const api::MatchParameters ¶ms, util::json::Object &result) const
|
||||
{
|
||||
return RunQuery(lock, *query_data_facade, params, *match_plugin, result);
|
||||
return RunQuery(lock, query_data_facade, params, *match_plugin, result);
|
||||
}
|
||||
|
||||
Status Engine::Tile(const api::TileParameters ¶ms, std::string &result) const
|
||||
{
|
||||
return RunQuery(lock, *query_data_facade, params, *tile_plugin, result);
|
||||
return RunQuery(lock, query_data_facade, params, *tile_plugin, result);
|
||||
}
|
||||
|
||||
} // engine ns
|
||||
|
||||
@@ -105,7 +105,8 @@ void filterCandidates(const std::vector<util::Coordinate> &coordinates,
|
||||
}
|
||||
}
|
||||
|
||||
Status MatchPlugin::HandleRequest(const api::MatchParameters ¶meters,
|
||||
Status MatchPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
|
||||
const api::MatchParameters ¶meters,
|
||||
util::json::Object &json_result)
|
||||
{
|
||||
BOOST_ASSERT(parameters.IsValid());
|
||||
@@ -150,7 +151,7 @@ Status MatchPlugin::HandleRequest(const api::MatchParameters ¶meters,
|
||||
});
|
||||
}
|
||||
|
||||
auto candidates_lists = GetPhantomNodesInRange(parameters, search_radiuses);
|
||||
auto candidates_lists = GetPhantomNodesInRange(*facade, parameters, search_radiuses);
|
||||
|
||||
filterCandidates(parameters.coordinates, candidates_lists);
|
||||
if (std::all_of(candidates_lists.begin(),
|
||||
@@ -165,7 +166,7 @@ Status MatchPlugin::HandleRequest(const api::MatchParameters ¶meters,
|
||||
}
|
||||
|
||||
// call the actual map matching
|
||||
SubMatchingList sub_matchings = map_matching(
|
||||
SubMatchingList sub_matchings = map_matching(*facade,
|
||||
candidates_lists, parameters.coordinates, parameters.timestamps, parameters.radiuses);
|
||||
|
||||
if (sub_matchings.size() == 0)
|
||||
@@ -192,11 +193,11 @@ Status MatchPlugin::HandleRequest(const api::MatchParameters ¶meters,
|
||||
// force uturns to be on, since we split the phantom nodes anyway and only have
|
||||
// bi-directional
|
||||
// phantom nodes for possible uturns
|
||||
shortest_path(sub_routes[index].segment_end_coordinates, {false}, sub_routes[index]);
|
||||
shortest_path(*facade, sub_routes[index].segment_end_coordinates, {false}, sub_routes[index]);
|
||||
BOOST_ASSERT(sub_routes[index].shortest_path_length != INVALID_EDGE_WEIGHT);
|
||||
}
|
||||
|
||||
api::MatchAPI match_api{BasePlugin::facade, parameters};
|
||||
api::MatchAPI match_api{*facade, parameters};
|
||||
match_api.MakeResponse(sub_matchings, sub_routes, json_result);
|
||||
|
||||
return Status::Ok;
|
||||
|
||||
@@ -17,13 +17,14 @@ namespace engine
|
||||
namespace plugins
|
||||
{
|
||||
|
||||
NearestPlugin::NearestPlugin(datafacade::BaseDataFacade &facade, const int max_results_)
|
||||
: BasePlugin{facade}, max_results{max_results_}
|
||||
NearestPlugin::NearestPlugin(const int max_results_)
|
||||
: max_results{max_results_}
|
||||
{
|
||||
}
|
||||
|
||||
Status NearestPlugin::HandleRequest(const api::NearestParameters ¶ms,
|
||||
util::json::Object &json_result)
|
||||
Status NearestPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
|
||||
const api::NearestParameters ¶ms,
|
||||
util::json::Object &json_result) const
|
||||
{
|
||||
BOOST_ASSERT(params.IsValid());
|
||||
|
||||
@@ -44,7 +45,7 @@ Status NearestPlugin::HandleRequest(const api::NearestParameters ¶ms,
|
||||
return Error("InvalidOptions", "Only one input coordinate is supported", json_result);
|
||||
}
|
||||
|
||||
auto phantom_nodes = GetPhantomNodes(params, params.number_of_results);
|
||||
auto phantom_nodes = GetPhantomNodes(*facade, params, params.number_of_results);
|
||||
|
||||
if (phantom_nodes.front().size() == 0)
|
||||
{
|
||||
@@ -52,7 +53,7 @@ Status NearestPlugin::HandleRequest(const api::NearestParameters ¶ms,
|
||||
}
|
||||
BOOST_ASSERT(phantom_nodes.front().size() > 0);
|
||||
|
||||
api::NearestAPI nearest_api(facade, params);
|
||||
api::NearestAPI nearest_api(*facade, params);
|
||||
nearest_api.MakeResponse(phantom_nodes, json_result);
|
||||
|
||||
return Status::Ok;
|
||||
|
||||
@@ -23,13 +23,15 @@ namespace engine
|
||||
namespace plugins
|
||||
{
|
||||
|
||||
TablePlugin::TablePlugin(datafacade::BaseDataFacade &facade, const int max_locations_distance_table)
|
||||
: BasePlugin{facade}, distance_table(&facade, heaps),
|
||||
TablePlugin::TablePlugin(const int max_locations_distance_table)
|
||||
: distance_table(heaps),
|
||||
max_locations_distance_table(max_locations_distance_table)
|
||||
{
|
||||
}
|
||||
|
||||
Status TablePlugin::HandleRequest(const api::TableParameters ¶ms, util::json::Object &result)
|
||||
Status TablePlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
|
||||
const api::TableParameters ¶ms,
|
||||
util::json::Object &result)
|
||||
{
|
||||
BOOST_ASSERT(params.IsValid());
|
||||
|
||||
@@ -58,15 +60,15 @@ Status TablePlugin::HandleRequest(const api::TableParameters ¶ms, util::json
|
||||
return Error("TooBig", "Too many table coordinates", result);
|
||||
}
|
||||
|
||||
auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(params));
|
||||
auto result_table = distance_table(snapped_phantoms, params.sources, params.destinations);
|
||||
auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(*facade, params));
|
||||
auto result_table = distance_table(*facade, snapped_phantoms, params.sources, params.destinations);
|
||||
|
||||
if (result_table.empty())
|
||||
{
|
||||
return Error("NoTable", "No table found", result);
|
||||
}
|
||||
|
||||
api::TableAPI table_api{facade, params};
|
||||
api::TableAPI table_api{*facade, params};
|
||||
table_api.MakeResponse(result_table, snapped_phantoms, result);
|
||||
|
||||
return Status::Ok;
|
||||
|
||||
+28
-26
@@ -269,7 +269,9 @@ void UnpackEdgeToEdges(const datafacade::BaseDataFacade &facade,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::string &pbf_buffer)
|
||||
Status TilePlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
|
||||
const api::TileParameters ¶meters,
|
||||
std::string &pbf_buffer) const
|
||||
{
|
||||
BOOST_ASSERT(parameters.IsValid());
|
||||
|
||||
@@ -284,7 +286,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
|
||||
// Fetch all the segments that are in our bounding box.
|
||||
// This hits the OSRM StaticRTree
|
||||
const auto edges = facade.GetEdgesInBox(southwest, northeast);
|
||||
const auto edges = facade->GetEdgesInBox(southwest, northeast);
|
||||
|
||||
// Vector tiles encode properties as references to a common lookup table.
|
||||
// When we add a property to a "feature", we actually attach the index of the value
|
||||
@@ -467,7 +469,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
{
|
||||
// Grab a copy of the geometry leading up to the intersection.
|
||||
first_geometry.clear();
|
||||
facade.GetUncompressedGeometry(source_ebn.second.packed_geometry_id, first_geometry);
|
||||
facade->GetUncompressedGeometry(source_ebn.second.packed_geometry_id, first_geometry);
|
||||
|
||||
// We earlier saved the source and target intersection nodes for every road section.
|
||||
// We can use the target node to find all road sections that lead away from
|
||||
@@ -481,7 +483,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
continue;
|
||||
|
||||
// Find the connection between our source road and the target node
|
||||
EdgeID smaller_edge_id = facade.FindSmallestEdge(
|
||||
EdgeID smaller_edge_id = facade->FindSmallestEdge(
|
||||
source_ebn.first, target_ebn, [](const contractor::QueryEdge::EdgeData &data) {
|
||||
return data.forward;
|
||||
});
|
||||
@@ -493,7 +495,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
// If we didn't find a forward edge, try for a backward one
|
||||
if (SPECIAL_EDGEID == smaller_edge_id)
|
||||
{
|
||||
smaller_edge_id = facade.FindSmallestEdge(
|
||||
smaller_edge_id = facade->FindSmallestEdge(
|
||||
target_ebn,
|
||||
source_ebn.first,
|
||||
[](const contractor::QueryEdge::EdgeData &data) { return data.backward; });
|
||||
@@ -510,13 +512,13 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
// out of it, which should represent the first hop, which is the one
|
||||
// we want to find the turn.
|
||||
const auto &data =
|
||||
[this, smaller_edge_id, source_ebn, target_ebn, &unpacked_shortcut]() {
|
||||
const auto inner_data = facade.GetEdgeData(smaller_edge_id);
|
||||
[this, &facade, smaller_edge_id, source_ebn, target_ebn, &unpacked_shortcut]() {
|
||||
const auto inner_data = facade->GetEdgeData(smaller_edge_id);
|
||||
if (inner_data.shortcut)
|
||||
{
|
||||
unpacked_shortcut.clear();
|
||||
UnpackEdgeToEdges(
|
||||
facade, source_ebn.first, target_ebn, unpacked_shortcut);
|
||||
*facade, source_ebn.first, target_ebn, unpacked_shortcut);
|
||||
return unpacked_shortcut.front();
|
||||
}
|
||||
else
|
||||
@@ -527,12 +529,12 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
// This is the geometry leading away from the intersection
|
||||
// (i.e. the geometry of the target edge-based-node)
|
||||
second_geometry.clear();
|
||||
facade.GetUncompressedGeometry(
|
||||
facade->GetUncompressedGeometry(
|
||||
edge_based_node_info.at(target_ebn).packed_geometry_id, second_geometry);
|
||||
|
||||
// Now, calculate the sum of the weight of all the segments.
|
||||
forward_weight_vector.clear();
|
||||
facade.GetUncompressedWeights(source_ebn.second.packed_geometry_id,
|
||||
facade->GetUncompressedWeights(source_ebn.second.packed_geometry_id,
|
||||
forward_weight_vector);
|
||||
const auto sum_node_weight = std::accumulate(
|
||||
forward_weight_vector.begin(), forward_weight_vector.end(), EdgeWeight{0});
|
||||
@@ -552,9 +554,9 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
const auto node_via = source_ebn.second.target_intersection;
|
||||
const auto node_to = second_geometry.front();
|
||||
|
||||
const auto coord_from = facade.GetCoordinateOfNode(node_from);
|
||||
const auto coord_via = facade.GetCoordinateOfNode(node_via);
|
||||
const auto coord_to = facade.GetCoordinateOfNode(node_to);
|
||||
const auto coord_from = facade->GetCoordinateOfNode(node_from);
|
||||
const auto coord_via = facade->GetCoordinateOfNode(node_via);
|
||||
const auto coord_to = facade->GetCoordinateOfNode(node_to);
|
||||
|
||||
// Calculate the bearing that we approach the intersection at
|
||||
const auto angle_in = static_cast<int>(
|
||||
@@ -613,11 +615,11 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
if (edge.forward_packed_geometry_id != SPECIAL_EDGEID)
|
||||
{
|
||||
forward_weight_vector.clear();
|
||||
facade.GetUncompressedWeights(edge.forward_packed_geometry_id, forward_weight_vector);
|
||||
facade->GetUncompressedWeights(edge.forward_packed_geometry_id, forward_weight_vector);
|
||||
forward_weight = forward_weight_vector[edge.fwd_segment_position];
|
||||
|
||||
forward_datasource_vector.clear();
|
||||
facade.GetUncompressedDatasources(edge.forward_packed_geometry_id,
|
||||
facade->GetUncompressedDatasources(edge.forward_packed_geometry_id,
|
||||
forward_datasource_vector);
|
||||
forward_datasource = forward_datasource_vector[edge.fwd_segment_position];
|
||||
|
||||
@@ -627,7 +629,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
if (edge.reverse_packed_geometry_id != SPECIAL_EDGEID)
|
||||
{
|
||||
reverse_weight_vector.clear();
|
||||
facade.GetUncompressedWeights(edge.reverse_packed_geometry_id, reverse_weight_vector);
|
||||
facade->GetUncompressedWeights(edge.reverse_packed_geometry_id, reverse_weight_vector);
|
||||
|
||||
BOOST_ASSERT(edge.fwd_segment_position < reverse_weight_vector.size());
|
||||
|
||||
@@ -635,7 +637,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
reverse_weight_vector[reverse_weight_vector.size() - edge.fwd_segment_position - 1];
|
||||
|
||||
reverse_datasource_vector.clear();
|
||||
facade.GetUncompressedDatasources(edge.reverse_packed_geometry_id,
|
||||
facade->GetUncompressedDatasources(edge.reverse_packed_geometry_id,
|
||||
reverse_datasource_vector);
|
||||
reverse_datasource = reverse_datasource_vector[reverse_datasource_vector.size() -
|
||||
edge.fwd_segment_position - 1];
|
||||
@@ -647,7 +649,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
max_datasource_id = std::max(max_datasource_id, forward_datasource);
|
||||
max_datasource_id = std::max(max_datasource_id, reverse_datasource);
|
||||
|
||||
std::string name = facade.GetNameForID(edge.name_id);
|
||||
std::string name = facade->GetNameForID(edge.name_id);
|
||||
if (name_offsets.find(name) == name_offsets.end())
|
||||
{
|
||||
names.push_back(name);
|
||||
@@ -687,8 +689,8 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
for (const auto &edge : edges)
|
||||
{
|
||||
// Get coordinates for start/end nodes of segment (NodeIDs u and v)
|
||||
const auto a = facade.GetCoordinateOfNode(edge.u);
|
||||
const auto b = facade.GetCoordinateOfNode(edge.v);
|
||||
const auto a = facade->GetCoordinateOfNode(edge.u);
|
||||
const auto b = facade->GetCoordinateOfNode(edge.v);
|
||||
// Calculate the length in meters
|
||||
const double length =
|
||||
osrm::util::coordinate_calculation::haversineDistance(a, b);
|
||||
@@ -699,17 +701,17 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
std::uint8_t forward_datasource = 0;
|
||||
std::uint8_t reverse_datasource = 0;
|
||||
|
||||
std::string name = facade.GetNameForID(edge.name_id);
|
||||
std::string name = facade->GetNameForID(edge.name_id);
|
||||
|
||||
if (edge.forward_packed_geometry_id != SPECIAL_EDGEID)
|
||||
{
|
||||
forward_weight_vector.clear();
|
||||
facade.GetUncompressedWeights(edge.forward_packed_geometry_id,
|
||||
facade->GetUncompressedWeights(edge.forward_packed_geometry_id,
|
||||
forward_weight_vector);
|
||||
forward_weight = forward_weight_vector[edge.fwd_segment_position];
|
||||
|
||||
forward_datasource_vector.clear();
|
||||
facade.GetUncompressedDatasources(edge.forward_packed_geometry_id,
|
||||
facade->GetUncompressedDatasources(edge.forward_packed_geometry_id,
|
||||
forward_datasource_vector);
|
||||
forward_datasource = forward_datasource_vector[edge.fwd_segment_position];
|
||||
}
|
||||
@@ -717,7 +719,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
if (edge.reverse_packed_geometry_id != SPECIAL_EDGEID)
|
||||
{
|
||||
reverse_weight_vector.clear();
|
||||
facade.GetUncompressedWeights(edge.reverse_packed_geometry_id,
|
||||
facade->GetUncompressedWeights(edge.reverse_packed_geometry_id,
|
||||
reverse_weight_vector);
|
||||
|
||||
BOOST_ASSERT(edge.fwd_segment_position < reverse_weight_vector.size());
|
||||
@@ -726,7 +728,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
edge.fwd_segment_position - 1];
|
||||
|
||||
reverse_datasource_vector.clear();
|
||||
facade.GetUncompressedDatasources(edge.reverse_packed_geometry_id,
|
||||
facade->GetUncompressedDatasources(edge.reverse_packed_geometry_id,
|
||||
reverse_datasource_vector);
|
||||
reverse_datasource =
|
||||
reverse_datasource_vector[reverse_datasource_vector.size() -
|
||||
@@ -884,7 +886,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters ¶meters, std::str
|
||||
util::vector_tile::VARIANT_TAG);
|
||||
// Attribute value 1 == string type
|
||||
values_writer.add_string(util::vector_tile::VARIANT_TYPE_STRING,
|
||||
facade.GetDatasourceName(i));
|
||||
facade->GetDatasourceName(i));
|
||||
}
|
||||
for (auto value : used_line_ints)
|
||||
{
|
||||
|
||||
@@ -114,7 +114,8 @@ SCC_Component SplitUnaccessibleLocations(const std::size_t number_of_locations,
|
||||
return SCC_Component(std::move(components), std::move(range));
|
||||
}
|
||||
|
||||
InternalRouteResult TripPlugin::ComputeRoute(const std::vector<PhantomNode> &snapped_phantoms,
|
||||
InternalRouteResult TripPlugin::ComputeRoute(const datafacade::BaseDataFacade& facade,
|
||||
const std::vector<PhantomNode> &snapped_phantoms,
|
||||
const std::vector<NodeID> &trip)
|
||||
{
|
||||
InternalRouteResult min_route;
|
||||
@@ -134,13 +135,14 @@ InternalRouteResult TripPlugin::ComputeRoute(const std::vector<PhantomNode> &sna
|
||||
}
|
||||
BOOST_ASSERT(min_route.segment_end_coordinates.size() == trip.size());
|
||||
|
||||
shortest_path(min_route.segment_end_coordinates, {false}, min_route);
|
||||
shortest_path(facade, min_route.segment_end_coordinates, {false}, min_route);
|
||||
|
||||
BOOST_ASSERT_MSG(min_route.shortest_path_length < INVALID_EDGE_WEIGHT, "unroutable route");
|
||||
return min_route;
|
||||
}
|
||||
|
||||
Status TripPlugin::HandleRequest(const api::TripParameters ¶meters,
|
||||
Status TripPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
|
||||
const api::TripParameters ¶meters,
|
||||
util::json::Object &json_result)
|
||||
{
|
||||
BOOST_ASSERT(parameters.IsValid());
|
||||
@@ -157,7 +159,7 @@ Status TripPlugin::HandleRequest(const api::TripParameters ¶meters,
|
||||
return Error("InvalidValue", "Invalid coordinate value.", json_result);
|
||||
}
|
||||
|
||||
auto phantom_node_pairs = GetPhantomNodes(parameters);
|
||||
auto phantom_node_pairs = GetPhantomNodes(*facade, parameters);
|
||||
if (phantom_node_pairs.size() != parameters.coordinates.size())
|
||||
{
|
||||
return Error("NoSegment",
|
||||
@@ -173,7 +175,7 @@ Status TripPlugin::HandleRequest(const api::TripParameters ¶meters,
|
||||
|
||||
// compute the duration table of all phantom nodes
|
||||
const auto result_table = util::DistTableWrapper<EdgeWeight>(
|
||||
duration_table(snapped_phantoms, {}, {}), number_of_locations);
|
||||
duration_table(*facade, snapped_phantoms, {}, {}), number_of_locations);
|
||||
|
||||
if (result_table.size() == 0)
|
||||
{
|
||||
@@ -231,10 +233,10 @@ Status TripPlugin::HandleRequest(const api::TripParameters ¶meters,
|
||||
routes.reserve(trips.size());
|
||||
for (const auto &trip : trips)
|
||||
{
|
||||
routes.push_back(ComputeRoute(snapped_phantoms, trip));
|
||||
routes.push_back(ComputeRoute(*facade, snapped_phantoms, trip));
|
||||
}
|
||||
|
||||
api::TripAPI trip_api{BasePlugin::facade, parameters};
|
||||
api::TripAPI trip_api{*facade, parameters};
|
||||
trip_api.MakeResponse(trips, routes, snapped_phantoms, json_result);
|
||||
|
||||
return Status::Ok;
|
||||
|
||||
@@ -21,13 +21,14 @@ namespace engine
|
||||
namespace plugins
|
||||
{
|
||||
|
||||
ViaRoutePlugin::ViaRoutePlugin(datafacade::BaseDataFacade &facade_, int max_locations_viaroute)
|
||||
: BasePlugin(facade_), shortest_path(&facade_, heaps), alternative_path(&facade_, heaps),
|
||||
direct_shortest_path(&facade_, heaps), max_locations_viaroute(max_locations_viaroute)
|
||||
ViaRoutePlugin::ViaRoutePlugin(int max_locations_viaroute)
|
||||
: shortest_path(heaps), alternative_path(heaps), direct_shortest_path(heaps),
|
||||
max_locations_viaroute(max_locations_viaroute)
|
||||
{
|
||||
}
|
||||
|
||||
Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameters,
|
||||
Status ViaRoutePlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
|
||||
const api::RouteParameters &route_parameters,
|
||||
util::json::Object &json_result)
|
||||
{
|
||||
BOOST_ASSERT(route_parameters.IsValid());
|
||||
@@ -47,7 +48,7 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
|
||||
return Error("InvalidValue", "Invalid coordinate value.", json_result);
|
||||
}
|
||||
|
||||
auto phantom_node_pairs = GetPhantomNodes(route_parameters);
|
||||
auto phantom_node_pairs = GetPhantomNodes(*facade, route_parameters);
|
||||
if (phantom_node_pairs.size() != route_parameters.coordinates.size())
|
||||
{
|
||||
return Error("NoSegment",
|
||||
@@ -61,7 +62,7 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
|
||||
|
||||
const bool continue_straight_at_waypoint = route_parameters.continue_straight
|
||||
? *route_parameters.continue_straight
|
||||
: facade.GetContinueStraightDefault();
|
||||
: facade->GetContinueStraightDefault();
|
||||
|
||||
InternalRouteResult raw_route;
|
||||
auto build_phantom_pairs = [&raw_route, continue_straight_at_waypoint](
|
||||
@@ -85,18 +86,18 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
|
||||
|
||||
if (1 == raw_route.segment_end_coordinates.size())
|
||||
{
|
||||
if (route_parameters.alternatives && facade.GetCoreSize() == 0)
|
||||
if (route_parameters.alternatives && facade->GetCoreSize() == 0)
|
||||
{
|
||||
alternative_path(raw_route.segment_end_coordinates.front(), raw_route);
|
||||
alternative_path(*facade, raw_route.segment_end_coordinates.front(), raw_route);
|
||||
}
|
||||
else
|
||||
{
|
||||
direct_shortest_path(raw_route.segment_end_coordinates, raw_route);
|
||||
direct_shortest_path(*facade, raw_route.segment_end_coordinates, raw_route);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shortest_path(
|
||||
shortest_path(*facade,
|
||||
raw_route.segment_end_coordinates, route_parameters.continue_straight, raw_route);
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
|
||||
// allow for connection in one direction.
|
||||
if (raw_route.is_valid())
|
||||
{
|
||||
api::RouteAPI route_api{BasePlugin::facade, route_parameters};
|
||||
api::RouteAPI route_api{*facade, route_parameters};
|
||||
route_api.MakeResponse(raw_route, json_result);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user