Skip to content

Conversation

@ziggie1984
Copy link
Collaborator

@ziggie1984 ziggie1984 commented Nov 26, 2025

Added new Postgres configuration options db.postgres.channeldb-with-global-lockand db.postgres.walletdb-with-global-lock to allow fine-grained control over database concurrency. The channeldb global lock defaults to false to enable concurrent access, while the wallet global lock defaults to true to maintain safe single-writer behavior until the wallet subsystem is fully concurrent-safe.

@ziggie1984 ziggie1984 added this to the v0.20.1 milestone Nov 27, 2025
@saubyk saubyk added this to lnd v0.20 Nov 27, 2025
@saubyk saubyk moved this to In progress in lnd v0.20 Nov 27, 2025
@ziggie1984 ziggie1984 force-pushed the add-back-globallock branch 2 times, most recently from 660f743 to 98ea583 Compare November 27, 2025 19:20
@ziggie1984 ziggie1984 marked this pull request as ready for review November 27, 2025 19:21
@ziggie1984 ziggie1984 added postgres size/micro small bug fix or feature, less than 15 mins of review, less than 250 labels Nov 27, 2025
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💾
Added few comments.

sqldb/config.go Outdated
MaxConnections int `long:"maxconnections" description:"The maximum number of open connections to the database. Set to zero for unlimited."`
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
ChannelDBWithGlobalLock bool `long:"channeldb-with-global-lock" description:"Use a global lock for channeldb access. This ensures only a single writer at a time but reduces concurrency. This is a temporary workaround until the revocation log is migrated to native SQL."`
WalletDBWithGlobalLock bool `long:"walletdb-with-global-lock" description:"Use a global lock for wallet database access. This ensures only a single writer at a time but reduces concurrency. This is a temporary workaround until the wallet is fully concurrent-safe."`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add default:"true" to the tags? I think lnd --help will show it then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no go-flags does not support defaults for booleans.

concurrent access, while the wallet global lock defaults to `true` to maintain
safe single-writer behavior until the wallet subsystem is fully
concurrent-safe.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also document the options in docs/postgres.md file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

@ziggie1984 ziggie1984 force-pushed the add-back-globallock branch 3 times, most recently from 506e232 to 5b7abfd Compare November 28, 2025 07:56
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! 🎉

Add two configuration options to control global lock usage for
different postgres database backends:

- ChannelDBWithGlobalLock: for channeldb access (default: false)
- WalletDBWithGlobalLock: for wallet database access (default: true)

These allow fine-grained control over which databases use global
locks, rather than hardcoding the behavior. This is a temporary
measure until the revocation log and wallet are migrated to native
SQL and become fully concurrent-safe.
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.
@yyforyongyu yyforyongyu merged commit 0a2a5b2 into lightningnetwork:master Nov 28, 2025
36 of 39 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in lnd v0.20 Nov 28, 2025
@ziggie1984 ziggie1984 deleted the add-back-globallock branch November 28, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postgres size/micro small bug fix or feature, less than 15 mins of review, less than 250

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants