mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-20 04:21:37 +02:00
channeldb: add NoMigration mode
In case the channeldb package is used as a library in external tools, it can be useful to allow read-only access to a DB. This allows such a tool to access a DB even if not all migrations were executed, which can be useful for recovery purposes. To make it possible to even start the DB with a read-only backend, we need to disable the automatic migration step.
This commit is contained in:
@@ -263,15 +263,17 @@ func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) {
|
||||
// CreateWithBackend creates channeldb instance using the passed kvdb.Backend.
|
||||
// Any necessary schemas migrations due to updates will take place as necessary.
|
||||
func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB, error) {
|
||||
if err := initChannelDB(backend); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts := DefaultOptions()
|
||||
for _, modifier := range modifiers {
|
||||
modifier(&opts)
|
||||
}
|
||||
|
||||
if !opts.NoMigration {
|
||||
if err := initChannelDB(backend); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
chanDB := &DB{
|
||||
Backend: backend,
|
||||
channelStateDB: &ChannelStateDB{
|
||||
@@ -291,16 +293,18 @@ func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB,
|
||||
chanDB.graph, err = NewChannelGraph(
|
||||
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
|
||||
opts.UseGraphCache,
|
||||
opts.UseGraphCache, opts.NoMigration,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Synchronize the version of database and apply migrations if needed.
|
||||
if err := chanDB.syncVersions(dbVersions); err != nil {
|
||||
backend.Close()
|
||||
return nil, err
|
||||
if !opts.NoMigration {
|
||||
if err := chanDB.syncVersions(dbVersions); err != nil {
|
||||
backend.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return chanDB, nil
|
||||
|
Reference in New Issue
Block a user