Skip to content

feat: set transaction isolation to REPEATABLE_READ in DatabaseContext… - #164

Open
mabduelaziz wants to merge 1 commit into
openstreetmap:mainfrom
HudHud-Maps:main
Open

feat: set transaction isolation to REPEATABLE_READ in DatabaseContext…#164
mabduelaziz wants to merge 1 commit into
openstreetmap:mainfrom
HudHud-Maps:main

Conversation

@mabduelaziz

Copy link
Copy Markdown

OSMOSIS apidb read task: modify transaction isolation level from READ COMMITTED to REPEATABLE READ

Background

We are trying to use osmosis as a tool to dump a PBF snapshot file used by routing engines. But we are seeing issues with dangling references in the dump. We have narrowed down the issue to the apidb read task reading nodes, ways, and relations in sequence within a single transaction. Under PostgreSQL's default READ COMMITTED, each statement gets its own snapshot. If a writer commits between the nodes scan and the ways scan, the dump can include a way that references nodes it never read, producing a PBF with dangling references that downstream consumers reject.

Fix

The apidb read task opens a transaction at REPEATABLE READ and holds it for the full dump. The whole transaction sees one snapshot, so nodes and ways are read from a consistent point in time — no dangling references possible.

Since READ_COMMITTED and REPEATABLE READ don't use locks on PostgreSQL, this change doesn't require any additional locks.

Outcomes under concurrent writes

Under concurrent writes, the dump either includes both nodes and ways or orphan nodes. It is not possible to have dangling references. This is valid OSM data.

Notes

  • No schema changes, no write-side changes, no new locks (PostgreSQL REPEATABLE READ uses MVCC).

…2 to ensure consistent snapshot reads during data dumps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant