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:
5 files changed
+33
-13
No files matched your search
@@ -50,6 +50,11 @@ type Options struct {
|
||||
// path finding.
|
||||
UseGraphCache bool
|
||||
|
||||
// NoMigration specifies that underlying backend was opened in read-only
|
||||
// mode and migrations shouldn't be performed. This can be useful for
|
||||
// applications that use the channeldb package as a library.
|
||||
NoMigration bool
|
||||
|
||||
// clock is the time source used by the database.
|
||||
clock clock.Clock
|
||||
|
||||
@@ -71,6 +76,7 @@ func DefaultOptions() Options {
|
||||
ChannelCacheSize: DefaultChannelCacheSize,
|
||||
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
|
||||
UseGraphCache: true,
|
||||
NoMigration: false,
|
||||
clock: clock.NewDefaultClock(),
|
||||
}
|
||||
}
|
||||
@@ -136,6 +142,14 @@ func OptionSetBatchCommitInterval(interval time.Duration) OptionModifier {
|
||||
}
|
||||
}
|
||||
|
||||
// OptionNoMigration allows the database to be opened in read only mode by
|
||||
// disabling migrations.
|
||||
func OptionNoMigration(b bool) OptionModifier {
|
||||
return func(o *Options) {
|
||||
o.NoMigration = b
|
||||
}
|
||||
}
|
||||
|
||||
// OptionClock sets a non-default clock dependency.
|
||||
func OptionClock(clock clock.Clock) OptionModifier {
|
||||
return func(o *Options) {
|
||||
|
||||
Reference in new issue
Block a user