lncfg+scripts: use configurable global lock for postgres backends
Replace hardcoded WithGlobalLock assignment with configurable options wallet postgres backends. Also add the WithGlobalLock option to the channeldb table for postgres backends. Defaults: - channeldb: false (allow concurrent access) - wallet: true (maintain safe single-writer behavior) Users can now override these defaults via: - db.postgres.channeldb-with-global-lock - db.postgres.walletdb-with-global-lock This gives operators flexibility while maintaining safe defaults until full native SQL migration is complete. Moreover exclude db.postgres.walletdb-with-global-lock check in the sample config file script. We cannot easily check the correct default because we set it later in the LND startup sequence so we exclude it.
This commit is contained in:
4 files changed
+42
-10
No files matched your search
+20
-9
@@ -115,7 +115,15 @@ func DefaultDB() *DB {
|
||||
},
|
||||
Postgres: &sqldb.PostgresConfig{
|
||||
MaxConnections: defaultPostgresMaxConnections,
|
||||
QueryConfig: *sqldb.DefaultPostgresConfig(),
|
||||
// Normally we don't use a global lock for channeldb
|
||||
// access, but if a user encounters huge concurrency
|
||||
// issues, they can enable this to use a global lock.
|
||||
ChannelDBWithGlobalLock: false,
|
||||
// Default to true to maintain safe single-writer
|
||||
// behavior until the wallet subsystem is upgraded to
|
||||
// a native sql schema.
|
||||
WalletDBWithGlobalLock: true,
|
||||
QueryConfig: *sqldb.DefaultPostgresConfig(),
|
||||
},
|
||||
Sqlite: &sqldb.SqliteConfig{
|
||||
MaxConnections: defaultSqliteMaxConnections,
|
||||
@@ -400,9 +408,15 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
||||
// users to native SQL.
|
||||
postgresConfig := GetPostgresConfigKVDB(db.Postgres)
|
||||
|
||||
// Create a separate config for channeldb with the global lock
|
||||
// setting if configured.
|
||||
postgresConfigChannelDB := GetPostgresConfigKVDB(db.Postgres)
|
||||
postgresConfigChannelDB.WithGlobalLock = db.Postgres.
|
||||
ChannelDBWithGlobalLock
|
||||
|
||||
postgresBackend, err := kvdb.Open(
|
||||
kvdb.PostgresBackendName, ctx,
|
||||
postgresConfig, NSChannelDB,
|
||||
postgresConfigChannelDB, NSChannelDB,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening postgres graph "+
|
||||
@@ -450,14 +464,11 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
||||
}
|
||||
closeFuncs[NSTowerServerDB] = postgresTowerServerBackend.Close
|
||||
|
||||
// The wallet subsystem is still not robust enough to run it
|
||||
// without a single writer in postgres therefore we create a
|
||||
// new config with the global lock enabled.
|
||||
//
|
||||
// NOTE: This is a temporary measure and should be removed as
|
||||
// soon as the wallet code is more robust.
|
||||
// Create a separate config for wallet with the global lock
|
||||
// setting if configured.
|
||||
postgresConfigWalletDB := GetPostgresConfigKVDB(db.Postgres)
|
||||
postgresConfigWalletDB.WithGlobalLock = true
|
||||
postgresConfigWalletDB.WithGlobalLock = db.Postgres.
|
||||
WalletDBWithGlobalLock
|
||||
|
||||
postgresWalletBackend, err := kvdb.Open(
|
||||
kvdb.PostgresBackendName, ctx,
|
||||
|
||||
Reference in new issue
Block a user