@@ -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}
0 commit comments