channeldb: add freelist sync option modifier

This commit is contained in:
Wilmer Paulino 2019-10-04 11:19:34 -04:00
parent 194a9dea81
commit fa96450db8
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
2 changed files with 14 additions and 1 deletions

@ -85,7 +85,7 @@ func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) {
// Specify bbolt freelist options to reduce heap pressure in case the
// freelist grows to be very large.
options := &bbolt.Options{
NoFreelistSync: true,
NoFreelistSync: opts.NoFreelistSync,
FreelistType: bbolt.FreelistMapType,
}

@ -21,6 +21,11 @@ type Options struct {
// ChannelCacheSize is the maximum number of ChannelEdges to hold in the
// channel cache.
ChannelCacheSize int
// NoFreelistSync, if true, prevents the database from syncing its
// freelist to disk, resulting in improved performance at the expense of
// increased startup time.
NoFreelistSync bool
}
// DefaultOptions returns an Options populated with default values.
@ -28,6 +33,7 @@ func DefaultOptions() Options {
return Options{
RejectCacheSize: DefaultRejectCacheSize,
ChannelCacheSize: DefaultChannelCacheSize,
NoFreelistSync: true,
}
}
@ -47,3 +53,10 @@ func OptionSetChannelCacheSize(n int) OptionModifier {
o.ChannelCacheSize = n
}
}
// OptionSetSyncFreelist allows the database to sync its freelist.
func OptionSetSyncFreelist(b bool) OptionModifier {
return func(o *Options) {
o.NoFreelistSync = !b
}
}