From ce75b4c6174daa71e11d37e8c4cc7e4e15e56b04 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 13 Feb 2025 10:00:44 +0100 Subject: [PATCH 1/2] Fix two-stage processing when flat node file is used This is an additional fix to the fix in 8d1a55e5. If a flat node file is used, nodes are not stored in the database (unless --middle-with-nodes is specified, but also then only nodes with tags are stored in the database). There are two problems here: 1. The "get_node" prepared statement was not prepared in this case, so it fails when executes. This is fixed by only executing that statement if m_store_options.nodes is set in the middle. 2. If there is no node in the database, there might still be one in the flat node file. So we need to try this and create the node from the information in there. (It will only have the node id and location in it, but at least we get the location.) This commit contains both fixes. --- src/middle-pgsql.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/middle-pgsql.cpp b/src/middle-pgsql.cpp index c0fd0c36f..655617ddb 100644 --- a/src/middle-pgsql.cpp +++ b/src/middle-pgsql.cpp @@ -762,17 +762,33 @@ bool middle_query_pgsql_t::node_get(osmid_t id, { assert(buffer); - auto const res = m_db_connection.exec_prepared("get_node", id); + if (m_store_options.nodes) { + auto const res = m_db_connection.exec_prepared("get_node", id); - if (res.num_tuples() != 1) { - return false; + if (res.num_tuples() == 1) { + build_node(id, res, 0, 0, buffer, m_store_options.with_attributes); + buffer->commit(); + return true; + } } - build_node(id, res, 0, 0, buffer, m_store_options.with_attributes); + if (m_store_options.use_flat_node_file) { + auto const location = get_node_location_flatnodes(id); + if (!location.valid()) { + return false; + } - buffer->commit(); + { + osmium::builder::NodeBuilder builder{*buffer}; + builder.set_id(id); + builder.set_location(location); + } - return true; + buffer->commit(); + return true; + } + + return false; } bool middle_query_pgsql_t::way_get(osmid_t id, From 45d16e0562d0b41301eea5375db5603421344ac4 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 13 Feb 2025 10:46:20 +0100 Subject: [PATCH 2/2] Look for nodes in cache in non-slim mode in two-stage processing Another addition to the same issue as in the previews commit: In non-slim mode look for node locations in the (on disk and ram) caches and create a node from there is a node is requested for further processing in two-stage processing. --- src/middle-ram.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/middle-ram.cpp b/src/middle-ram.cpp index 4c5bf995b..10c095960 100644 --- a/src/middle-ram.cpp +++ b/src/middle-ram.cpp @@ -283,8 +283,32 @@ bool middle_ram_t::node_get(osmid_t id, osmium::memory::Buffer *buffer) const assert(buffer); if (m_store_options.nodes) { - return get_object(osmium::item_type::node, id, buffer); + auto const got_it = get_object(osmium::item_type::node, id, buffer); + if (got_it) { + return true; + } } + + if (m_store_options.locations) { + osmium::Location location{}; + if (m_persistent_cache) { + location = m_persistent_cache->get(id); + } + if (!location.valid()) { + location = m_node_locations.get(id); + } + if (location.valid()) { + { + osmium::builder::NodeBuilder builder{*buffer}; + builder.set_id(id); + builder.set_location(location); + } + + buffer->commit(); + return true; + } + } + return false; }