Skip to content

Commit f0ea5bf

Browse files
authored
Merge pull request #9672 from Roasbeef/kvdb-sqlite-incremental-vacuum
kvdb/sqlite: enable incremental auto_vacuum on DB creation
2 parents 580935a + 9eef2a0 commit f0ea5bf

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
210210
// allows us to specify that as an option.
211211
replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display
212212

213+
replace github.com/lightningnetwork/lnd/sqldb => ./sqldb
214+
215+
replace github.com/lightningnetwork/lnd/kvdb => ./kvdb
216+
213217
// If you change this please also update docs/INSTALL.md and GO_VERSION in
214218
// Makefile (then run `make lint` to see where else it needs to be updated as
215219
// well).

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,8 @@ github.com/lightningnetwork/lnd/fn/v2 v2.0.8 h1:r2SLz7gZYQPVc3IZhU82M66guz3Zk2oY
371371
github.com/lightningnetwork/lnd/fn/v2 v2.0.8/go.mod h1:TOzwrhjB/Azw1V7aa8t21ufcQmdsQOQMDtxVOQWNl8s=
372372
github.com/lightningnetwork/lnd/healthcheck v1.2.6 h1:1sWhqr93GdkWy4+6U7JxBfcyZIE78MhIHTJZfPx7qqI=
373373
github.com/lightningnetwork/lnd/healthcheck v1.2.6/go.mod h1:Mu02um4CWY/zdTOvFje7WJgJcHyX2zq/FG3MhOAiGaQ=
374-
github.com/lightningnetwork/lnd/kvdb v1.4.13 h1:fe3sFBxsgcXl16G1zj6O/wZf0hbBHOxFe8pCgmnHZxM=
375-
github.com/lightningnetwork/lnd/kvdb v1.4.13/go.mod h1:1y0Z81CGQu4SMpcnAie/oK4tzgEqFQqFdj6k3fz2s8s=
376374
github.com/lightningnetwork/lnd/queue v1.1.1 h1:99ovBlpM9B0FRCGYJo6RSFDlt8/vOkQQZznVb18iNMI=
377375
github.com/lightningnetwork/lnd/queue v1.1.1/go.mod h1:7A6nC1Qrm32FHuhx/mi1cieAiBZo5O6l8IBIoQxvkz4=
378-
github.com/lightningnetwork/lnd/sqldb v1.0.8 h1:bTrMwEVDTthkfea+ShdzfK0XkKQz3VNN9dbE+B+gvEk=
379-
github.com/lightningnetwork/lnd/sqldb v1.0.8/go.mod h1:OG09zL/PHPaBJefp4HsPz2YLUJ+zIQHbpgCtLnOx8I4=
380376
github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM=
381377
github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA=
382378
github.com/lightningnetwork/lnd/tlv v1.3.0 h1:exS/KCPEgpOgviIttfiXAPaUqw2rHQrnUOpP7HPBPiY=

kvdb/sqlite/db.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ const (
2424
sqliteTxLockImmediate = "_txlock=immediate"
2525
)
2626

27+
// pragmaOption holds a key-value pair for a SQLite pragma setting.
28+
type pragmaOption struct {
29+
name string
30+
value string
31+
}
32+
2733
// NewSqliteBackend returns a db object initialized with the passed backend
2834
// config. If a sqlite connection cannot be established, then an error is
2935
// returned.
3036
func NewSqliteBackend(ctx context.Context, cfg *Config, dbPath, fileName,
3137
prefix string) (walletdb.DB, error) {
3238

3339
// First, we add a set of mandatory pragma options to the query.
34-
pragmaOptions := []struct {
35-
name string
36-
value string
37-
}{
40+
pragmaOptions := []pragmaOption{
3841
{
3942
name: "busy_timeout",
4043
value: fmt.Sprintf(
@@ -49,7 +52,12 @@ func NewSqliteBackend(ctx context.Context, cfg *Config, dbPath, fileName,
4952
name: "journal_mode",
5053
value: "WAL",
5154
},
55+
{
56+
name: "auto_vacuum",
57+
value: "incremental",
58+
},
5259
}
60+
5361
sqliteOptions := make(url.Values)
5462
for _, option := range pragmaOptions {
5563
sqliteOptions.Add(

sqldb/sqlite.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ var (
4040
_ DB = (*SqliteStore)(nil)
4141
)
4242

43+
// pragmaOption holds a key-value pair for a SQLite pragma setting.
44+
type pragmaOption struct {
45+
name string
46+
value string
47+
}
48+
4349
// SqliteStore is a database store implementation that uses a sqlite backend.
4450
type SqliteStore struct {
4551
cfg *SqliteConfig
@@ -53,10 +59,7 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
5359
// The set of pragma options are accepted using query options. For now
5460
// we only want to ensure that foreign key constraints are properly
5561
// enforced.
56-
pragmaOptions := []struct {
57-
name string
58-
value string
59-
}{
62+
pragmaOptions := []pragmaOption{
6063
{
6164
name: "foreign_keys",
6265
value: "on",
@@ -84,6 +87,10 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
8487
name: "fullfsync",
8588
value: "true",
8689
},
90+
{
91+
name: "auto_vacuum",
92+
value: "incremental",
93+
},
8794
}
8895
sqliteOptions := make(url.Values)
8996
for _, option := range pragmaOptions {

0 commit comments

Comments
 (0)