Skip to content

Commit 27dd4dc

Browse files
committed
Flush COPY between nodes/ways and ways/relations respectively
In most cases database tables are filled based on OSM object types, so after we have read all nodes nothing will be added to node-type tables any more etc. So it makes sense to explicitly flush the COPY making sure this data is written to the database. If more data is later added, maybe because of second-stage processing, it doesn't matter, the COPY will be reopened.
1 parent c42e200 commit 27dd4dc

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

src/db-copy-mgr.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,22 @@ class db_copy_mgr_t
271271
m_current->add_deletable(std::forward<ARGS>(args)...);
272272
}
273273

274+
void flush()
275+
{
276+
// finish any ongoing copy operations
277+
if (m_current) {
278+
m_processor->add_buffer(std::move(m_current));
279+
}
280+
}
281+
274282
/**
275283
* Synchronize with worker.
276284
*
277285
* Only returns when all previously issued commands are done.
278286
*/
279287
void sync()
280288
{
281-
// finish any ongoing copy operations
282-
if (m_current) {
283-
m_processor->add_buffer(std::move(m_current));
284-
}
285-
289+
flush();
286290
m_processor->sync_and_wait();
287291
}
288292

src/flex-table.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ class table_connection_t
247247

248248
pg_result_t get_geom_by_id(osmium::item_type type, osmid_t id) const;
249249

250+
void flush() { m_copy_mgr.flush(); }
251+
250252
void sync() { m_copy_mgr.sync(); }
251253

252254
void new_line() { m_copy_mgr.new_line(m_target); }

src/osmdata.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ void osmdata_t::node(osmium::Node const &node)
6767
}
6868
}
6969

70-
void osmdata_t::after_nodes() { m_mid->after_nodes(); }
70+
void osmdata_t::after_nodes()
71+
{
72+
m_mid->after_nodes();
73+
m_output->after_nodes();
74+
}
7175

7276
void osmdata_t::way(osmium::Way &way)
7377
{
@@ -84,7 +88,11 @@ void osmdata_t::way(osmium::Way &way)
8488
}
8589
}
8690

87-
void osmdata_t::after_ways() { m_mid->after_ways(); }
91+
void osmdata_t::after_ways()
92+
{
93+
m_mid->after_ways();
94+
m_output->after_ways();
95+
}
8896

8997
void osmdata_t::relation(osmium::Relation const &rel)
9098
{

src/output-flex.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,20 @@ void output_flex_t::sync()
12631263
}
12641264
}
12651265

1266+
void output_flex_t::after_nodes()
1267+
{
1268+
for (auto &table : m_table_connections) {
1269+
table.flush();
1270+
}
1271+
}
1272+
1273+
void output_flex_t::after_ways()
1274+
{
1275+
for (auto &table : m_table_connections) {
1276+
table.flush();
1277+
}
1278+
}
1279+
12661280
void output_flex_t::stop()
12671281
{
12681282
for (auto &table : m_table_connections) {

src/output-flex.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class output_flex_t : public output_t
124124
void stop() override;
125125
void sync() override;
126126

127+
void after_nodes() override;
128+
void after_ways() override;
129+
127130
void wait() override;
128131

129132
idset_t const &get_marked_way_ids() override;

src/output.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class output_t
6262
virtual void stop() = 0;
6363
virtual void sync() = 0;
6464

65+
virtual void after_nodes() {}
66+
virtual void after_ways() {}
67+
6568
virtual void wait() {}
6669

6770
virtual osmium::index::IdSetSmall<osmid_t> const &get_marked_way_ids()

0 commit comments

Comments
 (0)