From 675c1b95c91f3da51cb997948a16d42d4d8b3f2e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 4 Aug 2020 15:33:21 -0700 Subject: [PATCH 1/3] lnd: don't set freelist value when creating channeldb This value actually isn't read anywhere, since it's no longer used. Instead, `cfg.Db.Bolt.NoSyncFreeList` is what's evaluated when we go to open the DB. --- lnd.go | 1 - 1 file changed, 1 deletion(-) diff --git a/lnd.go b/lnd.go index cccf30e61..ddce659af 100644 --- a/lnd.go +++ b/lnd.go @@ -269,7 +269,6 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error { chanDbBackend, channeldb.OptionSetRejectCacheSize(cfg.Caches.RejectCacheSize), channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize), - channeldb.OptionSetSyncFreelist(cfg.SyncFreelist), channeldb.OptionDryRunMigration(cfg.DryRunMigration), ) switch { From e616903d4f62ba3ff026e09a82d85f47bfca991d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 4 Aug 2020 15:34:29 -0700 Subject: [PATCH 2/3] config: unify old and new config values for sync-freelist In this commit, unify the old and new values for `sync-freelist`, and also ensure that we don't break behavior for any users that're using the _old_ value. To do this, we first rename what was `--db.bolt.no-sync-freelist`, to `--db.bolt.sync-freelist`. This gets rid of the negation on the config level, and lets us override that value if the user is specifying the legacy config option. In the future, we'll deprecate the old config option, in favor of the new DB scoped option. --- channeldb/kvdb/config.go | 2 +- config.go | 8 ++++++++ lncfg/db.go | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/channeldb/kvdb/config.go b/channeldb/kvdb/config.go index a4ed68bab..179fde78a 100644 --- a/channeldb/kvdb/config.go +++ b/channeldb/kvdb/config.go @@ -12,7 +12,7 @@ const EtcdBackendName = "etcd" // BoltConfig holds bolt configuration. type BoltConfig struct { - NoFreeListSync bool `long:"nofreelistsync" description:"If true, prevents the database from syncing its freelist to disk"` + SyncFreelist bool `long:"nofreelistsync" description:"Whether the databases used within lnd should sync their freelist to disk. This is disabled by default resulting in improved memory performance during operation, but with an increase in startup time."` } // EtcdConfig holds etcd configuration. diff --git a/config.go b/config.go index 3a52ca964..7913f04ea 100644 --- a/config.go +++ b/config.go @@ -1097,6 +1097,14 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) { "minbackoff") } + // Newer versions of lnd added a new sub-config for bolt-specific + // parameters. However we want to also allow existing users to use the + // value on the top-level config. If the outer config value is set, + // then we'll use that directly. + if cfg.SyncFreelist { + cfg.DB.Bolt.SyncFreelist = cfg.SyncFreelist + } + // Validate the subconfigs for workers, caches, and the tower client. err = lncfg.Validate( cfg.Workers, diff --git a/lncfg/db.go b/lncfg/db.go index d63da8caf..6bc1e9a3b 100644 --- a/lncfg/db.go +++ b/lncfg/db.go @@ -9,8 +9,8 @@ import ( const ( dbName = "channel.db" - boltBackend = "bolt" - etcdBackend = "etcd" + BoltBackend = "bolt" + EtcdBackend = "etcd" ) // DB holds database configuration for LND. @@ -25,26 +25,24 @@ type DB struct { // NewDB creates and returns a new default DB config. func DefaultDB() *DB { return &DB{ - Backend: boltBackend, - Bolt: &kvdb.BoltConfig{ - NoFreeListSync: true, - }, + Backend: BoltBackend, + Bolt: &kvdb.BoltConfig{}, } } // Validate validates the DB config. func (db *DB) Validate() error { switch db.Backend { - case boltBackend: + case BoltBackend: - case etcdBackend: + case EtcdBackend: if db.Etcd.Host == "" { return fmt.Errorf("etcd host must be set") } default: return fmt.Errorf("unknown backend, must be either \"%v\" or \"%v\"", - boltBackend, etcdBackend) + BoltBackend, EtcdBackend) } return nil @@ -54,12 +52,14 @@ func (db *DB) Validate() error { func (db *DB) GetBackend(ctx context.Context, dbPath string, networkName string) (kvdb.Backend, error) { - if db.Backend == etcdBackend { + if db.Backend == EtcdBackend { // Prefix will separate key/values in the db. return kvdb.GetEtcdBackend(ctx, networkName, db.Etcd) } - return kvdb.GetBoltBackend(dbPath, dbName, db.Bolt.NoFreeListSync) + // The implementation by walletdb accepts "noFreelistSync" as the + // second parameter, so we negate here. + return kvdb.GetBoltBackend(dbPath, dbName, !db.Bolt.SyncFreelist) } // Compile-time constraint to ensure Workers implements the Validator interface. From 19f68d2538dc59f502524295cbfeb0ec607da2c0 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 4 Aug 2020 16:17:03 -0700 Subject: [PATCH 3/3] lnd: log bbolt freelist sync config value on start up --- lnd.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lnd.go b/lnd.go index ddce659af..7cfae4c3d 100644 --- a/lnd.go +++ b/lnd.go @@ -255,6 +255,11 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error { ctx, cancel := context.WithCancel(ctx) defer cancel() + if cfg.DB.Backend == lncfg.BoltBackend { + ltndLog.Infof("Opening bbolt database, sync_freelist=%v", + cfg.DB.Bolt.SyncFreelist) + } + chanDbBackend, err := cfg.DB.GetBackend(ctx, cfg.localDatabaseDir(), cfg.networkName(), )