Skip to content

Commit

Permalink
Make DataFacade local to every request
Browse files Browse the repository at this point in the history
This is the first step to having fine grained locking on data updates,
see issue #2570.
  • Loading branch information
TheMarex committed Oct 6, 2016
1 parent 66f2cc5 commit 241ee7b
Show file tree
Hide file tree
Showing 21 changed files with 361 additions and 291 deletions.
2 changes: 1 addition & 1 deletion include/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Engine final
std::unique_ptr<plugins::MatchPlugin> match_plugin;
std::unique_ptr<plugins::TilePlugin> tile_plugin;

std::unique_ptr<datafacade::BaseDataFacade> query_data_facade;
std::shared_ptr<datafacade::BaseDataFacade> query_data_facade;
};
}
}
Expand Down
10 changes: 6 additions & 4 deletions include/engine/plugins/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ class MatchPlugin : public BasePlugin
static const constexpr double DEFAULT_GPS_PRECISION = 5;
static const constexpr double RADIUS_MULTIPLIER = 3;

MatchPlugin(datafacade::BaseDataFacade &facade_, const int max_locations_map_matching)
: BasePlugin(facade_), map_matching(&facade_, heaps, DEFAULT_GPS_PRECISION),
shortest_path(&facade_, heaps), max_locations_map_matching(max_locations_map_matching)
MatchPlugin(const int max_locations_map_matching)
: map_matching(heaps, DEFAULT_GPS_PRECISION),
shortest_path(heaps), max_locations_map_matching(max_locations_map_matching)
{
}

Status HandleRequest(const api::MatchParameters &parameters, util::json::Object &json_result);
Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::MatchParameters &parameters,
util::json::Object &json_result);

private:
SearchEngineData heaps;
Expand Down
6 changes: 4 additions & 2 deletions include/engine/plugins/nearest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ namespace plugins
class NearestPlugin final : public BasePlugin
{
public:
explicit NearestPlugin(datafacade::BaseDataFacade &facade, const int max_results);
explicit NearestPlugin(const int max_results);

Status HandleRequest(const api::NearestParameters &params, util::json::Object &result);
Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::NearestParameters &params,
util::json::Object &result) const;

private:
const int max_results;
Expand Down
15 changes: 8 additions & 7 deletions include/engine/plugins/plugin_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ namespace plugins
class BasePlugin
{
protected:
datafacade::BaseDataFacade &facade;
BasePlugin(datafacade::BaseDataFacade &facade_) : facade(facade_) {}

bool CheckAllCoordinates(const std::vector<util::Coordinate> &coordinates)
bool CheckAllCoordinates(const std::vector<util::Coordinate> &coordinates) const
{
return !std::any_of(
std::begin(coordinates), std::end(coordinates), [](const util::Coordinate coordinate) {
Expand Down Expand Up @@ -111,7 +108,8 @@ class BasePlugin

// Falls back to default_radius for non-set radii
std::vector<std::vector<PhantomNodeWithDistance>>
GetPhantomNodesInRange(const api::BaseParameters &parameters,
GetPhantomNodesInRange(const datafacade::BaseDataFacade &facade,
const api::BaseParameters &parameters,
const std::vector<double> radiuses) const
{
std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes(
Expand Down Expand Up @@ -152,7 +150,9 @@ class BasePlugin
}

std::vector<std::vector<PhantomNodeWithDistance>>
GetPhantomNodes(const api::BaseParameters &parameters, unsigned number_of_results)
GetPhantomNodes(const datafacade::BaseDataFacade &facade,
const api::BaseParameters &parameters,
unsigned number_of_results) const
{
std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes(
parameters.coordinates.size());
Expand Down Expand Up @@ -216,7 +216,8 @@ class BasePlugin
return phantom_nodes;
}

std::vector<PhantomNodePair> GetPhantomNodes(const api::BaseParameters &parameters)
std::vector<PhantomNodePair> GetPhantomNodes(const datafacade::BaseDataFacade &facade,
const api::BaseParameters &parameters) const
{
std::vector<PhantomNodePair> phantom_node_pairs(parameters.coordinates.size());

Expand Down
7 changes: 4 additions & 3 deletions include/engine/plugins/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ namespace plugins
class TablePlugin final : public BasePlugin
{
public:
explicit TablePlugin(datafacade::BaseDataFacade &facade,
const int max_locations_distance_table);
explicit TablePlugin(const int max_locations_distance_table);

Status HandleRequest(const api::TableParameters &params, util::json::Object &result);
Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::TableParameters &params,
util::json::Object &result);

private:
SearchEngineData heaps;
Expand Down
4 changes: 1 addition & 3 deletions include/engine/plugins/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ namespace plugins
class TilePlugin final : public BasePlugin
{
public:
TilePlugin(datafacade::BaseDataFacade &facade) : BasePlugin(facade) {}

Status HandleRequest(const api::TileParameters &parameters, std::string &pbf_buffer);
Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade, const api::TileParameters &parameters, std::string &pbf_buffer) const;
};
}
}
Expand Down
11 changes: 7 additions & 4 deletions include/engine/plugins/trip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ class TripPlugin final : public BasePlugin
routing_algorithms::ManyToManyRouting<datafacade::BaseDataFacade> duration_table;
int max_locations_trip;

InternalRouteResult ComputeRoute(const std::vector<PhantomNode> &phantom_node_list,
InternalRouteResult ComputeRoute(const datafacade::BaseDataFacade &facade,
const std::vector<PhantomNode> &phantom_node_list,
const std::vector<NodeID> &trip);

public:
explicit TripPlugin(datafacade::BaseDataFacade &facade_, const int max_locations_trip_)
: BasePlugin(facade_), shortest_path(&facade_, heaps), duration_table(&facade_, heaps),
explicit TripPlugin(const int max_locations_trip_)
: shortest_path(heaps), duration_table(heaps),
max_locations_trip(max_locations_trip_)
{
}

Status HandleRequest(const api::TripParameters &parameters, util::json::Object &json_result);
Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::TripParameters &parameters,
util::json::Object &json_result);
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions include/engine/plugins/viaroute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class ViaRoutePlugin final : public BasePlugin
int max_locations_viaroute;

public:
explicit ViaRoutePlugin(datafacade::BaseDataFacade &facade, int max_locations_viaroute);
explicit ViaRoutePlugin(int max_locations_viaroute);

Status HandleRequest(const api::RouteParameters &route_parameters,
Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::RouteParameters &route_parameters,
util::json::Object &json_result);
};
}
Expand Down
Loading

0 comments on commit 241ee7b

Please sign in to comment.