etcd: add namespace support to separate key spaces

This commit extends etcd db with namespaces without additional storage
space requirements. This is simply done by instead of using an all zero
root bucket id, we use the sha256 hash of the name space as our root
bucket id.
This commit is contained in:
Andras Banki-Horvath
2020-05-12 16:02:46 +02:00
parent bce0597643
commit c3fcfd1530
8 changed files with 40 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ package lncfg
import (
"fmt"
"path"
"github.com/lightningnetwork/lnd/channeldb/kvdb"
)
@@ -50,12 +51,14 @@ 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) {
func (db *DB) GetBackend(dbPath string) (kvdb.Backend, error) {
if db.Backend == etcdBackend {
return kvdb.GetEtcdBackend(db.Etcd)
// Prefix will separate key/values in the db.
prefix := path.Join(dbPath, dbName)
return kvdb.GetEtcdBackend(prefix, db.Etcd)
}
return kvdb.GetBoltBackend(path, dbName, db.Bolt.NoFreeListSync)
return kvdb.GetBoltBackend(dbPath, dbName, db.Bolt.NoFreeListSync)
}
// Compile-time constraint to ensure Workers implements the Validator interface.