etcd: remove (unused) etcd root bucket prefix

This commit removes the unused prefix from the etcd backend config as
etcd key space separation in LND is implemented by using namespaces
instead.
This commit is contained in:
Andras Banki-Horvath 2021-02-09 17:56:42 +01:00
parent 99fe0ab150
commit 44e312ace9
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8
6 changed files with 16 additions and 27 deletions

View File

@ -23,6 +23,10 @@ const (
// etcdLongTimeout is a timeout for longer taking etcd operatons. // etcdLongTimeout is a timeout for longer taking etcd operatons.
etcdLongTimeout = 30 * time.Second etcdLongTimeout = 30 * time.Second
// etcdDefaultRootBucketId is used as the root bucket key. Note that
// the actual key is not visible, since all bucket keys are hashed.
etcdDefaultRootBucketId = "@"
) )
// callerStats holds commit stats for a specific caller. Currently it only // callerStats holds commit stats for a specific caller. Currently it only
@ -152,11 +156,6 @@ type BackendConfig struct {
// skip TLS verification. // skip TLS verification.
InsecureSkipVerify bool InsecureSkipVerify bool
// Prefix the hash of the prefix will be used as the root
// bucket id. This enables key space separation similar to
// name spaces.
Prefix string
// Namespace is the etcd namespace that we'll use for all keys. // Namespace is the etcd namespace that we'll use for all keys.
Namespace string Namespace string
@ -243,7 +242,7 @@ func (db *db) getSTMOptions() []STMOptionFunc {
func (db *db) View(f func(tx walletdb.ReadTx) error, reset func()) error { func (db *db) View(f func(tx walletdb.ReadTx) error, reset func()) error {
apply := func(stm STM) error { apply := func(stm STM) error {
reset() reset()
return f(newReadWriteTx(stm, db.config.Prefix)) return f(newReadWriteTx(stm, etcdDefaultRootBucketId))
} }
return RunSTM(db.cli, apply, db.txQueue, db.getSTMOptions()...) return RunSTM(db.cli, apply, db.txQueue, db.getSTMOptions()...)
@ -259,7 +258,7 @@ func (db *db) View(f func(tx walletdb.ReadTx) error, reset func()) error {
func (db *db) Update(f func(tx walletdb.ReadWriteTx) error, reset func()) error { func (db *db) Update(f func(tx walletdb.ReadWriteTx) error, reset func()) error {
apply := func(stm STM) error { apply := func(stm STM) error {
reset() reset()
return f(newReadWriteTx(stm, db.config.Prefix)) return f(newReadWriteTx(stm, etcdDefaultRootBucketId))
} }
return RunSTM(db.cli, apply, db.txQueue, db.getSTMOptions()...) return RunSTM(db.cli, apply, db.txQueue, db.getSTMOptions()...)
@ -278,7 +277,7 @@ func (db *db) PrintStats() string {
func (db *db) BeginReadWriteTx() (walletdb.ReadWriteTx, error) { func (db *db) BeginReadWriteTx() (walletdb.ReadWriteTx, error) {
return newReadWriteTx( return newReadWriteTx(
NewSTM(db.cli, db.txQueue, db.getSTMOptions()...), NewSTM(db.cli, db.txQueue, db.getSTMOptions()...),
db.config.Prefix, etcdDefaultRootBucketId,
), nil ), nil
} }
@ -286,7 +285,7 @@ func (db *db) BeginReadWriteTx() (walletdb.ReadWriteTx, error) {
func (db *db) BeginReadTx() (walletdb.ReadTx, error) { func (db *db) BeginReadTx() (walletdb.ReadTx, error) {
return newReadWriteTx( return newReadWriteTx(
NewSTM(db.cli, db.txQueue, db.getSTMOptions()...), NewSTM(db.cli, db.txQueue, db.getSTMOptions()...),
db.config.Prefix, etcdDefaultRootBucketId,
), nil ), nil
} }

View File

@ -14,8 +14,8 @@ const TestBackend = EtcdBackendName
// GetEtcdBackend returns an etcd backend configured according to the // GetEtcdBackend returns an etcd backend configured according to the
// passed etcdConfig. // passed etcdConfig.
func GetEtcdBackend(ctx context.Context, prefix string, func GetEtcdBackend(ctx context.Context, etcdConfig *EtcdConfig) (
etcdConfig *EtcdConfig) (Backend, error) { Backend, error) {
// Config translation is needed here in order to keep the // Config translation is needed here in order to keep the
// etcd package fully independent from the rest of the source tree. // etcd package fully independent from the rest of the source tree.
@ -28,7 +28,6 @@ func GetEtcdBackend(ctx context.Context, prefix string,
CertFile: etcdConfig.CertFile, CertFile: etcdConfig.CertFile,
KeyFile: etcdConfig.KeyFile, KeyFile: etcdConfig.KeyFile,
InsecureSkipVerify: etcdConfig.InsecureSkipVerify, InsecureSkipVerify: etcdConfig.InsecureSkipVerify,
Prefix: prefix,
Namespace: etcdConfig.Namespace, Namespace: etcdConfig.Namespace,
CollectCommitStats: etcdConfig.CollectStats, CollectCommitStats: etcdConfig.CollectStats,
} }

View File

@ -14,8 +14,8 @@ const TestBackend = BoltBackendName
var errEtcdNotAvailable = fmt.Errorf("etcd backend not available") var errEtcdNotAvailable = fmt.Errorf("etcd backend not available")
// GetEtcdBackend is a stub returning nil and errEtcdNotAvailable error. // GetEtcdBackend is a stub returning nil and errEtcdNotAvailable error.
func GetEtcdBackend(ctx context.Context, prefix string, func GetEtcdBackend(ctx context.Context, etcdConfig *EtcdConfig) (
etcdConfig *EtcdConfig) (Backend, error) { Backend, error) {
return nil, errEtcdNotAvailable return nil, errEtcdNotAvailable
} }

View File

@ -1398,10 +1398,6 @@ func (c *Config) localDatabaseDir() string {
lncfg.NormalizeNetwork(c.ActiveNetParams.Name)) lncfg.NormalizeNetwork(c.ActiveNetParams.Name))
} }
func (c *Config) networkName() string {
return lncfg.NormalizeNetwork(c.ActiveNetParams.Name)
}
// CleanAndExpandPath expands environment variables and leading ~ in the // CleanAndExpandPath expands environment variables and leading ~ in the
// passed path, cleans the result, and returns it. // passed path, cleans the result, and returns it.
// This function is taken from https://github.com/btcsuite/btcd // This function is taken from https://github.com/btcsuite/btcd

View File

@ -73,8 +73,8 @@ type DatabaseBackends struct {
// GetBackends returns a set of kvdb.Backends as set in the DB config. The // GetBackends returns a set of kvdb.Backends as set in the DB config. The
// local database will ALWAYS be non-nil, while the remote database will only // local database will ALWAYS be non-nil, while the remote database will only
// be populated if etcd is specified. // be populated if etcd is specified.
func (db *DB) GetBackends(ctx context.Context, dbPath string, func (db *DB) GetBackends(ctx context.Context, dbPath string) (
networkName string) (*DatabaseBackends, error) { *DatabaseBackends, error) {
var ( var (
localDB, remoteDB kvdb.Backend localDB, remoteDB kvdb.Backend
@ -88,10 +88,7 @@ func (db *DB) GetBackends(ctx context.Context, dbPath string,
db.Etcd.EmbeddedPeerPort, db.Etcd.EmbeddedPeerPort,
) )
} else { } else {
// Prefix will separate key/values in the db. remoteDB, err = kvdb.GetEtcdBackend(ctx, db.Etcd)
remoteDB, err = kvdb.GetEtcdBackend(
ctx, networkName, db.Etcd,
)
} }
if err != nil { if err != nil {
return nil, err return nil, err

4
lnd.go
View File

@ -1455,9 +1455,7 @@ func initializeDatabases(ctx context.Context,
startOpenTime := time.Now() startOpenTime := time.Now()
databaseBackends, err := cfg.DB.GetBackends( databaseBackends, err := cfg.DB.GetBackends(ctx, cfg.localDatabaseDir())
ctx, cfg.localDatabaseDir(), cfg.networkName(),
)
if err != nil { if err != nil {
return nil, nil, nil, fmt.Errorf("unable to obtain database "+ return nil, nil, nil, fmt.Errorf("unable to obtain database "+
"backends: %v", err) "backends: %v", err)