migrate-db: skip missing source DBs by default#85
Open
0xfandom wants to merge 1 commit intolightninglabs:mainfrom
Open
migrate-db: skip missing source DBs by default#850xfandom wants to merge 1 commit intolightninglabs:mainfrom
0xfandom wants to merge 1 commit intolightninglabs:mainfrom
Conversation
Running migrate-db on a fresh node (no bbolt DBs yet) currently aborts with an unrecoverable "database does not exist" error on the first mandatory prefix. LND happily creates the destination SQL DB itself on first start, so a missing source is not actually a failure — it just means there is nothing to migrate. Treat ErrDbDoesNotExist on a mandatory prefix the same as on an optional one (log and continue), and gate the previous strict behavior behind a new opt-in flag: --error-if-no-bbolt-db-exists The flag is off by default so the no-op case becomes friendly to container/k8s init wrappers that always run migrate-db, and on for operators who want a hard failure when their bbolt files have gone missing unexpectedly. Fixes lightninglabs#77
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.
Summary
lndinit migrate-dbcurrently aborts on the first mandatory prefix withdatabase does not existwhen run against a fresh node (no bbolt files yet). For container/k8s init wrappers that always runmigrate-db, this means the wrapper has to special-case "no DBs yet" or LND never gets a chance to create the SQLite DB itself.This PR treats
ErrDbDoesNotExiston a mandatory prefix the same way it already treats it on an optional one (log + continue), and gates the previous strict behavior behind a new opt-in flag:Off by default so a fresh-node migration is a successful no-op; on for operators who want a hard failure if their bbolt files vanished unexpectedly.
The second flag suggested in the issue (
--tombstone-empty-db-if-no-bbolt-db-exists) is intentionally not part of this PR — its use case is unclear and it can be added cleanly on top later if someone wants it.Testing
TestMigrateDBNoBboltDBExistscovers both default-skip and flag-forces-error paths against an empty data dir.go test -tags="kvdb_etcd kvdb_postgres kvdb_sqlite" ./...clean.golangci-lint run --timeout 10m --build-tags="kvdb_etcd kvdb_postgres kvdb_sqlite" ./...clean (v1.64.8 fromtools/go.mod).lndinit migrate-db -hconfirms the new flag renders.Related
Fixes #77