Skip to content

Fix LSM snapshot restoration by resolving double path nesting#2111

Merged
kderme merged 1 commit intomasterfrom
fix/lsm-snapshot-doubled-path
Apr 28, 2026
Merged

Fix LSM snapshot restoration by resolving double path nesting#2111
kderme merged 1 commit intomasterfrom
fix/lsm-snapshot-doubled-path

Conversation

@ArturWieczorek
Copy link
Copy Markdown
Contributor

The LSM session was being initialised with the full lsmPath as both the HasBlockIO root and the session's FsPath inside it, producing a doubled on-disk layout like:
/lsm//lsm/{active,snapshots,...} instead of:
/lsm/{active,snapshots,...}.

Effect on snapshots: scripts/postgresql-setup.sh --create-snapshot looks for the LSM tree at /lsm/snapshots/, didn't find it because of the doubled path, silently fell back to the InMemory branch, and produced a tarball missing the LSM tree files. On --restore-snapshot

  • db-sync startup the snapshot couldn't be loaded (ErrSnapshotDoesNotExist) and sync replayed from genesis.

Fix:
Pass mkFsPath [] as the session's FsPath so it's rooted at the HasBlockIO root directly. Also harden the snapshot script to abort with a clear error when an lsm/ subtree exists but no LSM snapshot is found at the expected path, instead of producing an incomplete tarball.

Files staged for commit:

  • cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs
  • scripts/postgresql-setup.sh

Description

Add your description here, if it fixes a particular issue please provide a link to the issue.

Checklist

  • Commit sequence broadly makes sense
  • Commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Any changes are noted in the changelog
  • Code is formatted with fourmolu on version 0.17.0.0 (which can be run with scripts/fourmolize.sh)
  • Self-reviewed the diff

Migrations

  • The pr causes a breaking change of type a,b or c
  • If there is a breaking change, the pr includes a database migration and/or a fix process for old values, so that upgrade is possible
  • Resyncing and running the migrations provided will result in the same database semantically

If there is a breaking change, especially a big one, please add a justification here. Please elaborate
more what the migration achieves, what it cannot achieve or why a migration is not possible.

The LSM session was being initialised with the full lsmPath as both the
HasBlockIO root and the session's FsPath inside it, producing a doubled
on-disk layout like:
<state-dir>/lsm/<state-dir>/lsm/{active,snapshots,...}
instead of:
<state-dir>/lsm/{active,snapshots,...}.

Effect on snapshots: scripts/postgresql-setup.sh --create-snapshot looks
for the LSM tree at <state-dir>/lsm/snapshots/<slot>, didn't find it
because of the doubled path, silently fell back to the InMemory branch,
and produced a tarball missing the LSM tree files. On --restore-snapshot
+ db-sync startup the snapshot couldn't be loaded (ErrSnapshotDoesNotExist)
and sync replayed from genesis.

Fix:
Pass mkFsPath [] as the session's FsPath so it's rooted at the
HasBlockIO root directly. Also harden the snapshot script to abort with
a clear error when an lsm/ subtree exists but no LSM snapshot is found
at the expected path, instead of producing an incomplete tarball.

Files staged for commit:
- cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs
- scripts/postgresql-setup.sh
@ArturWieczorek ArturWieczorek requested a review from a team as a code owner April 28, 2026 15:39
@kderme kderme merged commit 7549b99 into master Apr 28, 2026
21 checks passed
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.

2 participants