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.
This commit is contained in:
Olaoluwa Osuntokun 2020-08-04 15:34:29 -07:00
parent 675c1b95c9
commit e616903d4f
No known key found for this signature in database
GPG Key ID: BC13F65E2DC84465
3 changed files with 20 additions and 12 deletions

@ -12,7 +12,7 @@ const EtcdBackendName = "etcd"
// BoltConfig holds bolt configuration. // BoltConfig holds bolt configuration.
type BoltConfig struct { 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. // EtcdConfig holds etcd configuration.

@ -1097,6 +1097,14 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
"minbackoff") "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. // Validate the subconfigs for workers, caches, and the tower client.
err = lncfg.Validate( err = lncfg.Validate(
cfg.Workers, cfg.Workers,

@ -9,8 +9,8 @@ import (
const ( const (
dbName = "channel.db" dbName = "channel.db"
boltBackend = "bolt" BoltBackend = "bolt"
etcdBackend = "etcd" EtcdBackend = "etcd"
) )
// DB holds database configuration for LND. // DB holds database configuration for LND.
@ -25,26 +25,24 @@ type DB struct {
// NewDB creates and returns a new default DB config. // NewDB creates and returns a new default DB config.
func DefaultDB() *DB { func DefaultDB() *DB {
return &DB{ return &DB{
Backend: boltBackend, Backend: BoltBackend,
Bolt: &kvdb.BoltConfig{ Bolt: &kvdb.BoltConfig{},
NoFreeListSync: true,
},
} }
} }
// Validate validates the DB config. // Validate validates the DB config.
func (db *DB) Validate() error { func (db *DB) Validate() error {
switch db.Backend { switch db.Backend {
case boltBackend: case BoltBackend:
case etcdBackend: case EtcdBackend:
if db.Etcd.Host == "" { if db.Etcd.Host == "" {
return fmt.Errorf("etcd host must be set") return fmt.Errorf("etcd host must be set")
} }
default: default:
return fmt.Errorf("unknown backend, must be either \"%v\" or \"%v\"", return fmt.Errorf("unknown backend, must be either \"%v\" or \"%v\"",
boltBackend, etcdBackend) BoltBackend, EtcdBackend)
} }
return nil return nil
@ -54,12 +52,14 @@ func (db *DB) Validate() error {
func (db *DB) GetBackend(ctx context.Context, dbPath string, func (db *DB) GetBackend(ctx context.Context, dbPath string,
networkName string) (kvdb.Backend, error) { networkName string) (kvdb.Backend, error) {
if db.Backend == etcdBackend { if db.Backend == EtcdBackend {
// Prefix will separate key/values in the db. // Prefix will separate key/values in the db.
return kvdb.GetEtcdBackend(ctx, networkName, db.Etcd) 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. // Compile-time constraint to ensure Workers implements the Validator interface.