Skip to content

Commit 36324d8

Browse files
committed
Remove stage 2 processing of relations
We currently have no use case for processing relations again in stage 2 and two-stage-processing is difficult enough without having to think about how relations in relations are handled, especially when updates are involved. This commit removes tracking of relation ids for stage 2, i.e. the Lua function mark_relation() and all the internal processing behind it is removed. This functionality can be added back in later, when we have some more experience with stage 2 processing.
1 parent 0a6f795 commit 36324d8

File tree

4 files changed

+9
-46
lines changed

4 files changed

+9
-46
lines changed

docs/flex.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ The following functions are defined:
3737
more control than the more convenient other functions.
3838
* `osm2pgsql.mark_way(id)`: Mark the OSM way with the specified id. This way
3939
will be processed (again) in stage 2.
40-
* `osm2pgsql.mark_relation(id)`: Mark the OSM relation with the specified id.
41-
This relation will be processed (again) in stage 2.
4240

4341
You are expected to define one or more of the following functions:
4442

@@ -226,10 +224,9 @@ a default transformation. These are the defaults:
226224

227225
## Stages
228226

229-
Osm2pgsql processes the data in up to two stages. You can mark ways or
230-
relations in stage 1 for processing in stage 2 by calling
231-
`osm2pgsql.mark_way(id)` or `osm2pgsql.mark_relation(id)`, respectively. If you
232-
don't mark any objects, nothing will be done in stage 2.
227+
Osm2pgsql processes the data in up to two stages. You can mark ways in stage 1
228+
for processing in stage 2 by calling `osm2pgsql.mark_way(id)`. If you don't
229+
mark any ways, nothing will be done in stage 2.
233230

234231
You can look at `osm2pgsql.stage` to see in which stage you are.
235232

src/init.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ function osm2pgsql.mark_way(id)
3333
return osm2pgsql.mark('w', id)
3434
end
3535

36-
function osm2pgsql.mark_relation(id)
37-
return osm2pgsql.mark('r', id)
38-
end
39-
4036
function osm2pgsql.clamp(value, low, high)
4137
return math.min(math.max(value, low), high)
4238
end

src/output-flex.cpp

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,6 @@ int output_flex_t::app_mark()
519519

520520
if (type_name[0] == 'w') {
521521
m_stage2_ways_tracker->mark(id);
522-
} else if (type_name[0] == 'r') {
523-
m_stage2_rels_tracker->mark(id);
524522
}
525523

526524
return 0;
@@ -821,10 +819,6 @@ int output_flex_t::table_add_row()
821819
throw std::runtime_error{
822820
"Trying to add relation to table '{}'"_format(table.name())};
823821
}
824-
if (m_in_stage2) {
825-
delete_from_table(&table_connection, osmium::item_type::relation,
826-
m_context_relation->id());
827-
}
828822
add_row(&table_connection, *m_context_relation);
829823
} else {
830824
throw std::runtime_error{"The add_row() function can only be called "
@@ -1214,7 +1208,7 @@ output_flex_t::clone(std::shared_ptr<middle_query_t> const &mid,
12141208
return std::make_shared<output_flex_t>(
12151209
mid, *get_options(), copy_thread, true, m_lua_state, m_process_node,
12161210
m_process_way, m_process_relation, m_tables,
1217-
m_stage2_ways_tracker, m_stage2_rels_tracker);
1211+
m_stage2_ways_tracker);
12181212
}
12191213

12201214
output_flex_t::output_flex_t(
@@ -1224,11 +1218,9 @@ output_flex_t::output_flex_t(
12241218
prepared_lua_function_t process_way,
12251219
prepared_lua_function_t process_relation,
12261220
std::shared_ptr<std::vector<flex_table_t>> tables,
1227-
std::shared_ptr<id_tracker> ways_tracker,
1228-
std::shared_ptr<id_tracker> rels_tracker)
1221+
std::shared_ptr<id_tracker> ways_tracker)
12291222
: output_t(mid, o), m_tables(std::move(tables)),
1230-
m_stage2_ways_tracker(std::move(ways_tracker)),
1231-
m_stage2_rels_tracker(std::move(rels_tracker)), m_copy_thread(copy_thread),
1223+
m_stage2_ways_tracker(std::move(ways_tracker)), m_copy_thread(copy_thread),
12321224
m_lua_state(std::move(lua_state)), m_builder(o.projection),
12331225
m_expire(o.expire_tiles_zoom, o.expire_tiles_max_bbox, o.projection),
12341226
m_buffer(32768, osmium::memory::Buffer::auto_grow::yes),
@@ -1333,11 +1325,8 @@ void output_flex_t::init_lua(std::string const &filename)
13331325

13341326
void output_flex_t::stage2_proc()
13351327
{
1336-
bool const has_marked_ways = !m_stage2_ways_tracker->empty();
1337-
bool const has_marked_rels = !m_stage2_rels_tracker->empty();
1338-
1339-
if (!has_marked_ways && !has_marked_rels) {
1340-
fmt::print(stderr, "Skipping stage 2 (no marked objects).\n");
1328+
if (m_stage2_ways_tracker->empty()) {
1329+
fmt::print(stderr, "Skipping stage 2 (no marked ways).\n");
13411330
return;
13421331
}
13431332

@@ -1349,10 +1338,7 @@ void output_flex_t::stage2_proc()
13491338
util::timer_t timer;
13501339

13511340
for (auto &table : m_table_connections) {
1352-
if ((has_marked_ways &&
1353-
table.table().matches_type(osmium::item_type::way)) ||
1354-
(has_marked_rels &&
1355-
table.table().matches_type(osmium::item_type::relation))) {
1341+
if (table.table().matches_type(osmium::item_type::way)) {
13561342
fmt::print(stderr, " Creating id index on table '{}'...\n",
13571343
table.table().name());
13581344
table.create_id_index();
@@ -1385,19 +1371,6 @@ void output_flex_t::stage2_proc()
13851371
auto &way = m_buffer.get<osmium::Way>(0);
13861372
way_add(&way);
13871373
}
1388-
1389-
fmt::print(stderr,
1390-
"Entering stage 2 processing of {} relations...\n"_format(
1391-
m_stage2_rels_tracker->size()));
1392-
1393-
while (id_tracker::is_valid((id = m_stage2_rels_tracker->pop_mark()))) {
1394-
m_rels_buffer.clear();
1395-
if (!m_mid->relation_get(id, m_rels_buffer)) {
1396-
continue;
1397-
}
1398-
auto const &relation = m_rels_buffer.get<osmium::Relation>(0);
1399-
relation_add(relation);
1400-
}
14011374
}
14021375

14031376
void output_flex_t::merge_expire_trees(output_t *other)

src/output-flex.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class output_flex_t : public output_t
6969
std::shared_ptr<std::vector<flex_table_t>> tables =
7070
std::make_shared<std::vector<flex_table_t>>(),
7171
std::shared_ptr<id_tracker> ways_tracker =
72-
std::make_shared<id_tracker>(),
73-
std::shared_ptr<id_tracker> rels_tracker =
7472
std::make_shared<id_tracker>());
7573

7674
output_flex_t(output_flex_t const &) = delete;
@@ -167,7 +165,6 @@ class output_flex_t : public output_t
167165
std::vector<table_connection_t> m_table_connections;
168166

169167
std::shared_ptr<id_tracker> m_stage2_ways_tracker;
170-
std::shared_ptr<id_tracker> m_stage2_rels_tracker;
171168

172169
std::shared_ptr<db_copy_thread_t> m_copy_thread;
173170

0 commit comments

Comments
 (0)