Skip to content

Commit f6c414b

Browse files
committed
Remove support for multiple outputs
This was only needed for the multi output which was removed.
1 parent 60b17d4 commit f6c414b

File tree

6 files changed

+68
-137
lines changed

6 files changed

+68
-137
lines changed

src/osm2pgsql.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@ static void run(options_t const &options)
3232
auto middle = create_middle(options);
3333
middle->start();
3434

35-
auto const outputs =
36-
output_t::create_outputs(middle->get_query_instance(), options);
35+
auto output =
36+
output_t::create_output(middle->get_query_instance(), options);
3737

3838
auto dependency_manager = std::unique_ptr<dependency_manager_t>(
3939
options.with_forward_dependencies
4040
? new full_dependency_manager_t{middle}
4141
: new dependency_manager_t{});
4242

43-
osmdata_t osmdata{std::move(dependency_manager), middle, outputs,
44-
options};
43+
osmdata_t osmdata{std::move(dependency_manager), middle, output, options};
4544

4645
osmdata.start();
4746

src/osmdata.cpp

Lines changed: 39 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828

2929
osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
3030
std::shared_ptr<middle_t> mid,
31-
std::vector<std::shared_ptr<output_t>> outs,
32-
options_t const &options)
31+
std::shared_ptr<output_t> output, options_t const &options)
3332
: m_dependency_manager(std::move(dependency_manager)), m_mid(std::move(mid)),
34-
m_outs(std::move(outs)), m_conninfo(options.database_options.conninfo()),
33+
m_output(std::move(output)), m_conninfo(options.database_options.conninfo()),
3534
m_bbox(options.bbox), m_num_procs(options.num_procs),
3635
m_append(options.append), m_droptemp(options.droptemp),
3736
m_parallel_indexing(options.parallel_indexing),
@@ -40,7 +39,7 @@ osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
4039
{
4140
assert(m_dependency_manager);
4241
assert(m_mid);
43-
assert(!m_outs.empty());
42+
assert(m_output);
4443
}
4544

4645
void osmdata_t::node(osmium::Node const &node)
@@ -91,9 +90,7 @@ void osmdata_t::after_ways() { m_mid->after_ways(); }
9190
void osmdata_t::relation(osmium::Relation const &rel)
9291
{
9392
if (m_append && !rel.deleted()) {
94-
for (auto const &out : m_outs) {
95-
out->select_relation_members(rel.id());
96-
}
93+
m_output->select_relation_members(rel.id());
9794
}
9895

9996
m_mid->relation(rel);
@@ -117,81 +114,59 @@ void osmdata_t::after_relations() { m_mid->after_relations(); }
117114
void osmdata_t::node_add(osmium::Node const &node) const
118115
{
119116
if (m_with_extra_attrs || !node.tags().empty()) {
120-
for (auto const &out : m_outs) {
121-
out->node_add(node);
122-
}
117+
m_output->node_add(node);
123118
}
124119
}
125120

126121
void osmdata_t::way_add(osmium::Way *way) const
127122
{
128123
if (m_with_extra_attrs || !way->tags().empty()) {
129-
for (auto const &out : m_outs) {
130-
out->way_add(way);
131-
}
124+
m_output->way_add(way);
132125
}
133126
}
134127

135128
void osmdata_t::relation_add(osmium::Relation const &rel) const
136129
{
137130
if (m_with_extra_attrs || !rel.tags().empty()) {
138-
for (auto const &out : m_outs) {
139-
out->relation_add(rel);
140-
}
131+
m_output->relation_add(rel);
141132
}
142133
}
143134

144135
void osmdata_t::node_modify(osmium::Node const &node) const
145136
{
146-
for (auto const &out : m_outs) {
147-
out->node_modify(node);
148-
}
149-
137+
m_output->node_modify(node);
150138
m_dependency_manager->node_changed(node.id());
151139
}
152140

153141
void osmdata_t::way_modify(osmium::Way *way) const
154142
{
155-
for (auto const &out : m_outs) {
156-
out->way_modify(way);
157-
}
158-
143+
m_output->way_modify(way);
159144
m_dependency_manager->way_changed(way->id());
160145
}
161146

162147
void osmdata_t::relation_modify(osmium::Relation const &rel) const
163148
{
164-
for (auto const &out : m_outs) {
165-
out->relation_modify(rel);
166-
}
149+
m_output->relation_modify(rel);
167150
}
168151

169152
void osmdata_t::node_delete(osmid_t id) const
170153
{
171-
for (auto const &out : m_outs) {
172-
out->node_delete(id);
173-
}
154+
m_output->node_delete(id);
174155
}
175156

176157
void osmdata_t::way_delete(osmid_t id) const
177158
{
178-
for (auto const &out : m_outs) {
179-
out->way_delete(id);
180-
}
159+
m_output->way_delete(id);
181160
}
182161

183162
void osmdata_t::relation_delete(osmid_t id) const
184163
{
185-
for (auto const &out : m_outs) {
186-
out->relation_delete(id);
187-
}
164+
m_output->relation_delete(id);
188165
}
189166

190167
void osmdata_t::start() const
191168
{
192-
for (auto const &out : m_outs) {
193-
out->start();
194-
}
169+
m_output->start();
195170
}
196171

197172
namespace {
@@ -205,24 +180,20 @@ namespace {
205180
class multithreaded_processor
206181
{
207182
public:
208-
using output_vec_t = std::vector<std::shared_ptr<output_t>>;
209-
210183
multithreaded_processor(std::string const &conninfo,
211184
std::shared_ptr<middle_t> const &mid,
212-
output_vec_t outs, size_t thread_count)
213-
: m_outputs(std::move(outs))
185+
std::shared_ptr<output_t> output,
186+
std::size_t thread_count)
187+
: m_output(std::move(output))
214188
{
215-
assert(!m_outputs.empty());
189+
assert(mid);
190+
assert(m_output);
216191

217-
// For each thread we create clones of all the outputs.
218-
m_clones.resize(thread_count);
219-
for (size_t i = 0; i < thread_count; ++i) {
192+
// For each thread we create a clone of the output.
193+
for (std::size_t i = 0; i < thread_count; ++i) {
220194
auto const midq = mid->get_query_instance();
221195
auto copy_thread = std::make_shared<db_copy_thread_t>(conninfo);
222-
223-
for (auto const &out : m_outputs) {
224-
m_clones[i].push_back(out->clone(midq, copy_thread));
225-
}
196+
m_clones.push_back(m_output->clone(midq, copy_thread));
226197
}
227198
}
228199

@@ -262,17 +233,12 @@ class multithreaded_processor
262233

263234
/**
264235
* Collect expiry tree information from all clones and merge it back
265-
* into the original outputs.
236+
* into the original output.
266237
*/
267238
void merge_expire_trees()
268239
{
269-
std::size_t n = 0;
270-
for (auto const &output : m_outputs) {
271-
for (auto const &clone : m_clones) {
272-
assert(n < clone.size());
273-
output->merge_expire_trees(clone[n].get());
274-
}
275-
++n;
240+
for (auto const &clone : m_clones) {
241+
m_output->merge_expire_trees(clone.get());
276242
}
277243
}
278244

@@ -296,23 +262,15 @@ class multithreaded_processor
296262

297263
/**
298264
* Runs in the worker threads: As long as there are any, get ids from
299-
* the queue and let the outputs process it by calling "func".
265+
* the queue and let the output process it by calling "func".
300266
*/
301-
static void run(output_vec_t const &outputs, idlist_t *queue,
267+
static void run(std::shared_ptr<output_t> output, idlist_t *queue,
302268
std::mutex *mutex, output_member_fn_ptr func)
303269
{
304270
while (osmid_t const id = pop_id(queue, mutex)) {
305-
for (auto const &output : outputs) {
306-
if (output) {
307-
(output.get()->*func)(id);
308-
}
309-
}
310-
}
311-
for (auto const &output : outputs) {
312-
if (output) {
313-
output->sync();
314-
}
271+
(output.get()->*func)(id);
315272
}
273+
output->sync();
316274
}
317275

318276
/// Runs in a worker thread: Update progress display once per second.
@@ -375,11 +333,11 @@ class multithreaded_processor
375333
timer.per_second(ids_queued));
376334
}
377335

378-
/// Clones of all outputs, one vector of clones per thread.
379-
std::vector<output_vec_t> m_clones;
336+
/// Clones of output, one clone per thread.
337+
std::vector<std::shared_ptr<output_t>> m_clones;
380338

381-
/// All outputs.
382-
output_vec_t m_outputs;
339+
/// The output.
340+
std::shared_ptr<output_t> m_output;
383341

384342
/// Mutex to make sure worker threads coordinate access to queue.
385343
std::mutex m_mutex;
@@ -389,7 +347,7 @@ class multithreaded_processor
389347

390348
void osmdata_t::process_dependents() const
391349
{
392-
multithreaded_processor proc{m_conninfo, m_mid, m_outs,
350+
multithreaded_processor proc{m_conninfo, m_mid, m_output,
393351
(std::size_t)m_num_procs};
394352

395353
// stage 1b processing: process parents of changed objects
@@ -401,10 +359,8 @@ void osmdata_t::process_dependents() const
401359
}
402360

403361
// stage 1c processing: mark parent relations of marked objects as changed
404-
for (auto &out : m_outs) {
405-
for (auto const id : out->get_marked_way_ids()) {
406-
m_dependency_manager->way_changed(id);
407-
}
362+
for (auto const id : m_output->get_marked_way_ids()) {
363+
m_dependency_manager->way_changed(id);
408364
}
409365

410366
// process parent relations of marked ways
@@ -414,12 +370,7 @@ void osmdata_t::process_dependents() const
414370
}
415371
}
416372

417-
void osmdata_t::reprocess_marked() const
418-
{
419-
for (auto &out : m_outs) {
420-
out->reprocess_marked();
421-
}
422-
}
373+
void osmdata_t::reprocess_marked() const { m_output->reprocess_marked(); }
423374

424375
void osmdata_t::postprocess_database() const
425376
{
@@ -436,9 +387,7 @@ void osmdata_t::postprocess_database() const
436387
m_mid->stop(pool);
437388
}
438389

439-
for (auto &out : m_outs) {
440-
out->stop(&pool);
441-
}
390+
m_output->stop(&pool);
442391

443392
if (!m_droptemp) {
444393
// When keeping middle tables, there is quite a large index created
@@ -455,9 +404,7 @@ void osmdata_t::postprocess_database() const
455404

456405
void osmdata_t::stop() const
457406
{
458-
for (auto &out : m_outs) {
459-
out->sync();
460-
}
407+
m_output->sync();
461408

462409
if (m_append && m_with_forward_dependencies) {
463410
process_dependents();

src/osmdata.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020

2121
#include <memory>
22-
#include <vector>
2322

2423
#include <osmium/fwd.hpp>
2524
#include <osmium/handler.hpp>
@@ -35,14 +34,13 @@ struct middle_t;
3534
/**
3635
* This class guides the processing of the OSM data through its multiple
3736
* stages. It calls upon the major compontents of osm2pgsql, the dependency
38-
* manager, the middle, and the outputs to do their work.
37+
* manager, the middle, and the output to do their work.
3938
*/
4039
class osmdata_t : public osmium::handler::Handler
4140
{
4241
public:
4342
osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
44-
std::shared_ptr<middle_t> mid,
45-
std::vector<std::shared_ptr<output_t>> outs,
43+
std::shared_ptr<middle_t> mid, std::shared_ptr<output_t> output,
4644
options_t const &options);
4745

4846
void start() const;
@@ -92,7 +90,7 @@ class osmdata_t : public osmium::handler::Handler
9290

9391
std::unique_ptr<dependency_manager_t> m_dependency_manager;
9492
std::shared_ptr<middle_t> m_mid;
95-
std::vector<std::shared_ptr<output_t>> m_outs;
93+
std::shared_ptr<output_t> m_output;
9694

9795
std::string m_conninfo;
9896

src/output.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,32 @@
2727
#include <cstring>
2828
#include <stdexcept>
2929

30-
std::vector<std::shared_ptr<output_t>>
31-
output_t::create_outputs(std::shared_ptr<middle_query_t> const &mid,
32-
options_t const &options)
30+
std::shared_ptr<output_t>
31+
output_t::create_output(std::shared_ptr<middle_query_t> const &mid,
32+
options_t const &options)
3333
{
34-
std::vector<std::shared_ptr<output_t>> outputs;
3534
auto copy_thread =
3635
std::make_shared<db_copy_thread_t>(options.database_options.conninfo());
3736

3837
if (options.output_backend == "pgsql") {
39-
outputs.push_back(
40-
std::make_shared<output_pgsql_t>(mid, options, copy_thread));
38+
return std::make_shared<output_pgsql_t>(mid, options, copy_thread);
4139

4240
#ifdef HAVE_LUA
4341
} else if (options.output_backend == "flex") {
44-
outputs.push_back(
45-
std::make_shared<output_flex_t>(mid, options, copy_thread));
42+
return std::make_shared<output_flex_t>(mid, options, copy_thread);
4643
#endif
4744

4845
} else if (options.output_backend == "gazetteer") {
49-
outputs.push_back(
50-
std::make_shared<output_gazetteer_t>(mid, options, copy_thread));
46+
return std::make_shared<output_gazetteer_t>(mid, options, copy_thread);
5147

5248
} else if (options.output_backend == "null") {
53-
outputs.push_back(std::make_shared<output_null_t>(mid, options));
54-
55-
} else {
56-
throw std::runtime_error{
57-
"Output backend `{}' not recognised. Should be one "
58-
"of [pgsql, " flex_backend
59-
"gazetteer, null].\n"_format(options.output_backend)};
60-
}
61-
62-
if (outputs.empty()) {
63-
throw std::runtime_error{"Must have at least one output, "
64-
"but none have been configured."};
49+
return std::make_shared<output_null_t>(mid, options);
6550
}
6651

67-
return outputs;
52+
throw std::runtime_error{
53+
"Output backend '{}' not recognised. Should be one "
54+
"of [pgsql, " flex_backend
55+
"gazetteer, null]."_format(options.output_backend)};
6856
}
6957

7058
output_t::output_t(std::shared_ptr<middle_query_t> const &mid,

0 commit comments

Comments
 (0)