Skip to content

Commit 835728d

Browse files
authored
Merge pull request #1198 from joto/split-processing
Split up processing into functions for each stage
2 parents 4702b23 + d774b57 commit 835728d

File tree

2 files changed

+65
-35
lines changed

2 files changed

+65
-35
lines changed

src/osmdata.cpp

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,9 @@ class multithreaded_processor
367367

368368
} // anonymous namespace
369369

370-
void osmdata_t::stop() const
370+
void osmdata_t::process_stage1b() const
371371
{
372-
/* Commit the transactions, so that multiple processes can
373-
* access the data simultaneously to process the rest in parallel
374-
* as well as see the newly created tables.
375-
*/
376-
m_mid->commit();
377-
for (auto &out : m_outs) {
378-
out->sync();
379-
}
380-
381-
// In append mode there might be dependent objects pending that we
382-
// need to process.
383-
if (m_append && m_dependency_manager->has_pending()) {
372+
if (m_dependency_manager->has_pending()) {
384373
multithreaded_processor proc{m_conninfo, m_mid, m_outs,
385374
(std::size_t)m_num_procs};
386375

@@ -389,36 +378,60 @@ void osmdata_t::stop() const
389378
m_dependency_manager->get_pending_relation_ids());
390379
proc.merge_expire_trees();
391380
}
381+
}
392382

383+
void osmdata_t::process_stage2() const
384+
{
393385
for (auto &out : m_outs) {
394386
out->stage2_proc();
395387
}
388+
}
396389

397-
// Clustering, index creation, and cleanup.
398-
// All the intensive parts of this are long-running PostgreSQL commands
399-
{
400-
osmium::thread::Pool pool{m_parallel_indexing ? m_num_procs : 1, 512};
390+
void osmdata_t::process_stage3() const
391+
{
392+
// All the intensive parts of this are long-running PostgreSQL commands.
393+
// They will be run in a thread pool.
394+
osmium::thread::Pool pool{m_parallel_indexing ? m_num_procs : 1, 512};
395+
396+
if (m_droptemp) {
397+
// When dropping middle tables, make sure they are gone before
398+
// indexing starts.
399+
m_mid->stop(pool);
400+
}
401401

402-
if (m_droptemp) {
403-
// When dropping middle tables, make sure they are gone before
404-
// indexing starts.
405-
m_mid->stop(pool);
406-
}
402+
for (auto &out : m_outs) {
403+
out->stop(&pool);
404+
}
407405

408-
for (auto &out : m_outs) {
409-
out->stop(&pool);
410-
}
406+
if (!m_droptemp) {
407+
// When keeping middle tables, there is quite a large index created
408+
// which is better done after the output tables have been copied.
409+
// Note that --disable-parallel-indexing needs to be used to really
410+
// force the order.
411+
m_mid->stop(pool);
412+
}
411413

412-
if (!m_droptemp) {
413-
// When keeping middle tables, there is quite a large index created
414-
// which is better done after the output tables have been copied.
415-
// Note that --disable-parallel-indexing needs to be used to really
416-
// force the order.
417-
m_mid->stop(pool);
418-
}
414+
// Waiting here for pool to execute all tasks.
415+
// XXX If one of them has an error, all other will finish first,
416+
// which may take a long time.
417+
}
418+
419+
void osmdata_t::stop() const
420+
{
421+
/* Commit the transactions, so that multiple processes can
422+
* access the data simultaneously to process the rest in parallel
423+
* as well as see the newly created tables.
424+
*/
425+
m_mid->commit();
426+
for (auto &out : m_outs) {
427+
out->sync();
428+
}
419429

420-
// Waiting here for pool to execute all tasks.
421-
// XXX If one of them has an error, all other will finish first,
422-
// which may take a long time.
430+
if (m_append) {
431+
process_stage1b();
423432
}
433+
434+
process_stage2();
435+
436+
process_stage3();
424437
}

src/osmdata.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ class osmdata_t
3737
void relation_delete(osmid_t id) const;
3838

3939
private:
40+
/**
41+
* Run stage 1b processing: Process dependent objects.
42+
* In append mode we need to process dependent objects that were marked
43+
* earlier.
44+
*/
45+
void process_stage1b() const;
46+
47+
/**
48+
* Run stage 2 processing: Process objects marked in stage 1 (if any).
49+
*/
50+
void process_stage2() const;
51+
52+
/**
53+
* Run stage 3 processing: Clustering and index creation.
54+
*/
55+
void process_stage3() const;
56+
4057
slim_middle_t &slim_middle() const noexcept;
4158

4259
std::unique_ptr<dependency_manager_t> m_dependency_manager;

0 commit comments

Comments
 (0)