Skip to content

Commit 7549b99

Browse files
authored
Merge pull request #2111 from IntersectMBO/fix/lsm-snapshot-doubled-path
Fix LSM snapshot restoration by resolving double path nesting
2 parents d323ee3 + 45d54e3 commit 7549b99

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ import Ouroboros.Network.Block (HeaderHash, pointSlot)
118118
import System.FS.API (SomeHasFS (..), mkFsPath)
119119
import System.FS.API.Types (MountPoint (..))
120120
import System.FS.IO (ioHasFS)
121-
import System.FilePath (splitDirectories, (</>))
121+
import System.FilePath ((</>))
122122
import System.Mem (performMajorGC)
123123
import System.Random (genWord64, newStdGen)
124124

@@ -227,7 +227,13 @@ mkHasLedgerEnv trce protoInfo dir nw maxLovelaceSupply systemStart syncOptions b
227227
LedgerBackendLSM mPath -> do
228228
let lsmPath = fromMaybe (unLedgerStateDir dir </> "lsm") mPath
229229
salt <- fst . genWord64 <$> newStdGen
230-
let args = LSM.LSMArgs (mkFsPath $ splitDirectories lsmPath) salt (LSM.stdMkBlockIOFS lsmPath)
230+
-- The HasBlockIO is rooted at lsmPath, so the session's FsPath inside it
231+
-- must be the empty path. Passing the full lsmPath here causes the LSM
232+
-- session to be created at <lsmPath>/<lsmPath>, which breaks snapshot
233+
-- bundling in scripts/postgresql-setup.sh (it falls back to the InMemory
234+
-- branch and ships an incomplete tarball; on restore db-sync then can't
235+
-- find the snapshot and replays from genesis).
236+
let args = LSM.LSMArgs (mkFsPath []) salt (LSM.stdMkBlockIOFS lsmPath)
231237
res <-
232238
runWithTempRegistry $
233239
(,())

scripts/postgresql-setup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ function create_snapshot {
176176
# The active/ directory is not needed — it gets cleared on session restore.
177177
tar czf "${tmp_dir}/${ledger_dir_name}.tar.gz" \
178178
-C "${state_dir}" "${ledger_dir_name}" "lsm/snapshots/${ledger_dir_name}" "lsm/metadata"
179+
elif [ -d "${state_dir}/lsm" ]; then
180+
# State directory contains an lsm/ subtree but the expected snapshot path is missing.
181+
# Refuse to silently fall back to the InMemory branch — the resulting tarball would
182+
# exclude the LSM tree files and restoration would replay from genesis.
183+
echo "ERROR: ${state_dir}/lsm exists but no LSM snapshot found at ${lsm_snap_dir}." >&2
184+
echo " The LSM session may be using a non-standard layout. Aborting to avoid" >&2
185+
echo " producing an incomplete snapshot." >&2
186+
rm "${recursive}" "${force}" "${tmp_dir}"
187+
exit 1
179188
else
180189
echo "Detected InMemory backend snapshot at slot ${ledger_dir_name}"
181190
# InMemory backend: just the ledger snapshot directory

0 commit comments

Comments
 (0)