From fa96450db8872be22047783ad3ab0bbd8e188375 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 4 Oct 2019 11:19:34 -0400 Subject: [PATCH] channeldb: add freelist sync option modifier --- channeldb/db.go | 2 +- channeldb/options.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/channeldb/db.go b/channeldb/db.go index 4bcfa0f8a..667ea418d 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -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, } diff --git a/channeldb/options.go b/channeldb/options.go index a96ebfa90..38ac05efd 100644 --- a/channeldb/options.go +++ b/channeldb/options.go @@ -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 + } +}