From 66d15c8e766a1f0aa8b784c1833d7d0afc24087a Mon Sep 17 00:00:00 2001 From: nsa Date: Mon, 8 Jul 2019 18:41:25 -0400 Subject: [PATCH] channeldb + wtdb: specify freelist bbolt options by default This commit specifies two bbolt options when opening the underlying channel and watchtower databases so that there is reduced heap pressure in case the bbolt database has a lot of free pages in the B+ tree. --- channeldb/db.go | 9 ++++++++- watchtower/wtdb/db_common.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/channeldb/db.go b/channeldb/db.go index e9a9a185..0fa3953f 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -135,7 +135,14 @@ func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) { modifier(&opts) } - bdb, err := bbolt.Open(path, dbFilePermission, nil) + // Specify bbolt freelist options to reduce heap pressure in case the + // freelist grows to be very large. + options := &bbolt.Options{ + NoFreelistSync: true, + FreelistType: bbolt.FreelistMapType, + } + + bdb, err := bbolt.Open(path, dbFilePermission, options) if err != nil { return nil, err } diff --git a/watchtower/wtdb/db_common.go b/watchtower/wtdb/db_common.go index 63bca9ae..ed6f1c6b 100644 --- a/watchtower/wtdb/db_common.go +++ b/watchtower/wtdb/db_common.go @@ -63,7 +63,14 @@ func createDBIfNotExist(dbPath, name string) (*bbolt.DB, bool, error) { } } - bdb, err := bbolt.Open(path, dbFilePermission, nil) + // Specify bbolt freelist options to reduce heap pressure in case the + // freelist grows to be very large. + options := &bbolt.Options{ + NoFreelistSync: true, + FreelistType: bbolt.FreelistMapType, + } + + bdb, err := bbolt.Open(path, dbFilePermission, options) if err != nil { return nil, false, err }