Merge pull request #4506 from Roasbeef/free-list-sync-config-fix

config: make bbolt freelist settings mutually exclusive
This commit is contained in:
Conner Fromknecht 2020-08-05 11:37:27 -07:00 committed by GitHub
commit 0e558cfbed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 13 deletions

@ -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.

@ -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,

@ -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.

6
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(),
)
@ -269,7 +274,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 {