Repository navigation
Conversation
This was referenced Nov 21, 2026
cldellow
force-pushed
the
better-imports
branch
from
November 23, 2026 22:34
cc99851 to
ff0bed7
Compare
…ttic Node_Updater and Way_Updater initialise partial_possible to false when keeping attic data, but the constructor body then overwrites it with "the database files don't exist yet". So a fresh `update_database --keep-attic` import runs in partial mode, and partial mode clears new_skeletons, attic_skeletons and new_attic_skeletons after each node or way update. The way updater needs the new attic node skeletons to compute the geometry and index of older way versions, and the relation updater needs the new attic way skeletons likewise. Without them, a way version that is older than the latest move of one of its nodes gets an empty geometry and the invalid index, so [date:] queries by bounding box don't find it. Keep the initialiser's intent: partial updates only without attic data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
A full-history file (.osh, e.g. from `osmium cat x.osh.pbf -f osh`) marks deleted versions with visible="false" instead of wrapping them in <delete>. The parser ignored the attribute, so update_database stored each deleted version as a live object: a node at the out-of-range placeholder position (lat 100, lon 200), a way without nodes, a relation without members. Such objects were then returned by id queries, with or without [date:], as if never deleted. Pass elements with visible="false" to set_id_deleted, as for <delete>. This depends on keeping the new attic skeletons during a fresh attic import: without that, ways referring to a node that is deleted later lose that node's coordinates in their older versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
History data has way versions that refer to nodes deleted before them. In the extract this was found with, a way's nodes were deleted ten seconds before the way itself. compute_idx_and_geometry then skipped those nodes, so the stored way had fewer coordinates than nds. Overpass stores older way versions as deltas from the newer ones, so expanding any older version through that state fails with "Bad geometry for way", and [date:] queries lose the way for every date before it, not only for the ten seconds. Use the node's last known position instead, keeping one coordinate per nd. Do the same for node and way members when computing a relation's index. Before deletions in history files were honoured, such nodes stayed alive at the placeholder position, which hid this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
update_database flushes every --flush-size elements. The way updater computes the geometry of older way versions from the attic node versions of the current batch plus the current node positions, and the relation updater does the same with nodes and ways. When a history file's nodes span several batches (with the default flush size, any extract with more than a few million node versions), the attic versions written by earlier batches are not seen: older way versions get too few coordinates or the placeholder index, and the import can abort with "Bad geometry for way". When importing without dispatcher (Way_Updater and Relation_Updater constructed with a db_dir), also read the stored attic versions of all nodes, respectively nodes and ways, referenced by the batch, and merge them into the attic skeletons used for the computation. Updates via the dispatcher are unchanged. Memory: the added map holds the attic versions of the nodes (and ways) referred to by one batch of ways (relations), so it is bounded by the batch size times the number of versions of those elements. It is not counted towards any limit, like the other structures of the updater. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
update_database flushes once --flush-size elements have been read. In a history file the versions of an element are consecutive, so a flush could fall between two versions of one element. With the versions split over two batches, attic tags came out duplicated: in the extract this was found with, a relation whose versions were split showed every tag twice at later dates. Defer the flush until the next element has a different id. A batch then grows by at most the versions of one element. osmChange files are unaffected, since they rarely contain the same element twice in a row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
Since update_database flushes only between elements, an element with attic versions in the current batch has all its versions of this import in memory. Only the referenced elements without such versions need their stored attic versions read. This saves reading back, in a single-batch import, the whole attic history that was just written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
compute_idx_and_geometry skipped nodes it found neither in the attic nor in the current data. In a regional history extract that happens to nodes whose only version in the extract is their deletion, e.g. because they were outside the region while visible. The stored way version then had fewer coordinates than nds, and since older versions are stored as deltas from newer ones, expanding any older version through it failed with "Bad geometry for way", so [date:] queries lost the way for every earlier date. Do as compute_geometry already does for current versions: push a zero Quad_Coord for the unknown node, keeping the geometry aligned with the nds, and compute the index only from the nodes with a known position. Queries print such a node as a reference without coordinates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
Relations in a regional extract often have members outside it, and the relation updater computes a relation's index for each version and each intermediate state, printing a line per missing member each time. Importing a full-history extract of Prince Edward Island printed 66 million such lines for 85 thousand distinct missing members. std::cerr is unbuffered, so this took more than half of the import time. Print each missing member once per run. The set of reported members is bounded by the number of distinct missing members. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJV9ygtU1g57EBR2Ufo
cldellow
force-pushed
the
better-imports
branch
from
November 24, 2026 18:59
ff0bed7 to
3929511
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34, fixes #45, fixes #46, fixes #47, fixes #48, fixes #49, fixes #50.
What this is
better-importscombines every import change, cherry-picked ontoupstream/masterin this order. These changes fix howupdate_database --keep-atticstores a full-history file (.osh), so that databases with history can be built for testing. They are kept apart fromall-changes, which is for performance work. Each change also has its own PR for review. This PR tracks their combined effect, and is updated when a change is added or revised.--keep-atticimport no longer clears the node and way history that older way and relation versions need.oshfiles are deletions, not live objectsNone of the changes alters the database format or the query API.
osm3s_querydoesn't link any changed file, so query performance (the benchmark queries ofall-changes) is unaffected.How to build a database with history
Use
-f osh:-f osmdrops thevisible="false"markers of deleted versions.Correctness:
upstream/mastervsbetter-importsTwo Geofabrik full-history extracts (licensed, not shareable; aggregate numbers only):
For each date, all objects in the world box were compared with
osmium time-filter <file> <date>:Objects whose latest version at or before the date is a deletion were queried by id, in chunks of up to 2,000, from a random sample:
likewise with
way(id:<ids>)andrel(id:<ids>).upstream/masterbetter-importsupstream/masterbetter-imports--flush-size=1gave the same output for 1,497 of 1,500 differential fuzz queries (fuzz.py --db-b --features history,users,complete --seed 2; 3 skipped for timeouts).The
upstream/masterNova Scotia import wasn't run here; #34 has its numbers from an earlier session.Import time and memory
4-core, 15 GB cloud container, idle, stderr written to a file:
upstream/masterbetter-importsGenerated by Claude Code