Skip to content

Commit

Permalink
Switch middle database default format to "new"
Browse files Browse the repository at this point in the history
  • Loading branch information
joto committed Feb 9, 2024
1 parent e6a3096 commit 3a460cd
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 60 deletions.
11 changes: 5 additions & 6 deletions man/osm2pgsql.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 29 additions & 26 deletions src/command-line-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -536,21 +531,10 @@ options_t parse_command_line(int argc, char *argv[])
->type_name("SCHEMA")
->group("Middle options");

std::string middle_database_format_raw;
// --middle-database-format
app.add_option_function<std::string>(
"--middle-database-format",
[&](std::string const &arg) {
if (arg == "legacy") {
options.middle_database_format = 1;
} else if (arg == "new") {
options.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').")
app.add_option("--middle-database-format", middle_database_format_raw)
->description("Set middle db format ('legacy', 'new' (default)).")
->type_name("FORMAT")
->group("Middle options");

Expand Down Expand Up @@ -703,7 +687,32 @@ options_t parse_command_line(int argc, char *argv[])
return options;
}

if (!options.slim) {
check_options(&options);

if (options.slim) { // slim mode, use database middle
if (middle_database_format_raw.empty()) {
// Database format not set on the command line, use defaults. For
// append mode we keep old default for backwards compatibility, for
// create mode the new format is the default. (These will possibly
// be overwritten later by properties setting if it exists.)
options.middle_database_format = options.append ? 1 : 2;
} else if (options.append) {
// Database format set on command line in append mode.
throw std::runtime_error{
"Do not use --middle-database-format with --append."};
} else {
// Database format set on the command line in create mode.
if (middle_database_format_raw == "legacy") {
options.middle_database_format = 1;
} else if (middle_database_format_raw == "new") {
options.middle_database_format = 2;
} else {
throw std::runtime_error{
"Unknown value for --middle-database-format"
" (Use 'legacy' or 'new')."};
}
}
} else { // non-slim mode, use ram middle
check_options_non_slim(app);
}

Expand Down Expand Up @@ -761,13 +770,7 @@ options_t parse_command_line(int argc, char *argv[])

check_options_expire(&options);

check_options(&options);

options.connection_params = app.connection_params();

if (!options.slim) {
options.middle_database_format = 0;
}

return options;
}
9 changes: 7 additions & 2 deletions src/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ 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;
/**
* Middle database format:
* 0 = non-slim mode, no database middle (ram middle)
* 1 = slim mode, legacy database format
* 2 = slim mode, new database format
*/
uint8_t middle_database_format = 0;

/**
* Should nodes (with tags) be stored in the middle? If no flat node file
Expand Down
2 changes: 1 addition & 1 deletion tests/bdd/command-line/invalid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions tests/bdd/regression/timestamps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions tests/common-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
38 changes: 19 additions & 19 deletions tests/test-middle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand All @@ -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)
{
Expand Down Expand Up @@ -367,9 +367,9 @@ static bool no_node(std::shared_ptr<middle_pgsql_t> 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<thread_pool_t>(1U);

Expand Down Expand Up @@ -586,9 +586,9 @@ static bool no_way(std::shared_ptr<middle_pgsql_t> 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<thread_pool_t>(1U);

Expand Down Expand Up @@ -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<thread_pool_t>(1U);

Expand Down Expand Up @@ -840,9 +840,9 @@ static bool no_relation(std::shared_ptr<middle_pgsql_t> 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<thread_pool_t>(1U);

Expand Down Expand Up @@ -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<thread_pool_t>(1U);

Expand Down Expand Up @@ -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<thread_pool_t>(1U);

Expand Down Expand Up @@ -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<thread_pool_t>(1U);

Expand Down

0 comments on commit 3a460cd

Please sign in to comment.