-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multi: add sqlite backend option #7252
Changes from all commits
2fd4f3f
8363c40
8c4d334
a5eaabf
b39049f
c89e5b6
fe52545
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ run: | |
- watchtowerrpc | ||
- kvdb_etcd | ||
- kvdb_postgres | ||
- kvdb_sqlite | ||
|
||
linters-settings: | ||
govet: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1404,12 +1404,18 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, | |
) | ||
} | ||
|
||
towerDir := filepath.Join( | ||
cfg.Watchtower.TowerDir, | ||
cfg.registeredChains.PrimaryChain().String(), | ||
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name), | ||
) | ||
|
||
// Create the lnd directory and all other sub-directories if they don't | ||
// already exist. This makes sure that directory trees are also created | ||
// for files that point to outside the lnddir. | ||
dirs := []string{ | ||
lndDir, cfg.DataDir, cfg.networkDir, | ||
cfg.LetsEncryptDir, cfg.Watchtower.TowerDir, | ||
cfg.LetsEncryptDir, towerDir, cfg.graphDatabaseDir(), | ||
filepath.Dir(cfg.TLSCertPath), filepath.Dir(cfg.TLSKeyPath), | ||
filepath.Dir(cfg.AdminMacPath), filepath.Dir(cfg.ReadMacPath), | ||
filepath.Dir(cfg.InvoiceMacPath), | ||
|
@@ -1616,6 +1622,47 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, | |
cfg.DB.Bolt.NoFreelistSync = !cfg.SyncFreelist | ||
} | ||
|
||
// Parse any extra sqlite pragma options that may have been provided | ||
// to determine if they override any of the defaults that we will | ||
// otherwise add. | ||
var ( | ||
defaultSynchronous = true | ||
defaultAutoVacuum = true | ||
defaultFullfsync = true | ||
) | ||
for _, option := range cfg.DB.Sqlite.PragmaOptions { | ||
switch { | ||
case strings.HasPrefix(option, "synchronous="): | ||
defaultSynchronous = false | ||
|
||
case strings.HasPrefix(option, "auto_vacuum="): | ||
defaultAutoVacuum = false | ||
|
||
case strings.HasPrefix(option, "fullfsync="): | ||
defaultFullfsync = false | ||
|
||
default: | ||
} | ||
} | ||
|
||
if defaultSynchronous { | ||
cfg.DB.Sqlite.PragmaOptions = append( | ||
cfg.DB.Sqlite.PragmaOptions, "synchronous=full", | ||
) | ||
} | ||
|
||
if defaultAutoVacuum { | ||
cfg.DB.Sqlite.PragmaOptions = append( | ||
cfg.DB.Sqlite.PragmaOptions, "auto_vacuum=incremental", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. it is actually the However, I forgot to add this to the docs, so I will add a note about it there 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah - also just realised not all pragma options are kv pairs. So need to update the config to allow for non kv pairs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the docs and removed the "kv" form requirement 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to get vacuum to clean up a test db, but didn't succeed. This is what I did:
The db file is still big at this point. Only issuing Am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right, after all this, I need to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think we want to eventually have the current compact flag effectively just run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too bad there is no real auto-vacuum in sqlite. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Cool - yeah the |
||
) | ||
} | ||
joostjager marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if defaultFullfsync { | ||
cfg.DB.Sqlite.PragmaOptions = append( | ||
cfg.DB.Sqlite.PragmaOptions, "fullfsync=true", | ||
) | ||
} | ||
|
||
// Ensure that the user hasn't chosen a remote-max-htlc value greater | ||
// than the protocol maximum. | ||
maxRemoteHtlcs := uint16(input.MaxHTLCNumber / 2) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# SQLite support in LND | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Carrying over my comments from #7251 for convenience:
|
||
|
||
With the introduction of the `kvdb` interface, LND can support multiple database | ||
backends. One of the supported backends is | ||
[sqlite](https://www.sqlite.org/index.html). This document describes how use | ||
LND with a sqlite backend. | ||
|
||
Note that for the time being, the sqlite backend option can only be set for | ||
_new_ nodes. Setting the option for an existing node will not migrate the data. | ||
|
||
## Supported platforms and architectures | ||
|
||
Note that the sqlite backend is _not_ supported for Windows (386/ARM) or for | ||
Linux (PPC/MIPS) due to these platforms [not being supported by the sqlite | ||
driver library.]( | ||
https://pkg.go.dev/modernc.org/sqlite#hdr-Supported_platforms_and_architectures) | ||
|
||
## Configuring LND for SQLite | ||
|
||
LND is configured for SQLite through the following configuration options: | ||
|
||
* `db.backend=sqlite` to select the SQLite backend. | ||
Roasbeef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* `db.sqlite.timeout=...` to set the connection timeout. If not set, no | ||
timeout applies. | ||
* `db.sqlite.busytimeout=...` to set the maximum amount of time that a db call | ||
should wait if the db is currently locked. | ||
* `db.sqlite.pragmaoptions=...` to set a list of pragma options to be applied | ||
to the db connection. See the | ||
[sqlite documentation](https://www.sqlite.org/pragma.html) for more | ||
information on the available pragma options. | ||
|
||
## Default pragma options | ||
|
||
Currently, the following pragma options are always set: | ||
|
||
``` | ||
foreign_keys=on | ||
journal_mode=wal | ||
busy_timeout=5000 // Overried with the db.sqlite.busytimeout option. | ||
``` | ||
|
||
The following pragma options are set by default but can be overridden using the | ||
`db.sqlite.pragmaoptions` option: | ||
|
||
``` | ||
synchronous=full | ||
auto_vacuum=incremental | ||
fullfsync=true // Only meaningful on a Mac. | ||
``` | ||
|
||
## Auto-compaction | ||
|
||
To activate auto-compaction on startup, the `incremental_vacuum` pragma option | ||
should be used: | ||
``` | ||
// Use N to restrict the maximum number of pages to be removed from the | ||
// freelist. | ||
db.sqlite.pragmaoptions=incremental_vacuum(N) | ||
|
||
// Omit N if the entire freelist should be cleared. | ||
db.sqlite.pragmaoptions=incremental_vacuum | ||
``` | ||
|
||
Example as follows: | ||
``` | ||
[db] | ||
db.backend=sqlite | ||
db.sqlite.timeout=0 | ||
db.sqlite.busytimeout=10s | ||
db.sqlite.pragmaoptions=temp_store=memory | ||
db.sqlite.pragmaoptions=incremental_vacuum | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phew, I think this might just work out without any issues... But the next version will give us problems I think: lightninglabs/aperture#62
So probably this is the last "painless"
etcd
upgrade 😬