Skip to content

Commit e64d8fd

Browse files
committed
move table to db_copy classes
1 parent a0bd896 commit e64d8fd

24 files changed

+340
-366
lines changed

db-copy.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ class db_copy_mgr_t
281281
m_current->buffer += std::to_string(value);
282282
}
283283

284+
void add_value(double value)
285+
{
286+
char tmp[32];
287+
snprintf(tmp, sizeof(tmp), "%g", value);
288+
m_current->buffer += tmp;
289+
}
290+
284291
void add_value(std::string const &s) { add_value(s.c_str()); }
285292

286293
void add_value(char const *s)

expire-tiles.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <cerrno>
1515
#include <string>
1616

17+
#include <boost/format.hpp>
18+
1719
#include "expire-tiles.hpp"
1820
#include "options.hpp"
1921
#include "reprojection.hpp"

osmdata.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <osmium/thread/pool.hpp>
1010

11+
#include "db-copy.hpp"
1112
#include "middle.hpp"
1213
#include "node-ram-cache.hpp"
1314
#include "osmdata.hpp"
@@ -247,11 +248,13 @@ struct pending_threaded_processor : public middle_t::pending_processor {
247248
for (size_t i = 0; i < thread_count; ++i) {
248249
//clone the middle
249250
auto mid_clone = mid->get_query_instance(mid);
251+
auto copy_thread = std::make_shared<db_copy_thread_t>(
252+
outs[0]->get_options()->database_options.conninfo());
250253

251254
//clone the outs
252255
output_vec_t out_clones;
253256
for (const auto& out: outs) {
254-
out_clones.push_back(out->clone(mid_clone));
257+
out_clones.push_back(out->clone(mid_clone, copy_thread));
255258
}
256259

257260
//keep the clones for a specific thread to use

output-gazetteer.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
class output_gazetteer_t : public output_t
1919
{
2020
output_gazetteer_t(output_gazetteer_t const *other,
21-
std::shared_ptr<middle_query_t> const &cloned_mid)
22-
: output_t(cloned_mid, other->m_options),
23-
m_copy(std::make_shared<db_copy_thread_t>(
24-
other->m_options.database_options.conninfo())),
21+
std::shared_ptr<middle_query_t> const &cloned_mid,
22+
std::shared_ptr<db_copy_thread_t> const &copy_thread)
23+
: output_t(cloned_mid, other->m_options), m_copy(copy_thread),
2524
m_conn(nullptr), m_builder(other->m_options.projection, true),
2625
osmium_buffer(PLACE_BUFFER_SIZE, osmium::memory::Buffer::auto_grow::yes)
2726
{
@@ -31,10 +30,10 @@ class output_gazetteer_t : public output_t
3130

3231
public:
3332
output_gazetteer_t(std::shared_ptr<middle_query_t> const &mid,
34-
options_t const &options)
35-
: output_t(mid, options), m_copy(std::make_shared<db_copy_thread_t>(
36-
options.database_options.conninfo())),
37-
m_conn(nullptr), m_builder(options.projection, true),
33+
options_t const &options,
34+
std::shared_ptr<db_copy_thread_t> const &copy_thread)
35+
: output_t(mid, options), m_copy(copy_thread), m_conn(nullptr),
36+
m_builder(options.projection, true),
3837
osmium_buffer(PLACE_BUFFER_SIZE, osmium::memory::Buffer::auto_grow::yes)
3938
{
4039
m_style.load_style(options.style);
@@ -43,9 +42,11 @@ class output_gazetteer_t : public output_t
4342
virtual ~output_gazetteer_t();
4443

4544
std::shared_ptr<output_t>
46-
clone(std::shared_ptr<middle_query_t> const &mid) const override
45+
clone(std::shared_ptr<middle_query_t> const &mid,
46+
std::shared_ptr<db_copy_thread_t> const &copy_thread) const override
4747
{
48-
return std::shared_ptr<output_t>(new output_gazetteer_t(this, mid));
48+
return std::shared_ptr<output_t>(
49+
new output_gazetteer_t(this, mid, copy_thread));
4950
}
5051

5152
int start() override;

output-multi.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include <boost/algorithm/string/predicate.hpp>
1212
#include <vector>
1313

14-
output_multi_t::output_multi_t(std::string const &name,
15-
std::shared_ptr<geometry_processor> processor_,
16-
export_list const &export_list,
17-
std::shared_ptr<middle_query_t> const &mid,
18-
options_t const &options)
14+
output_multi_t::output_multi_t(
15+
std::string const &name, std::shared_ptr<geometry_processor> processor_,
16+
export_list const &export_list, std::shared_ptr<middle_query_t> const &mid,
17+
options_t const &options,
18+
std::shared_ptr<db_copy_thread_t> const &copy_thread)
1919
: output_t(mid, options),
2020
m_tagtransform(tagtransform_t::make_tagtransform(&m_options, export_list)),
2121
m_processor(processor_), m_proj(m_options.projection),
@@ -27,7 +27,7 @@ output_multi_t::output_multi_t(std::string const &name,
2727
m_table(new table_t(name, m_processor->column_type(),
2828
export_list.normal_columns(m_osm_type),
2929
m_options.hstore_columns, m_processor->srid(),
30-
m_options.append, m_options.hstore_mode)),
30+
m_options.append, m_options.hstore_mode, copy_thread)),
3131
ways_done_tracker(new id_tracker()),
3232
m_expire(m_options.expire_tiles_zoom, m_options.expire_tiles_max_bbox,
3333
m_options.projection),
@@ -37,12 +37,14 @@ output_multi_t::output_multi_t(std::string const &name,
3737
{
3838
}
3939

40-
output_multi_t::output_multi_t(output_multi_t const *other,
41-
std::shared_ptr<middle_query_t> const &mid)
40+
output_multi_t::output_multi_t(
41+
output_multi_t const *other, std::shared_ptr<middle_query_t> const &mid,
42+
std::shared_ptr<db_copy_thread_t> const &copy_thread)
4243
: output_t(mid, other->m_options),
4344
m_tagtransform(other->m_tagtransform->clone()),
4445
m_processor(other->m_processor), m_proj(other->m_proj),
45-
m_osm_type(other->m_osm_type), m_table(new table_t(*other->m_table)),
46+
m_osm_type(other->m_osm_type),
47+
m_table(new table_t(*other->m_table, copy_thread)),
4648
// NOTE: we need to know which ways were used by relations so each thread
4749
// must have a copy of the original marked done ways, its read only so its
4850
// ok
@@ -57,10 +59,12 @@ output_multi_t::output_multi_t(output_multi_t const *other,
5759

5860
output_multi_t::~output_multi_t() = default;
5961

60-
std::shared_ptr<output_t>
61-
output_multi_t::clone(std::shared_ptr<middle_query_t> const &mid) const
62+
std::shared_ptr<output_t> output_multi_t::clone(
63+
std::shared_ptr<middle_query_t> const &mid,
64+
std::shared_ptr<db_copy_thread_t> const &copy_thread) const
6265
{
63-
return std::shared_ptr<output_t>(new output_multi_t(this, mid));
66+
return std::shared_ptr<output_t>(
67+
new output_multi_t(this, mid, copy_thread));
6468
}
6569

6670
int output_multi_t::start() {

output-multi.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ struct options_t;
2626
class output_multi_t : public output_t
2727
{
2828
output_multi_t(output_multi_t const *other,
29-
std::shared_ptr<middle_query_t> const &mid);
29+
std::shared_ptr<middle_query_t> const &mid,
30+
std::shared_ptr<db_copy_thread_t> const &copy_thread);
3031

3132
public:
3233
output_multi_t(std::string const &name,
3334
std::shared_ptr<geometry_processor> processor_,
3435
export_list const &export_list,
3536
std::shared_ptr<middle_query_t> const &mid,
36-
options_t const &options);
37+
options_t const &options,
38+
std::shared_ptr<db_copy_thread_t> const &copy_thread);
3739
virtual ~output_multi_t();
3840

3941
std::shared_ptr<output_t>
40-
clone(std::shared_ptr<middle_query_t> const &mid) const override;
42+
clone(std::shared_ptr<middle_query_t> const &mid,
43+
std::shared_ptr<db_copy_thread_t> const &copy_thread) const override;
4144

4245
int start() override;
4346
void stop(osmium::thread::Pool *pool) override;

output-null.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "osmtypes.hpp"
22
#include "output-null.hpp"
33

4-
struct middle_query_t;
5-
struct options_t;
6-
74
void output_null_t::cleanup() {
85
}
96

@@ -63,9 +60,10 @@ int output_null_t::relation_modify(osmium::Relation const &) {
6360
}
6461

6562
std::shared_ptr<output_t>
66-
output_null_t::clone(std::shared_ptr<middle_query_t> const &mid) const
63+
output_null_t::clone(std::shared_ptr<middle_query_t> const &mid,
64+
std::shared_ptr<db_copy_thread_t> const &) const
6765
{
68-
return std::shared_ptr<output_t>(new output_null_t(this, mid));
66+
return std::shared_ptr<output_t>(new output_null_t(mid, m_options));
6967
}
7068

7169
output_null_t::output_null_t(std::shared_ptr<middle_query_t> const &mid,
@@ -74,10 +72,4 @@ output_null_t::output_null_t(std::shared_ptr<middle_query_t> const &mid,
7472
{
7573
}
7674

77-
output_null_t::output_null_t(output_null_t const *other,
78-
std::shared_ptr<middle_query_t> const &mid)
79-
: output_t(mid, other->m_options)
80-
{
81-
}
82-
8375
output_null_t::~output_null_t() = default;

output-null.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
#include "output.hpp"
88

99
class output_null_t : public output_t {
10-
output_null_t(output_null_t const *other,
11-
std::shared_ptr<middle_query_t> const &mid);
12-
1310
public:
1411
output_null_t(std::shared_ptr<middle_query_t> const &mid,
1512
options_t const &options);
1613
virtual ~output_null_t();
1714

1815
std::shared_ptr<output_t>
19-
clone(std::shared_ptr<middle_query_t> const &mid) const override;
16+
clone(std::shared_ptr<middle_query_t> const &mid,
17+
std::shared_ptr<db_copy_thread_t> const &copy_thread) const override;
2018

2119
int start() override;
2220
void stop(osmium::thread::Pool *pool) override;

output-pgsql.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,17 @@ int output_pgsql_t::start()
499499
return 0;
500500
}
501501

502-
std::shared_ptr<output_t>
503-
output_pgsql_t::clone(std::shared_ptr<middle_query_t> const &mid) const
502+
std::shared_ptr<output_t> output_pgsql_t::clone(
503+
std::shared_ptr<middle_query_t> const &mid,
504+
std::shared_ptr<db_copy_thread_t> const &copy_thread) const
504505
{
505-
return std::shared_ptr<output_t>(new output_pgsql_t(this, mid));
506+
return std::shared_ptr<output_t>(
507+
new output_pgsql_t(this, mid, copy_thread));
506508
}
507509

508-
output_pgsql_t::output_pgsql_t(std::shared_ptr<middle_query_t> const &mid,
509-
options_t const &o)
510+
output_pgsql_t::output_pgsql_t(
511+
std::shared_ptr<middle_query_t> const &mid, options_t const &o,
512+
std::shared_ptr<db_copy_thread_t> const &copy_thread)
510513
: output_t(mid, o), m_builder(o.projection, o.enable_multi),
511514
expire(o.expire_tiles_zoom, o.expire_tiles_max_bbox, o.projection),
512515
ways_done_tracker(new id_tracker()),
@@ -552,15 +555,16 @@ output_pgsql_t::output_pgsql_t(std::shared_ptr<middle_query_t> const &mid,
552555
util::exit_nicely();
553556
}
554557

555-
m_tables[i].reset(new table_t(name, type, columns,
556-
m_options.hstore_columns,
557-
m_options.projection->target_srs(),
558-
m_options.append, m_options.hstore_mode));
558+
m_tables[i].reset(
559+
new table_t(name, type, columns, m_options.hstore_columns,
560+
m_options.projection->target_srs(), m_options.append,
561+
m_options.hstore_mode, copy_thread));
559562
}
560563
}
561564

562-
output_pgsql_t::output_pgsql_t(output_pgsql_t const *other,
563-
std::shared_ptr<middle_query_t> const &mid)
565+
output_pgsql_t::output_pgsql_t(
566+
output_pgsql_t const *other, std::shared_ptr<middle_query_t> const &mid,
567+
std::shared_ptr<db_copy_thread_t> const &copy_thread)
564568
: output_t(mid, other->m_options),
565569
m_tagtransform(other->m_tagtransform->clone()),
566570
m_enable_way_area(other->m_enable_way_area),
@@ -575,12 +579,12 @@ output_pgsql_t::output_pgsql_t(output_pgsql_t const *other,
575579
{
576580
for (size_t i = 0; i < t_MAX; ++i) {
577581
//copy constructor will just connect to the already there table
578-
m_tables[i].reset(new table_t(*(other->m_tables[i].get())));
582+
m_tables[i].reset(
583+
new table_t(*(other->m_tables[i].get()), copy_thread));
579584
}
580585
}
581586

582-
output_pgsql_t::~output_pgsql_t() {
583-
}
587+
output_pgsql_t::~output_pgsql_t() = default;
584588

585589
size_t output_pgsql_t::pending_count() const {
586590
return ways_pending_tracker.size() + rels_pending_tracker.size();

output-pgsql.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef OUTPUT_PGSQL_H
77
#define OUTPUT_PGSQL_H
88

9+
#include "db-copy.hpp"
910
#include "expire-tiles.hpp"
1011
#include "id-tracker.hpp"
1112
#include "osmium-builder.hpp"
@@ -18,19 +19,22 @@
1819

1920
class output_pgsql_t : public output_t {
2021
output_pgsql_t(output_pgsql_t const *other,
21-
std::shared_ptr<middle_query_t> const &mid);
22+
std::shared_ptr<middle_query_t> const &mid,
23+
std::shared_ptr<db_copy_thread_t> const &copy_thread);
2224

2325
public:
2426
enum table_id {
2527
t_point = 0, t_line, t_poly, t_roads, t_MAX
2628
};
2729

2830
output_pgsql_t(std::shared_ptr<middle_query_t> const &mid,
29-
options_t const &options);
31+
options_t const &options,
32+
std::shared_ptr<db_copy_thread_t> const &copy_thread);
3033
virtual ~output_pgsql_t();
3134

3235
std::shared_ptr<output_t>
33-
clone(std::shared_ptr<middle_query_t> const &mid) const override;
36+
clone(std::shared_ptr<middle_query_t> const &mid,
37+
std::shared_ptr<db_copy_thread_t> const &copy_thread) const override;
3438

3539
int start() override;
3640
void stop(osmium::thread::Pool *pool) override;

0 commit comments

Comments
 (0)