mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
lncfg: add new GetBackends which returns active DB backends
In this commit, we modify the existing `GetBackend` method to now be called `GetBackends`. This new method will populate a new `RemoteDB` attribute based on if the replicated backend is active or not. As is, the local backend is used everywhere. An upcoming commit will once again re-enable the remote backend, in a hybrid manner.
This commit is contained in:
parent
6a6521bba0
commit
7355c8ba3a
46
lncfg/db.go
46
lncfg/db.go
@ -48,18 +48,50 @@ func (db *DB) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBackend returns a kvdb.Backend as set in the DB config.
|
||||
func (db *DB) GetBackend(ctx context.Context, dbPath string,
|
||||
networkName string) (kvdb.Backend, error) {
|
||||
// DatabaseBackends is a two-tuple that holds the set of active database
|
||||
// backends for the daemon. The two backends we expose are the local database
|
||||
// backend, and the remote backend. The LocalDB attribute will always be
|
||||
// populated. However, the remote DB will only be set if a replicated database
|
||||
// is active.
|
||||
type DatabaseBackends struct {
|
||||
// LocalDB points to the local non-replicated backend.
|
||||
LocalDB kvdb.Backend
|
||||
|
||||
// RemoteDB points to a possibly networked replicated backend. If no
|
||||
// replicated backend is active, then this pointer will be nil.
|
||||
RemoteDB kvdb.Backend
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
var (
|
||||
localDB, remoteDB kvdb.Backend
|
||||
err error
|
||||
)
|
||||
|
||||
if db.Backend == EtcdBackend {
|
||||
// Prefix will separate key/values in the db.
|
||||
return kvdb.GetEtcdBackend(ctx, networkName, db.Etcd)
|
||||
remoteDB, err = kvdb.GetEtcdBackend(ctx, networkName, db.Etcd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// The implementation by walletdb accepts "noFreelistSync" as the
|
||||
// second parameter, so we negate here.
|
||||
return kvdb.GetBoltBackend(dbPath, dbName, !db.Bolt.SyncFreelist)
|
||||
localDB, err = kvdb.GetBoltBackend(
|
||||
dbPath, dbName, !db.Bolt.SyncFreelist,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DatabaseBackends{
|
||||
LocalDB: localDB,
|
||||
RemoteDB: remoteDB,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Compile-time constraint to ensure Workers implements the Validator interface.
|
||||
|
7
lnd.go
7
lnd.go
@ -251,6 +251,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
||||
"minutes...")
|
||||
|
||||
startOpenTime := time.Now()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
@ -260,8 +261,8 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
||||
cfg.DB.Bolt.SyncFreelist)
|
||||
}
|
||||
|
||||
chanDbBackend, err := cfg.DB.GetBackend(ctx,
|
||||
cfg.localDatabaseDir(), cfg.networkName(),
|
||||
databaseBackends, err := cfg.DB.GetBackends(
|
||||
ctx, cfg.localDatabaseDir(), cfg.networkName(),
|
||||
)
|
||||
if err != nil {
|
||||
ltndLog.Error(err)
|
||||
@ -271,7 +272,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
||||
// Open the channeldb, which is dedicated to storing channel, and
|
||||
// network related metadata.
|
||||
chanDB, err := channeldb.CreateWithBackend(
|
||||
chanDbBackend,
|
||||
databaseBackends.LocalDB,
|
||||
channeldb.OptionSetRejectCacheSize(cfg.Caches.RejectCacheSize),
|
||||
channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize),
|
||||
channeldb.OptionDryRunMigration(cfg.DryRunMigration),
|
||||
|
Loading…
Reference in New Issue
Block a user