From 8ca573282e4b300055cb67b7609ebb8a7fdd0ae4 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Fri, 26 Jan 2024 16:52:00 +0100 Subject: [PATCH] Switch middle database default format to "new" --- man/osm2pgsql.md | 11 ++++--- src/command-line-parser.cpp | 29 ++++++++++++------- src/options.hpp | 2 +- tests/bdd/command-line/invalid.feature | 2 +- tests/bdd/regression/timestamps.feature | 12 ++++---- tests/common-options.hpp | 2 ++ tests/test-middle.cpp | 38 ++++++++++++------------- 7 files changed, 52 insertions(+), 44 deletions(-) diff --git a/man/osm2pgsql.md b/man/osm2pgsql.md index 17869eb9c..d7e170407 100644 --- a/man/osm2pgsql.md +++ b/man/osm2pgsql.md @@ -179,12 +179,11 @@ mandatory for short options too. \--middle-database-format=FORMAT : Set the database format for the middle tables to FORMAT. Allowed formats - are **legacy** and **new**. The **legacy** format is the old format that - will eventually be deprecated and removed but is currently still the - default. The **new** format was introduced in version 1.9.0. - See the manual for details on these formats. (Only works - with **\--slim**. In append mode osm2pgsql will automatically detect the - database format, so don't use this with **-a, \--append**.) + are **new** (default) and **legacy** . The **legacy** format is deprecated + and will be removed in version 2.0.0. See the manual for details on these + formats. (Only works with **\--slim**. In append mode osm2pgsql will + automatically detect the database format, so don't use this with + **-a, \--append**.) \--middle-with-nodes : Used together with the **new** middle database format when a flat nodes diff --git a/src/command-line-parser.cpp b/src/command-line-parser.cpp index 11b545d4b..80ba25ceb 100644 --- a/src/command-line-parser.cpp +++ b/src/command-line-parser.cpp @@ -221,11 +221,6 @@ static void check_options(options_t *options) throw std::runtime_error{"--drop only makes sense with --slim."}; } - if (options->append && options->middle_database_format != 1) { - throw std::runtime_error{ - "Do not use --middle-database-format with --append."}; - } - if (options->cache < 0) { options->cache = 0; log_warn("RAM cache cannot be negative. Using 0 instead."); @@ -536,21 +531,22 @@ options_t parse_command_line(int argc, char *argv[]) ->type_name("SCHEMA") ->group("Middle options"); + uint8_t middle_database_format = 0; // --middle-database-format app.add_option_function( "--middle-database-format", [&](std::string const &arg) { if (arg == "legacy") { - options.middle_database_format = 1; + middle_database_format = 1; } else if (arg == "new") { - options.middle_database_format = 2; + middle_database_format = 2; } else { throw std::runtime_error{ "Unknown value for --middle-database-format" " (Use 'legacy' or 'new')."}; } }) - ->description("Set middle db format ('legacy' (default), 'new').") + ->description("Set middle db format ('legacy', 'new' (default)).") ->type_name("FORMAT") ->group("Middle options"); @@ -763,11 +759,22 @@ options_t parse_command_line(int argc, char *argv[]) check_options(&options); - options.connection_params = app.connection_params(); + if (middle_database_format) { + // Format was set explicitly. + if (options.append) { + throw std::runtime_error{ + "Do not use --middle-database-format with --append."}; + } - if (!options.slim) { - options.middle_database_format = 0; + options.middle_database_format = middle_database_format; + } else if (options.slim) { + // For append mode we keep old default for backwards compatibility, + // for create mode the new format is the default. + // Will be overwritten by properties setting if it exists. + options.middle_database_format = options.append ? 1 : 2; } + options.connection_params = app.connection_params(); + return options; } diff --git a/src/options.hpp b/src/options.hpp index 458927d95..f9cda40f5 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -116,7 +116,7 @@ struct options_t uint8_t way_node_index_id_shift = 5; /// Database format (0=unknown/no database middle, 1=legacy, 2=new) - uint8_t middle_database_format = 1; + uint8_t middle_database_format = 0; /** * Should nodes (with tags) be stored in the middle? If no flat node file diff --git a/tests/bdd/command-line/invalid.feature b/tests/bdd/command-line/invalid.feature index 012fdb503..49ab7455a 100644 --- a/tests/bdd/command-line/invalid.feature +++ b/tests/bdd/command-line/invalid.feature @@ -24,7 +24,7 @@ Feature: Errors for invalid command line parameter combinations Scenario: append and middle-database-format cannot be used together Then running osm2pgsql pgsql with parameters fails - | -a | --slim | --middle-database-format=new | + | -a | --slim | --middle-database-format=legacy | And the error output contains """ Do not use --middle-database-format with --append. diff --git a/tests/bdd/regression/timestamps.feature b/tests/bdd/regression/timestamps.feature index 56edb1631..fca9e776b 100644 --- a/tests/bdd/regression/timestamps.feature +++ b/tests/bdd/regression/timestamps.feature @@ -55,7 +55,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file And table osm2pgsql_properties contains | property | value | | attributes | false | - | db_format | 1 | + | db_format | 2 | | flat_node_file | | | prefix | planet_osm | | updatable | true | @@ -76,7 +76,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file And table osm2pgsql_properties contains | property | value | | attributes | false | - | db_format | 1 | + | db_format | 2 | | flat_node_file | | | prefix | planet_osm | | updatable | true | @@ -99,7 +99,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file And table osm2pgsql_properties contains | property | value | | attributes | false | - | db_format | 1 | + | db_format | 2 | | flat_node_file | | | prefix | planet_osm | | updatable | true | @@ -120,7 +120,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file And table osm2pgsql_properties contains | property | value | | attributes | false | - | db_format | 1 | + | db_format | 2 | | flat_node_file | | | prefix | planet_osm | | updatable | true | @@ -143,7 +143,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file And table osm2pgsql_properties contains | property | value | | attributes | false | - | db_format | 1 | + | db_format | 2 | | flat_node_file | | | prefix | planet_osm | | updatable | true | @@ -162,7 +162,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file And table osm2pgsql_properties contains | property | value | | attributes | false | - | db_format | 1 | + | db_format | 2 | | flat_node_file | | | prefix | planet_osm | | updatable | true | diff --git a/tests/common-options.hpp b/tests/common-options.hpp index 446289a62..ac9691ecb 100644 --- a/tests/common-options.hpp +++ b/tests/common-options.hpp @@ -38,12 +38,14 @@ class opt_t opt_t &slim() { m_opt.slim = true; + m_opt.middle_database_format = 2; return *this; } opt_t &slim(testing::pg::tempdb_t const &db) { m_opt.slim = true; + m_opt.middle_database_format = 2; m_opt.connection_params = db.connection_params(); return *this; } diff --git a/tests/test-middle.cpp b/tests/test-middle.cpp index 7438b4476..9f36536fb 100644 --- a/tests/test-middle.cpp +++ b/tests/test-middle.cpp @@ -83,22 +83,22 @@ struct options_flat_node_cache } }; -struct options_slim_new_format +struct options_slim_legacy_format { static options_t options(testing::pg::tempdb_t const &tmpdb) { options_t o = testing::opt_t().slim(tmpdb); - o.middle_database_format = 2; + o.middle_database_format = 1; return o; } }; -struct options_slim_new_format_with_flatnodes +struct options_slim_legacy_format_with_flatnodes { static options_t options(testing::pg::tempdb_t const &tmpdb) { options_t o = testing::opt_t().slim(tmpdb).flatnodes(); - o.middle_database_format = 2; + o.middle_database_format = 1; return o; } }; @@ -112,7 +112,7 @@ struct options_ram_optimized }; TEMPLATE_TEST_CASE("middle import", "", options_slim_default, - options_slim_new_format, options_slim_with_lc_prefix, + options_slim_legacy_format, options_slim_with_lc_prefix, options_slim_with_uc_prefix, options_slim_with_schema, options_ram_optimized) { @@ -367,9 +367,9 @@ static bool no_node(std::shared_ptr const &mid, osmid_t id) } TEMPLATE_TEST_CASE("middle: add, delete and update node", "", - options_slim_default, options_slim_new_format, + options_slim_default, options_slim_legacy_format, options_flat_node_cache, - options_slim_new_format_with_flatnodes) + options_slim_legacy_format_with_flatnodes) { auto thread_pool = std::make_shared(1U); @@ -586,9 +586,9 @@ static bool no_way(std::shared_ptr const &mid, osmid_t id) } TEMPLATE_TEST_CASE("middle: add, delete and update way", "", - options_slim_default, options_slim_new_format, + options_slim_default, options_slim_legacy_format, options_flat_node_cache, - options_slim_new_format_with_flatnodes) + options_slim_legacy_format_with_flatnodes) { auto thread_pool = std::make_shared(1U); @@ -739,8 +739,8 @@ TEMPLATE_TEST_CASE("middle: add, delete and update way", "", } TEMPLATE_TEST_CASE("middle: add way with attributes", "", options_slim_default, - options_slim_new_format, options_flat_node_cache, - options_slim_new_format_with_flatnodes) + options_slim_legacy_format, options_flat_node_cache, + options_slim_legacy_format_with_flatnodes) { auto thread_pool = std::make_shared(1U); @@ -840,9 +840,9 @@ static bool no_relation(std::shared_ptr const &mid, osmid_t id) } TEMPLATE_TEST_CASE("middle: add, delete and update relation", "", - options_slim_default, options_slim_new_format, + options_slim_default, options_slim_legacy_format, options_flat_node_cache, - options_slim_new_format_with_flatnodes) + options_slim_legacy_format_with_flatnodes) { auto thread_pool = std::make_shared(1U); @@ -993,9 +993,9 @@ TEMPLATE_TEST_CASE("middle: add, delete and update relation", "", } TEMPLATE_TEST_CASE("middle: add relation with attributes", "", - options_slim_default, options_slim_new_format, + options_slim_default, options_slim_legacy_format, options_flat_node_cache, - options_slim_new_format_with_flatnodes) + options_slim_legacy_format_with_flatnodes) { auto thread_pool = std::make_shared(1U); @@ -1042,8 +1042,8 @@ TEMPLATE_TEST_CASE("middle: add relation with attributes", "", } TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default, - options_slim_new_format, options_flat_node_cache, - options_slim_new_format_with_flatnodes) + options_slim_legacy_format, options_flat_node_cache, + options_slim_legacy_format_with_flatnodes) { auto thread_pool = std::make_shared(1U); @@ -1198,8 +1198,8 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default, } TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default, - options_slim_new_format, options_flat_node_cache, - options_slim_new_format_with_flatnodes) + options_slim_legacy_format, options_flat_node_cache, + options_slim_legacy_format_with_flatnodes) { auto thread_pool = std::make_shared(1U);