mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-08 23:01:53 +02:00
lncfg+etcd: add namespace support for etcd databases
Since we're now storing the content of multiple previously distinct database files in etcd, we want to properly namespace them as not to provoke any key collisions. We append a sub namespace to the given global namespace in order to still support multiple lnd nodes using the same etcd database simultaneously. Because the btcwallet code uses the legacy walletdb interface we must assume it is not fully concurrency safe. Therefore we make sure only a single writer can be active at any given time for the wallet DB backend when using etcd.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package etcd
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Config holds etcd configuration alongside with configuration related to our higher level interface.
|
||||
type Config struct {
|
||||
Embedded bool `long:"embedded" description:"Use embedded etcd instance instead of the external one. Note: use for testing only."`
|
||||
@@ -30,3 +32,51 @@ type Config struct {
|
||||
// single writer to the database at a time.
|
||||
SingleWriter bool
|
||||
}
|
||||
|
||||
// CloneWithSubNamespace clones the current configuration and returns a new
|
||||
// instance with the given sub namespace applied by appending it to the main
|
||||
// namespace.
|
||||
func (c *Config) CloneWithSubNamespace(subNamespace string) *Config {
|
||||
ns := c.Namespace
|
||||
if len(ns) == 0 {
|
||||
ns = subNamespace
|
||||
} else {
|
||||
ns = fmt.Sprintf("%s/%s", ns, subNamespace)
|
||||
}
|
||||
|
||||
return &Config{
|
||||
Embedded: c.Embedded,
|
||||
EmbeddedClientPort: c.EmbeddedClientPort,
|
||||
EmbeddedPeerPort: c.EmbeddedPeerPort,
|
||||
Host: c.Host,
|
||||
User: c.User,
|
||||
Pass: c.Pass,
|
||||
Namespace: ns,
|
||||
DisableTLS: c.DisableTLS,
|
||||
CertFile: c.CertFile,
|
||||
KeyFile: c.KeyFile,
|
||||
InsecureSkipVerify: c.InsecureSkipVerify,
|
||||
CollectStats: c.CollectStats,
|
||||
SingleWriter: c.SingleWriter,
|
||||
}
|
||||
}
|
||||
|
||||
// CloneWithSingleWriter clones the current configuration and returns a new
|
||||
// instance with the single writer property set to true.
|
||||
func (c *Config) CloneWithSingleWriter() *Config {
|
||||
return &Config{
|
||||
Embedded: c.Embedded,
|
||||
EmbeddedClientPort: c.EmbeddedClientPort,
|
||||
EmbeddedPeerPort: c.EmbeddedPeerPort,
|
||||
Host: c.Host,
|
||||
User: c.User,
|
||||
Pass: c.Pass,
|
||||
Namespace: c.Namespace,
|
||||
DisableTLS: c.DisableTLS,
|
||||
CertFile: c.CertFile,
|
||||
KeyFile: c.KeyFile,
|
||||
InsecureSkipVerify: c.InsecureSkipVerify,
|
||||
CollectStats: c.CollectStats,
|
||||
SingleWriter: true,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user