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:
parent
99fe0ab150
commit
44e312ace9
@ -23,6 +23,10 @@ const (
|
||||
|
||||
// etcdLongTimeout is a timeout for longer taking etcd operatons.
|
||||
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
|
||||
@ -152,11 +156,6 @@ type BackendConfig struct {
|
||||
// skip TLS verification.
|
||||
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 string
|
||||
|
||||
@ -243,7 +242,7 @@ func (db *db) getSTMOptions() []STMOptionFunc {
|
||||
func (db *db) View(f func(tx walletdb.ReadTx) error, reset func()) error {
|
||||
apply := func(stm STM) error {
|
||||
reset()
|
||||
return f(newReadWriteTx(stm, db.config.Prefix))
|
||||
return f(newReadWriteTx(stm, etcdDefaultRootBucketId))
|
||||
}
|
||||
|
||||
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 {
|
||||
apply := func(stm STM) error {
|
||||
reset()
|
||||
return f(newReadWriteTx(stm, db.config.Prefix))
|
||||
return f(newReadWriteTx(stm, etcdDefaultRootBucketId))
|
||||
}
|
||||
|
||||
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) {
|
||||
return newReadWriteTx(
|
||||
NewSTM(db.cli, db.txQueue, db.getSTMOptions()...),
|
||||
db.config.Prefix,
|
||||
etcdDefaultRootBucketId,
|
||||
), nil
|
||||
}
|
||||
|
||||
@ -286,7 +285,7 @@ func (db *db) BeginReadWriteTx() (walletdb.ReadWriteTx, error) {
|
||||
func (db *db) BeginReadTx() (walletdb.ReadTx, error) {
|
||||
return newReadWriteTx(
|
||||
NewSTM(db.cli, db.txQueue, db.getSTMOptions()...),
|
||||
db.config.Prefix,
|
||||
etcdDefaultRootBucketId,
|
||||
), nil
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ const TestBackend = EtcdBackendName
|
||||
|
||||
// GetEtcdBackend returns an etcd backend configured according to the
|
||||
// passed etcdConfig.
|
||||
func GetEtcdBackend(ctx context.Context, prefix string,
|
||||
etcdConfig *EtcdConfig) (Backend, error) {
|
||||
func GetEtcdBackend(ctx context.Context, etcdConfig *EtcdConfig) (
|
||||
Backend, error) {
|
||||
|
||||
// Config translation is needed here in order to keep the
|
||||
// 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,
|
||||
KeyFile: etcdConfig.KeyFile,
|
||||
InsecureSkipVerify: etcdConfig.InsecureSkipVerify,
|
||||
Prefix: prefix,
|
||||
Namespace: etcdConfig.Namespace,
|
||||
CollectCommitStats: etcdConfig.CollectStats,
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ const TestBackend = BoltBackendName
|
||||
var errEtcdNotAvailable = fmt.Errorf("etcd backend not available")
|
||||
|
||||
// GetEtcdBackend is a stub returning nil and errEtcdNotAvailable error.
|
||||
func GetEtcdBackend(ctx context.Context, prefix string,
|
||||
etcdConfig *EtcdConfig) (Backend, error) {
|
||||
func GetEtcdBackend(ctx context.Context, etcdConfig *EtcdConfig) (
|
||||
Backend, error) {
|
||||
|
||||
return nil, errEtcdNotAvailable
|
||||
}
|
||||
|
@ -1398,10 +1398,6 @@ func (c *Config) localDatabaseDir() string {
|
||||
lncfg.NormalizeNetwork(c.ActiveNetParams.Name))
|
||||
}
|
||||
|
||||
func (c *Config) networkName() string {
|
||||
return lncfg.NormalizeNetwork(c.ActiveNetParams.Name)
|
||||
}
|
||||
|
||||
// CleanAndExpandPath expands environment variables and leading ~ in the
|
||||
// passed path, cleans the result, and returns it.
|
||||
// This function is taken from https://github.com/btcsuite/btcd
|
||||
|
@ -73,8 +73,8 @@ type DatabaseBackends struct {
|
||||
// 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
|
||||
// be populated if etcd is specified.
|
||||
func (db *DB) GetBackends(ctx context.Context, dbPath string,
|
||||
networkName string) (*DatabaseBackends, error) {
|
||||
func (db *DB) GetBackends(ctx context.Context, dbPath string) (
|
||||
*DatabaseBackends, error) {
|
||||
|
||||
var (
|
||||
localDB, remoteDB kvdb.Backend
|
||||
@ -88,10 +88,7 @@ func (db *DB) GetBackends(ctx context.Context, dbPath string,
|
||||
db.Etcd.EmbeddedPeerPort,
|
||||
)
|
||||
} else {
|
||||
// Prefix will separate key/values in the db.
|
||||
remoteDB, err = kvdb.GetEtcdBackend(
|
||||
ctx, networkName, db.Etcd,
|
||||
)
|
||||
remoteDB, err = kvdb.GetEtcdBackend(ctx, db.Etcd)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
4
lnd.go
4
lnd.go
@ -1455,9 +1455,7 @@ func initializeDatabases(ctx context.Context,
|
||||
|
||||
startOpenTime := time.Now()
|
||||
|
||||
databaseBackends, err := cfg.DB.GetBackends(
|
||||
ctx, cfg.localDatabaseDir(), cfg.networkName(),
|
||||
)
|
||||
databaseBackends, err := cfg.DB.GetBackends(ctx, cfg.localDatabaseDir())
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("unable to obtain database "+
|
||||
"backends: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user