kvdb+lncfg: fully move etcd behind build tag

This commit separates all etcd related sources (sans a few stubs and
config) from the rest of the source tree and makes compilation conditional
depending on whether the kvdb_etcd build tag is specified.
This commit is contained in:
Andras Banki-Horvath
2020-05-15 16:59:37 +02:00
parent 3ef331e016
commit 85aee9b064
26 changed files with 145 additions and 77 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/lightningnetwork/lnd/channeldb/kvdb"
"github.com/lightningnetwork/lnd/channeldb/kvdb/etcd"
)
const (
@@ -13,42 +12,20 @@ const (
etcdBackend = "etcd"
)
// BoltDB holds bolt configuration.
type BoltDB struct {
NoFreeListSync bool `long:"nofreelistsync" description:"If true, prevents the database from syncing its freelist to disk"`
}
// EtcdDB hold etcd configuration.
type EtcdDB struct {
Host string `long:"host" description:"Etcd database host."`
User string `long:"user" description:"Etcd database user."`
Pass string `long:"pass" description:"Password for the database user."`
CertFile string `long:"cert_file" description:"Path to the TLS certificate for etcd RPC."`
KeyFile string `long:"key_file" description:"Path to the TLS private key for etcd RPC."`
InsecureSkipVerify bool `long:"insecure_skip_verify" description:"Whether we intend to skip TLS verification"`
CollectStats bool `long:"collect_stats" description:"Wheter to collect etcd commit stats."`
}
// DB holds database configuration for LND.
type DB struct {
Backend string `long:"backend" description:"The selected database backend."`
Etcd *EtcdDB `group:"etcd" namespace:"etcd" description:"Etcd settings."`
Etcd *kvdb.EtcdConfig `group:"etcd" namespace:"etcd" description:"Etcd settings."`
Bolt *BoltDB `group:"bolt" namespace:"bolt" description:"Bolt settings."`
Bolt *kvdb.BoltConfig `group:"bolt" namespace:"bolt" description:"Bolt settings."`
}
// NewDB creates and returns a new default DB config.
func DefaultDB() *DB {
return &DB{
Backend: boltBackend,
Bolt: &BoltDB{
Bolt: &kvdb.BoltConfig{
NoFreeListSync: true,
},
}
@@ -75,16 +52,7 @@ func (db *DB) Validate() error {
// GetBackend returns a kvdb.Backend as set in the DB config.
func (db *DB) GetBackend(path string) (kvdb.Backend, error) {
if db.Backend == etcdBackend {
backendConfig := etcd.BackendConfig{
Host: db.Etcd.Host,
User: db.Etcd.User,
Pass: db.Etcd.Pass,
CertFile: db.Etcd.CertFile,
KeyFile: db.Etcd.KeyFile,
InsecureSkipVerify: db.Etcd.InsecureSkipVerify,
CollectCommitStats: db.Etcd.CollectStats,
}
return kvdb.Open(kvdb.EtcdBackendName, backendConfig)
return kvdb.GetEtcdBackend(db.Etcd)
}
return kvdb.GetBoltBackend(path, dbName, db.Bolt.NoFreeListSync)