Skip to content

Commit 2188833

Browse files
Do not generate intermediate .osrm file in osrm-extract. (#6354)
1 parent 395cc6e commit 2188833

19 files changed

+193
-184
lines changed

.github/workflows/osrm-backend.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ jobs:
124124
# when `--memory-swap` value equals `--memory` it means container won't use swap
125125
# see https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details
126126
MEMORY_ARGS="--memory=1g --memory-swap=1g"
127-
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-extract -p /opt/car.lua /data/berlin-latest.osm.pbf
127+
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-extract --dump-nbg-graph -p /opt/car.lua /data/berlin-latest.osm.pbf
128+
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-components /data/berlin-latest.osrm.nbg /data/berlin-latest.geojson
129+
if [ ! -s "${PWD}/berlin-latest.geojson" ]
130+
then
131+
>&2 echo "No berlin-latest.geojson found"
132+
exit 1
133+
fi
134+
135+
# removing `.osrm.nbg` to check that whole pipeline works without it
136+
rm -rf "${PWD}/berlin-latest.osrm.nbg"
137+
128138
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-partition /data/berlin-latest.osrm
129139
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-customize /data/berlin-latest.osrm
130140
docker run $MEMORY_ARGS --name=osrm-container -t -p 5000:5000 -v "${PWD}:/data" "${TAG}" osrm-routed --algorithm mld /data/berlin-latest.osrm &

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
- FIXED: Ensure u-turn exists in intersection view. [#6376](https://github.com/Project-OSRM/osrm-backend/pull/6376)
6565
- Profile:
6666
- CHANGED: Bicycle surface speeds [#6212](https://github.com/Project-OSRM/osrm-backend/pull/6212)
67-
67+
- Tools:
68+
- CHANGED: Do not generate intermediate .osrm file in osrm-extract. [#6354](https://github.com/Project-OSRM/osrm-backend/pull/6354)
6869

6970
# 5.26.0
7071
- Changes from 5.25.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The flag `-v "${PWD}:/data"` creates the directory `/data` inside the docker con
6565
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/berlin-latest.osrm
6666
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/berlin-latest.osrm
6767

68-
Note that `berlin-latest.osrm` has a different file extension.
68+
Note there is no `berlin-latest.osrm` file, but multiple `berlin-latest.osrm.*` files, i.e. `berlin-latest.osrm` is not file path, but "base" path referring to set of files and there is an option to omit this `.osrm` suffix completely(e.g. `osrm-partition /data/berlin-latest`).
6969

7070
docker run -t -i -p 5000:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/berlin-latest.osrm
7171

docs/nodejs/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
## OSRM
44

55
The `OSRM` method is the main constructor for creating an OSRM instance.
6-
An OSRM instance requires a `.osrm` dataset, which is prepared by the OSRM toolchain.
7-
You can create such a `.osrm` file by running the OSRM binaries we ship in `node_modules/osrm/lib/binding/` and default
6+
An OSRM instance requires a `.osrm.*` dataset(`.osrm.*` because it contains several files), which is prepared by the OSRM toolchain.
7+
You can create such a `.osrm.*` dataset by running the OSRM binaries we ship in `node_modules/osrm/lib/binding/` and default
88
profiles (e.g. for setting speeds and determining road types to route on) in `node_modules/osrm/profiles/`:
99

1010
node_modules/osrm/lib/binding/osrm-extract data.osm.pbf -p node_modules/osrm/profiles/car.lua
1111
node_modules/osrm/lib/binding/osrm-contract data.osrm
1212

1313
Consult the [osrm-backend](https://github.com/Project-OSRM/osrm-backend) documentation for further details.
1414

15-
Once you have a complete `network.osrm` file, you can calculate routes in javascript with this object.
15+
Once you have a complete `network.osrm.*` dataset, you can calculate routes in javascript with this object.
1616

1717
```javascript
1818
var osrm = new OSRM('network.osrm');

include/extractor/extraction_containers.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ class ExtractionContainers
4343
void PrepareTrafficSignals(const ReferencedTrafficSignals &referenced_traffic_signals);
4444
void PrepareEdges(ScriptingEnvironment &scripting_environment);
4545

46-
void WriteNodes(storage::tar::FileWriter &file_out) const;
47-
void WriteEdges(storage::tar::FileWriter &file_out) const;
48-
void WriteMetadata(storage::tar::FileWriter &file_out) const;
4946
void WriteCharData(const std::string &file_name);
5047

5148
public:
@@ -75,6 +72,8 @@ class ExtractionContainers
7572
std::vector<InputTrafficSignal> external_traffic_signals;
7673
TrafficSignals internal_traffic_signals;
7774

75+
std::vector<NodeBasedEdge> used_edges;
76+
7877
// List of restrictions (conditional and unconditional) before we transform them into the
7978
// output types. Input containers reference OSMNodeIDs. We can only transform them to the
8079
// correct internal IDs after we've read everything. Without a multi-parse approach,
@@ -84,11 +83,12 @@ class ExtractionContainers
8483

8584
std::vector<InputManeuverOverride> external_maneuver_overrides_list;
8685
std::vector<UnresolvedManeuverOverride> internal_maneuver_overrides;
86+
std::unordered_set<NodeID> used_barrier_nodes;
87+
NodeVector used_nodes;
8788

8889
ExtractionContainers();
8990

9091
void PrepareData(ScriptingEnvironment &scripting_environment,
91-
const std::string &osrm_path,
9292
const std::string &names_data_path);
9393
};
9494
} // namespace extractor

include/extractor/extractor.hpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,25 @@ class Extractor
6060
Extractor(ExtractorConfig extractor_config) : config(std::move(extractor_config)) {}
6161
int run(ScriptingEnvironment &scripting_environment);
6262

63+
private:
64+
struct ParsedOSMData
65+
{
66+
LaneDescriptionMap turn_lane_map;
67+
std::vector<TurnRestriction> turn_restrictions;
68+
std::vector<UnresolvedManeuverOverride> unresolved_maneuver_overrides;
69+
TrafficSignals traffic_signals;
70+
std::unordered_set<NodeID> barriers;
71+
std::vector<util::Coordinate> osm_coordinates;
72+
extractor::PackedOSMIDs osm_node_ids;
73+
std::vector<NodeBasedEdge> edge_list;
74+
std::vector<NodeBasedEdgeAnnotation> annotation_data;
75+
};
76+
6377
private:
6478
ExtractorConfig config;
6579

66-
std::tuple<LaneDescriptionMap,
67-
std::vector<TurnRestriction>,
68-
std::vector<UnresolvedManeuverOverride>,
69-
TrafficSignals>
70-
ParseOSMData(ScriptingEnvironment &scripting_environment, const unsigned number_of_threads);
80+
ParsedOSMData ParseOSMData(ScriptingEnvironment &scripting_environment,
81+
const unsigned number_of_threads);
7182

7283
EdgeID BuildEdgeExpandedGraph(
7384
// input data

include/extractor/extractor_config.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct ExtractorConfig final : storage::IOConfig
4848
"",
4949
},
5050
{},
51-
{".osrm",
51+
{".osrm.nbg",
5252
".osrm.restrictions",
5353
".osrm.names",
5454
".osrm.tls",
@@ -89,6 +89,7 @@ struct ExtractorConfig final : storage::IOConfig
8989
bool use_metadata = false;
9090
bool parse_conditionals = false;
9191
bool use_locations_cache = true;
92+
bool dump_nbg_graph = false;
9293
};
9394
} // namespace extractor
9495
} // namespace osrm

include/extractor/files.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,11 @@ inline void readConditionalRestrictions(const boost::filesystem::path &path,
444444
}
445445

446446
// reads .osrm file which is a temporary file of osrm-extract
447-
template <typename BarrierOutIter, typename PackedOSMIDsT>
447+
template <typename PackedOSMIDsT>
448448
void readRawNBGraph(const boost::filesystem::path &path,
449-
BarrierOutIter barriers,
450449
std::vector<util::Coordinate> &coordinates,
451450
PackedOSMIDsT &osm_node_ids,
452-
std::vector<extractor::NodeBasedEdge> &edge_list,
453-
std::vector<extractor::NodeBasedEdgeAnnotation> &annotations)
451+
std::vector<extractor::NodeBasedEdge> &edge_list)
454452
{
455453
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
456454
storage::tar::FileReader reader{path, fingerprint};
@@ -468,10 +466,7 @@ void readRawNBGraph(const boost::filesystem::path &path,
468466
reader.ReadStreaming<extractor::QueryNode>("/extractor/nodes",
469467
boost::make_function_output_iterator(decode));
470468

471-
reader.ReadStreaming<NodeID>("/extractor/barriers", barriers);
472-
473469
storage::serialization::read(reader, "/extractor/edges", edge_list);
474-
storage::serialization::read(reader, "/extractor/annotations", annotations);
475470
}
476471

477472
template <typename NameTableT>

include/extractor/node_based_graph_factory.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ namespace extractor
3434
class NodeBasedGraphFactory
3535
{
3636
public:
37-
// The node-based graph factory loads the *.osrm file and transforms the data within into the
37+
// The node-based graph factory transforms the graph data into the
3838
// node-based graph to represent the OSM network. This includes geometry compression, annotation
3939
// data optimisation and many other aspects. After this step, the edge-based graph factory can
4040
// turn the graph into the routing graph to be used with the navigation algorithms.
41-
NodeBasedGraphFactory(const boost::filesystem::path &input_file,
42-
ScriptingEnvironment &scripting_environment,
41+
NodeBasedGraphFactory(ScriptingEnvironment &scripting_environment,
4342
std::vector<TurnRestriction> &turn_restrictions,
4443
std::vector<UnresolvedManeuverOverride> &maneuver_overrides,
45-
const TrafficSignals &traffic_signals);
44+
const TrafficSignals &traffic_signals,
45+
std::unordered_set<NodeID> &&barriers,
46+
std::vector<util::Coordinate> &&coordinates,
47+
extractor::PackedOSMIDs &&osm_node_ids,
48+
const std::vector<NodeBasedEdge> &edge_list,
49+
std::vector<NodeBasedEdgeAnnotation> &&annotation_data);
4650

4751
auto const &GetGraph() const { return compressed_output_graph; }
4852
auto const &GetBarriers() const { return barriers; }
@@ -60,9 +64,8 @@ class NodeBasedGraphFactory
6064
void ReleaseOsmNodes();
6165

6266
private:
63-
// Get the information from the *.osrm file (direct product of the extractor callback/extraction
64-
// containers) and prepare the graph creation process
65-
void LoadDataFromFile(const boost::filesystem::path &input_file);
67+
// Build and validate compressed output graph
68+
void BuildCompressedOutputGraph(const std::vector<NodeBasedEdge> &edge_list);
6669

6770
// Compress the node-based graph into a compact representation of itself. This removes storing a
6871
// single edge for every part of the geometry and might also combine meta-data for multiple

include/partitioner/partitioner_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace partitioner
1616
struct PartitionerConfig final : storage::IOConfig
1717
{
1818
PartitionerConfig()
19-
: IOConfig({".osrm", ".osrm.fileIndex", ".osrm.ebg_nodes", ".osrm.enw"},
19+
: IOConfig({".osrm.fileIndex", ".osrm.ebg_nodes", ".osrm.enw"},
2020
{".osrm.hsgr", ".osrm.cnbg"},
2121
{".osrm.ebg",
2222
".osrm.cnbg",

0 commit comments

Comments
 (0)