Skip to content

kvdb/sqlite: enable incremental auto_vacuum on DB creation #9672

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
// allows us to specify that as an option.
replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display

replace github.com/lightningnetwork/lnd/sqldb => ./sqldb

replace github.com/lightningnetwork/lnd/kvdb => ./kvdb

// If you change this please also update docs/INSTALL.md and GO_VERSION in
// Makefile (then run `make lint` to see where else it needs to be updated as
// well).
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,8 @@ github.com/lightningnetwork/lnd/fn/v2 v2.0.8 h1:r2SLz7gZYQPVc3IZhU82M66guz3Zk2oY
github.com/lightningnetwork/lnd/fn/v2 v2.0.8/go.mod h1:TOzwrhjB/Azw1V7aa8t21ufcQmdsQOQMDtxVOQWNl8s=
github.com/lightningnetwork/lnd/healthcheck v1.2.6 h1:1sWhqr93GdkWy4+6U7JxBfcyZIE78MhIHTJZfPx7qqI=
github.com/lightningnetwork/lnd/healthcheck v1.2.6/go.mod h1:Mu02um4CWY/zdTOvFje7WJgJcHyX2zq/FG3MhOAiGaQ=
github.com/lightningnetwork/lnd/kvdb v1.4.13 h1:fe3sFBxsgcXl16G1zj6O/wZf0hbBHOxFe8pCgmnHZxM=
github.com/lightningnetwork/lnd/kvdb v1.4.13/go.mod h1:1y0Z81CGQu4SMpcnAie/oK4tzgEqFQqFdj6k3fz2s8s=
github.com/lightningnetwork/lnd/queue v1.1.1 h1:99ovBlpM9B0FRCGYJo6RSFDlt8/vOkQQZznVb18iNMI=
github.com/lightningnetwork/lnd/queue v1.1.1/go.mod h1:7A6nC1Qrm32FHuhx/mi1cieAiBZo5O6l8IBIoQxvkz4=
github.com/lightningnetwork/lnd/sqldb v1.0.8 h1:bTrMwEVDTthkfea+ShdzfK0XkKQz3VNN9dbE+B+gvEk=
github.com/lightningnetwork/lnd/sqldb v1.0.8/go.mod h1:OG09zL/PHPaBJefp4HsPz2YLUJ+zIQHbpgCtLnOx8I4=
github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM=
github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA=
github.com/lightningnetwork/lnd/tlv v1.3.0 h1:exS/KCPEgpOgviIttfiXAPaUqw2rHQrnUOpP7HPBPiY=
Expand Down
16 changes: 12 additions & 4 deletions kvdb/sqlite/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ const (
sqliteTxLockImmediate = "_txlock=immediate"
)

// pragmaOption holds a key-value pair for a SQLite pragma setting.
type pragmaOption struct {
name string
value string
}

// NewSqliteBackend returns a db object initialized with the passed backend
// config. If a sqlite connection cannot be established, then an error is
// returned.
func NewSqliteBackend(ctx context.Context, cfg *Config, dbPath, fileName,
prefix string) (walletdb.DB, error) {

// First, we add a set of mandatory pragma options to the query.
pragmaOptions := []struct {
name string
value string
}{
pragmaOptions := []pragmaOption{
{
name: "busy_timeout",
value: fmt.Sprintf(
Expand All @@ -49,7 +52,12 @@ func NewSqliteBackend(ctx context.Context, cfg *Config, dbPath, fileName,
name: "journal_mode",
value: "WAL",
},
{
name: "auto_vacuum",
value: "incremental",
},
}

sqliteOptions := make(url.Values)
for _, option := range pragmaOptions {
sqliteOptions.Add(
Expand Down
15 changes: 11 additions & 4 deletions sqldb/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var (
_ DB = (*SqliteStore)(nil)
)

// pragmaOption holds a key-value pair for a SQLite pragma setting.
type pragmaOption struct {
name string
value string
}

// SqliteStore is a database store implementation that uses a sqlite backend.
type SqliteStore struct {
cfg *SqliteConfig
Expand All @@ -53,10 +59,7 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
// The set of pragma options are accepted using query options. For now
// we only want to ensure that foreign key constraints are properly
// enforced.
pragmaOptions := []struct {
name string
value string
}{
pragmaOptions := []pragmaOption{
{
name: "foreign_keys",
value: "on",
Expand Down Expand Up @@ -84,6 +87,10 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
name: "fullfsync",
value: "true",
},
{
name: "auto_vacuum",
value: "incremental",
},
}
sqliteOptions := make(url.Values)
for _, option := range pragmaOptions {
Expand Down
Loading