Skip to content

Commit

Permalink
Rename conninfo to connection_params everywhere
Browse files Browse the repository at this point in the history
This is really part of the previous commit but was factored out to keep
that one reasonably legible.
  • Loading branch information
joto committed Feb 1, 2024
1 parent 46ef18e commit abd6554
Show file tree
Hide file tree
Showing 30 changed files with 114 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/command-line-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ options_t parse_command_line(int argc, char *argv[])

check_options(&options);

options.conninfo = app.connection_params();
options.connection_params = app.connection_params();

if (!options.slim) {
options.middle_database_format = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/db-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
conn->exec(sql.data());
}

db_copy_thread_t::db_copy_thread_t(connection_params_t const &conninfo)
db_copy_thread_t::db_copy_thread_t(connection_params_t const &connection_params)
{
// Connection params are captured by copy here, because we don't know
// whether the reference will still be valid once we get around to running
// the thread.
m_worker = std::thread{thread_t{conninfo, &m_shared}};
m_worker = std::thread{thread_t{connection_params, &m_shared}};
}

db_copy_thread_t::~db_copy_thread_t() { finish(); }
Expand Down Expand Up @@ -120,15 +120,15 @@ void db_copy_thread_t::finish()
}
}

db_copy_thread_t::thread_t::thread_t(connection_params_t conninfo,
db_copy_thread_t::thread_t::thread_t(connection_params_t connection_params,
shared *shared)
: m_conninfo(std::move(conninfo)), m_shared(shared)
: m_connection_params(std::move(connection_params)), m_shared(shared)
{}

void db_copy_thread_t::thread_t::operator()()
{
try {
m_conn = std::make_unique<pg_conn_t>(m_conninfo);
m_conn = std::make_unique<pg_conn_t>(m_connection_params);

// Let commits happen faster by delaying when they actually occur.
m_conn->exec("SET synchronous_commit = off");
Expand Down
6 changes: 3 additions & 3 deletions src/db-copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ struct db_cmd_finish_t : public db_cmd_t
class db_copy_thread_t
{
public:
explicit db_copy_thread_t(connection_params_t const &conninfo);
explicit db_copy_thread_t(connection_params_t const &connection_params);

db_copy_thread_t(db_copy_thread_t const &) = delete;
db_copy_thread_t &operator=(db_copy_thread_t const &) = delete;
Expand Down Expand Up @@ -290,7 +290,7 @@ class db_copy_thread_t
class thread_t
{
public:
thread_t(connection_params_t conninfo, shared *shared);
thread_t(connection_params_t connection_params, shared *shared);

void operator()();

Expand All @@ -300,7 +300,7 @@ class db_copy_thread_t
void finish_copy();
void delete_rows(db_cmd_copy_t *buffer);

connection_params_t m_conninfo;
connection_params_t m_connection_params;
std::unique_ptr<pg_conn_t> m_conn;

// Target for copy operation currently ongoing.
Expand Down
11 changes: 6 additions & 5 deletions src/expire-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

#include <system_error>

std::size_t expire_output_t::output(quadkey_list_t const &tile_list,
connection_params_t const &conninfo) const
std::size_t
expire_output_t::output(quadkey_list_t const &tile_list,
connection_params_t const &connection_params) const
{
std::size_t num = 0;
if (!m_filename.empty()) {
num = output_tiles_to_file(tile_list);
}
if (!m_table.empty()) {
num = output_tiles_to_table(tile_list, conninfo);
num = output_tiles_to_table(tile_list, connection_params);
}
return num;
}
Expand Down Expand Up @@ -53,11 +54,11 @@ std::size_t expire_output_t::output_tiles_to_file(

std::size_t expire_output_t::output_tiles_to_table(
quadkey_list_t const &tiles_at_maxzoom,
connection_params_t const &conninfo) const
connection_params_t const &connection_params) const
{
auto const qn = qualified_name(m_schema, m_table);

pg_conn_t connection{conninfo};
pg_conn_t connection{connection_params};

auto const result = connection.exec("SELECT * FROM {} LIMIT 1", qn);

Expand Down
6 changes: 3 additions & 3 deletions src/expire-output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class expire_output_t
void set_maxzoom(uint32_t maxzoom) noexcept { m_maxzoom = maxzoom; }

std::size_t output(quadkey_list_t const &tile_list,
connection_params_t const &conninfo) const;
connection_params_t const &connection_params) const;

/**
* Write the list of tiles to a file.
Expand All @@ -67,11 +67,11 @@ class expire_output_t
* Write the list of tiles to a database table.
*
* \param tiles_at_maxzoom The list of tiles at maximum zoom level
* \param conninfo Database connection parameters
* \param connection_params Database connection parameters
*/
std::size_t
output_tiles_to_table(quadkey_list_t const &tiles_at_maxzoom,
connection_params_t const &conninfo) const;
connection_params_t const &connection_params) const;

/**
* Create table for tiles.
Expand Down
4 changes: 2 additions & 2 deletions src/flex-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ bool flex_table_t::has_columns_with_expire() const noexcept
[](auto const &column) { return column.has_expire(); });
}

void table_connection_t::connect(connection_params_t const &conninfo)
void table_connection_t::connect(connection_params_t const &connection_params)
{
assert(!m_db_connection);

m_db_connection = std::make_unique<pg_conn_t>(conninfo);
m_db_connection = std::make_unique<pg_conn_t>(connection_params);
m_db_connection->exec("SET synchronous_commit = off");
}

Expand Down
2 changes: 1 addition & 1 deletion src/flex-table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class table_connection_t
{
}

void connect(connection_params_t const &conninfo);
void connect(connection_params_t const &connection_params);

void start(bool append);

Expand Down
27 changes: 15 additions & 12 deletions src/gen/osm2pgsql-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class tile_processor_t
std::size_t m_num_tiles;
};

void run_tile_gen(connection_params_t const &conninfo,
void run_tile_gen(connection_params_t const &connection_params,
gen_base_t *master_generalizer, params_t params,
uint32_t zoom,
std::vector<std::pair<uint32_t, uint32_t>> *queue,
Expand All @@ -205,7 +205,7 @@ void run_tile_gen(connection_params_t const &conninfo,

log_debug("Started generalizer thread for '{}'.",
master_generalizer->strategy());
pg_conn_t db_connection{conninfo};
pg_conn_t db_connection{connection_params};
std::string const strategy{master_generalizer->strategy()};
auto generalizer = create_generalizer(strategy, &db_connection, &params);

Expand Down Expand Up @@ -233,7 +233,7 @@ class genproc_t
{
public:
genproc_t(std::string const &filename,
connection_params_t conninfo, std::string dbschema,
connection_params_t connection_params, std::string dbschema,
bool append, bool updatable, uint32_t jobs);

int app_define_table()
Expand Down Expand Up @@ -286,7 +286,7 @@ class genproc_t
write_to_debug_log(params, "Params (config):");

log_debug("Connecting to database...");
pg_conn_t db_connection{m_conninfo};
pg_conn_t db_connection{m_connection_params};

log_debug("Creating generalizer...");
auto generalizer =
Expand Down Expand Up @@ -368,7 +368,7 @@ class genproc_t
queries.emplace_back("COMMIT");
}

pg_conn_t const db_connection{m_conninfo};
pg_conn_t const db_connection{m_connection_params};

if (m_append && !if_has_rows.empty()) {
auto const result = db_connection.exec(if_has_rows);
Expand Down Expand Up @@ -496,8 +496,9 @@ class genproc_t
for (unsigned int n = 1;
n <= std::min(m_jobs, static_cast<uint32_t>(tile_list.size()));
++n) {
threads.emplace_back(run_tile_gen, m_conninfo, generalizer,
params, zoom, &tile_list, &mut, n);
threads.emplace_back(run_tile_gen, m_connection_params,
generalizer, params, zoom, &tile_list,
&mut, n);
}
for (auto &t : threads) {
t.join();
Expand All @@ -513,7 +514,7 @@ class genproc_t
std::vector<flex_table_t> m_tables;
std::vector<expire_output_t> m_expire_outputs;

connection_params_t m_conninfo;
connection_params_t m_connection_params;
std::string m_dbschema;
uint32_t m_jobs;
bool m_append;
Expand All @@ -525,11 +526,13 @@ TRAMPOLINE(app_define_expire_output, define_expire_output)
TRAMPOLINE(app_run_gen, run_gen)
TRAMPOLINE(app_run_sql, run_sql)

genproc_t::genproc_t(std::string const &filename, connection_params_t conninfo,
genproc_t::genproc_t(std::string const &filename,
connection_params_t connection_params,
std::string dbschema, bool append, bool updatable,
uint32_t jobs)
: m_conninfo(std::move(conninfo)), m_dbschema(std::move(dbschema)),
m_jobs(jobs), m_append(append), m_updatable(updatable)
: m_connection_params(std::move(connection_params)),
m_dbschema(std::move(dbschema)), m_jobs(jobs), m_append(append),
m_updatable(updatable)
{
setup_lua_environment(lua_state(), filename, append);

Expand Down Expand Up @@ -589,7 +592,7 @@ void genproc_t::run()
}

if (!m_append) {
pg_conn_t const db_connection{m_conninfo};
pg_conn_t const db_connection{m_connection_params};
for (auto const &table : m_tables) {
if (table.id_type() == flex_table_index_type::tile &&
(table.always_build_id_index() || m_updatable)) {
Expand Down
17 changes: 9 additions & 8 deletions src/middle-pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ void middle_pgsql_t::table_desc::drop_table(
}

void middle_pgsql_t::table_desc::build_index(
connection_params_t const &conninfo) const
connection_params_t const &connection_params) const
{
if (m_create_fw_dep_indexes.empty()) {
return;
}

// Use a temporary connection here because we might run in a separate
// thread context.
pg_conn_t const db_connection{conninfo};
pg_conn_t const db_connection{connection_params};

log_info("Building index on table '{}'", name());
for (auto const &query : m_create_fw_dep_indexes) {
Expand Down Expand Up @@ -1296,11 +1296,11 @@ void middle_pgsql_t::after_relations()
}

middle_query_pgsql_t::middle_query_pgsql_t(
connection_params_t const &conninfo,
connection_params_t const &connection_params,
std::shared_ptr<node_locations_t> cache,
std::shared_ptr<node_persistent_cache> persistent_cache,
middle_pgsql_options const &options)
: m_sql_conn(conninfo), m_cache(std::move(cache)),
: m_sql_conn(connection_params), m_cache(std::move(cache)),
m_persistent_cache(std::move(persistent_cache)), m_store_options(options)
{
// Disable JIT and parallel workers as they are known to cause
Expand Down Expand Up @@ -1409,7 +1409,7 @@ void middle_pgsql_t::stop()
// Building the indexes takes time, so do it asynchronously.
for (auto &table : m_tables) {
table.task_set(thread_pool().submit(
[&]() { table.build_index(m_options->conninfo); }));
[&]() { table.build_index(m_options->connection_params); }));
}
}
}
Expand Down Expand Up @@ -1649,8 +1649,8 @@ middle_pgsql_t::middle_pgsql_t(std::shared_ptr<thread_pool_t> thread_pool,
: middle_t(std::move(thread_pool)), m_options(options),
m_cache(std::make_unique<node_locations_t>(
static_cast<std::size_t>(options->cache) * 1024UL * 1024UL)),
m_db_connection(m_options->conninfo),
m_copy_thread(std::make_shared<db_copy_thread_t>(options->conninfo)),
m_db_connection(m_options->connection_params),
m_copy_thread(std::make_shared<db_copy_thread_t>(options->connection_params)),
m_db_copy(m_copy_thread), m_append(options->append)
{
m_store_options.with_attributes = options->extra_attributes;
Expand Down Expand Up @@ -1725,7 +1725,8 @@ middle_pgsql_t::get_query_instance()
// NOTE: this is thread safe for use in pending async processing only
// because during that process they are only read from
auto mid = std::make_unique<middle_query_pgsql_t>(
m_options->conninfo, m_cache, m_persistent_cache, m_store_options);
m_options->connection_params, m_cache, m_persistent_cache,
m_store_options);

// We use a connection per table to enable the use of COPY
for (auto &table : m_tables) {
Expand Down
4 changes: 2 additions & 2 deletions src/middle-pgsql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class middle_query_pgsql_t : public middle_query_t
{
public:
middle_query_pgsql_t(
connection_params_t const &conninfo,
connection_params_t const &connection_params,
std::shared_ptr<node_locations_t> cache,
std::shared_ptr<node_persistent_cache> persistent_cache,
middle_pgsql_options const &options);
Expand Down Expand Up @@ -151,7 +151,7 @@ struct middle_pgsql_t : public middle_t
void drop_table(pg_conn_t const &db_connection) const;

///< Open a new database connection and build index on this table.
void build_index(connection_params_t const &conninfo) const;
void build_index(connection_params_t const &connection_params) const;

std::string m_create_table;
std::vector<std::string> m_prepare_queries;
Expand Down
2 changes: 1 addition & 1 deletion src/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct options_t
command_t command = command_t::process;

/// Parameters for initializing database connections
connection_params_t conninfo;
connection_params_t connection_params;

std::string prefix{"planet_osm"}; ///< prefix for table names
bool prefix_is_set = false;
Expand Down
5 changes: 3 additions & 2 deletions src/osm2pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static file_info run(options_t const &options)

static void check_db(options_t const &options)
{
pg_conn_t const db_connection{options.conninfo};
pg_conn_t const db_connection{options.connection_params};

init_database_capabilities(db_connection);

Expand Down Expand Up @@ -372,7 +372,8 @@ int main(int argc, char *argv[])

check_db(options);

properties_t properties{options.conninfo, options.middle_dbschema};
properties_t properties{options.connection_params,
options.middle_dbschema};
if (options.append) {
if (properties.load()) {
check_and_update_properties(&properties, &options);
Expand Down
10 changes: 6 additions & 4 deletions src/osmdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
std::shared_ptr<middle_t> mid,
std::shared_ptr<output_t> output, options_t const &options)
: m_dependency_manager(std::move(dependency_manager)), m_mid(std::move(mid)),
m_output(std::move(output)), m_conninfo(options.conninfo),
m_output(std::move(output)), m_connection_params(options.connection_params),
m_bbox(options.bbox), m_num_procs(options.num_procs),
m_append(options.append), m_droptemp(options.droptemp),
m_with_extra_attrs(options.extra_attributes),
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace {
class multithreaded_processor
{
public:
multithreaded_processor(connection_params_t const &conninfo,
multithreaded_processor(connection_params_t const &connection_params,
std::shared_ptr<middle_t> const &mid,
std::shared_ptr<output_t> output,
std::size_t thread_count)
Expand All @@ -183,7 +183,8 @@ class multithreaded_processor
// For each thread we create a clone of the output.
for (std::size_t i = 0; i < thread_count; ++i) {
auto const midq = mid->get_query_instance();
auto copy_thread = std::make_shared<db_copy_thread_t>(conninfo);
auto copy_thread =
std::make_shared<db_copy_thread_t>(connection_params);
m_clones.push_back(m_output->clone(midq, copy_thread));
}
}
Expand Down Expand Up @@ -350,7 +351,8 @@ class multithreaded_processor

void osmdata_t::process_dependents() const
{
multithreaded_processor proc{m_conninfo, m_mid, m_output, m_num_procs};
multithreaded_processor proc{m_connection_params, m_mid, m_output,
m_num_procs};

// stage 1b processing: process parents of changed objects
if (m_dependency_manager->has_pending()) {
Expand Down
2 changes: 1 addition & 1 deletion src/osmdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class osmdata_t : public osmium::handler::Handler
std::shared_ptr<middle_t> m_mid;
std::shared_ptr<output_t> m_output;

connection_params_t m_conninfo;
connection_params_t m_connection_params;

// Bounding box for node import (or invalid Box if everything should be
// imported).
Expand Down
Loading

0 comments on commit abd6554

Please sign in to comment.