Skip to content

Commit 0372425

Browse files
authored
Merge pull request #1155 from joto/refactor-dependency-tracking-step3
Refactor dependency tracking step3
2 parents b59e10e + efff241 commit 0372425

File tree

5 files changed

+21
-93
lines changed

5 files changed

+21
-93
lines changed

src/middle-pgsql.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void middle_pgsql_t::way_delete(osmid_t osm_id)
438438
m_db_copy.delete_object(osm_id);
439439
}
440440

441-
void middle_pgsql_t::iterate_ways(middle_t::pending_processor &pf)
441+
void middle_pgsql_t::iterate_ways(pending_processor &pf)
442442
{
443443
// enqueue the jobs
444444
osmid_t id;

src/middle-pgsql.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct middle_pgsql_t : public slim_middle_t
8080

8181
void flush() override;
8282

83-
void iterate_ways(middle_t::pending_processor &pf) override;
83+
void iterate_ways(pending_processor &pf) override;
8484
void iterate_relations(pending_processor &pf) override;
8585

8686
bool has_pending() const override;

src/middle-ram.cpp

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
* emit the final geometry-enabled output formats
88
*/
99

10-
#include <stdexcept>
11-
1210
#include <cassert>
13-
#include <cstdio>
11+
#include <memory>
1412

1513
#include <osmium/builder/attr.hpp>
1614

17-
#include "id-tracker.hpp"
1815
#include "middle-ram.hpp"
1916
#include "node-ram-cache.hpp"
2017
#include "options.hpp"
@@ -64,38 +61,8 @@ size_t middle_ram_t::nodes_get_list(osmium::WayNodeList *nodes) const
6461
return count;
6562
}
6663

67-
void middle_ram_t::iterate_relations(pending_processor &pf)
68-
{
69-
//TODO: just dont do anything
70-
71-
//let the outputs enqueue everything they have the non slim middle
72-
//has nothing of its own to enqueue as it doesnt have pending anything
73-
pf.enqueue_relations(id_tracker::max());
74-
75-
//let the threads process the relations
76-
pf.process_relations();
77-
}
78-
79-
void middle_ram_t::iterate_ways(middle_t::pending_processor &pf)
80-
{
81-
//let the outputs enqueue everything they have the non slim middle
82-
//has nothing of its own to enqueue as it doesnt have pending anything
83-
pf.enqueue_ways(id_tracker::max());
84-
85-
//let the threads process the ways
86-
pf.process_ways();
87-
}
88-
89-
void middle_ram_t::release_relations() { m_rels.clear(); }
90-
91-
void middle_ram_t::release_ways() { m_ways.clear(); }
92-
9364
bool middle_ram_t::way_get(osmid_t id, osmium::memory::Buffer &buffer) const
9465
{
95-
if (m_simulate_ways_deleted) {
96-
return false;
97-
}
98-
9966
auto const *ele = m_ways.get(id);
10067

10168
if (!ele) {
@@ -143,46 +110,26 @@ bool middle_ram_t::relation_get(osmid_t id,
143110
return true;
144111
}
145112

146-
void middle_ram_t::analyze()
147-
{ /* No need */
148-
}
149-
150-
void middle_ram_t::start() {}
151-
152113
void middle_ram_t::stop(osmium::thread::Pool &)
153114
{
154-
m_cache.reset(nullptr);
155-
156-
release_ways();
157-
release_relations();
115+
m_cache.reset();
116+
m_ways.clear();
117+
m_rels.clear();
158118
}
159119

160-
void middle_ram_t::commit() {}
161-
162120
middle_ram_t::middle_ram_t(options_t const *options)
163121
: m_ways(), m_rels(),
164122
m_cache(new node_ram_cache{options->alloc_chunkwise, options->cache}),
165-
m_extra_attributes(options->extra_attributes), m_simulate_ways_deleted(false)
123+
m_extra_attributes(options->extra_attributes)
166124
{}
167125

168-
middle_ram_t::~middle_ram_t()
169-
{
170-
//instance.reset();
171-
}
172-
173126
idlist_t middle_ram_t::relations_using_way(osmid_t) const
174127
{
175-
// this function shouldn't be called - relations_using_way is only used in
176-
// slim mode, and a middle_ram_t shouldn't be constructed if the slim mode
177-
// option is set.
178-
throw std::runtime_error{
179-
"middle_ram_t::relations_using_way is unimplemented, and "
180-
"should not have been called. This is probably a bug, please "
181-
"report it at https://github.com/openstreetmap/osm2pgsql/issues"};
128+
assert(false && "Should only be called in slim mode");
129+
return {};
182130
}
183131

184-
std::shared_ptr<middle_query_t>
185-
middle_ram_t::get_query_instance()
132+
std::shared_ptr<middle_query_t> middle_ram_t::get_query_instance()
186133
{
187134
return shared_from_this();
188135
}

src/middle-ram.hpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ class elem_cache_t
9292
struct middle_ram_t : public middle_t, public middle_query_t
9393
{
9494
middle_ram_t(options_t const *options);
95-
virtual ~middle_ram_t();
95+
virtual ~middle_ram_t() noexcept = default;
9696

97-
void start() override;
97+
void start() override {}
9898
void stop(osmium::thread::Pool &pool) override;
99-
void analyze(void) override;
100-
void commit(void) override;
99+
void analyze() override {}
100+
void commit() override {}
101101

102102
void node_set(osmium::Node const &node) override;
103103
size_t nodes_get_list(osmium::WayNodeList *nodes) const override;
@@ -115,17 +115,14 @@ struct middle_ram_t : public middle_t, public middle_query_t
115115

116116
idlist_t relations_using_way(osmid_t way_id) const override;
117117

118-
void iterate_ways(middle_t::pending_processor &pf) override;
119-
void iterate_relations(pending_processor &pf) override;
118+
void iterate_ways(pending_processor &) override {}
119+
void iterate_relations(pending_processor &) override {}
120120

121121
bool has_pending() const override { return false; }
122122

123123
std::shared_ptr<middle_query_t> get_query_instance() override;
124124

125125
private:
126-
void release_ways();
127-
void release_relations();
128-
129126
struct ramWay
130127
{
131128
taglist_t tags;
@@ -159,13 +156,6 @@ struct middle_ram_t : public middle_t, public middle_query_t
159156

160157
std::unique_ptr<node_ram_cache> m_cache;
161158
bool m_extra_attributes;
162-
163-
/* the previous behaviour of iterate_ways was to delete all ways as they
164-
* were being iterated. this doesn't work now that the output handles its
165-
* own "done" status and output-specific "pending" status. however, the
166-
* tests depend on the behaviour that ways will be unavailable once
167-
* iterate_ways is complete, so this flag emulates that. */
168-
bool m_simulate_ways_deleted;
169159
};
170160

171161
#endif // OSM2PGSQL_MIDDLE_RAM_HPP

src/osmdata.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,14 @@ void osmdata_t::stop() const
409409
// should be the same for all outputs
410410
auto const *opts = m_outs[0]->get_options();
411411

412-
// are there any objects left pending?
413-
if (m_mid->has_pending()) {
414-
//threaded pending processing
412+
// In append mode there might be dependent objects pending that we
413+
// need to process.
414+
if (opts->append && m_mid->has_pending()) {
415415
pending_threaded_processor ptp(m_mid, m_outs, opts->num_procs,
416416
opts->append);
417417

418-
if (!m_outs.empty()) {
419-
//This stage takes ways which were processed earlier, but might be
420-
//involved in a multipolygon relation. They could also be ways that
421-
//were modified in diff processing.
422-
m_mid->iterate_ways(ptp);
423-
424-
//This is like pending ways, except there aren't pending relations
425-
//on import, only on update.
426-
//TODO: Can we skip this on import?
427-
m_mid->iterate_relations(ptp);
428-
}
418+
m_mid->iterate_ways(ptp);
419+
m_mid->iterate_relations(ptp);
429420
}
430421

431422
for (auto &out : m_outs) {

0 commit comments

Comments
 (0)