-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
kvdb/sqlite: enable incremental auto_vacuum on DB creation #9672
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Pull Request Overview
This PR enables incremental auto_vacuum for newly created SQLite databases by setting the corresponding SQLite pragma during database creation.
- Updated NewSqliteBackend to include a new isCreate boolean parameter.
- Modified createDBDriver and openDBDriver to pass appropriate values for isCreate.
- Refactored internal representation of pragma options to use the named struct pragmaOption.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
kvdb/sqlite/driver.go | Updated function calls to NewSqliteBackend with a new boolean flag. |
kvdb/sqlite/db.go | Modified NewSqliteBackend signature and added auto_vacuum logic using pragmaOption. |
a28b432
to
faba39f
Compare
kvdb/sqlite/driver.go
Outdated
// is meant to open existing databases, but the underlying driver might | ||
// create one if it doesn't exist. We need to know if we are creating | ||
// it here to set the initial pragmas correctly (like auto_vacuum). | ||
fullPath := filepath.Join(dbPath, filename) |
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.
We'll need to do the same thing for sqldb.NewSqliteStore(...)
Line 52 in 6a3845b
func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) { |
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.
Ah good catch. Added in the latest commit.
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.
just a reminder to add a temporary replace
in the go.mod
to point to the kvdb
package so that the sqlite itests can run against this (or open another PR with a go.mod that points to this PR)
Added the temp replace. |
319d881
to
ec02bb0
Compare
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.
LGTM, thank you! 🎉
Please note that the sqlite unit tests are failing now. |
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.
looks good - just a quick question re if it matters that we do this switch on isCreate
ec02bb0
to
29a9f4e
Compare
In this commit, we make a change that enables the `auto_vacuum = incremental` pragma for SQLite databases, but only when the database file is first created. Incremental auto-vacuum allows SQLite to reclaim unused space within the database file over time, preventing indefinite growth.
29a9f4e
to
9eef2a0
Compare
In this commit, we make a change that enables the
auto_vacuum = incremental
pragma for SQLite databases, but only when the database file is first created. Incremental auto-vacuum allows SQLite to reclaim unused space within the database file over time, preventing indefinite growth.According to the SQLite documentation, the
auto_vacuum
mode must be set before any tables are created in the database. To achieve this, a new boolean parameterisCreate
has been added to theNewSqliteBackend
function.The
createDBDriver
now passestrue
for this parameter, ensuring the pragma is set during initial database setup. Conversely,openDBDriver
passesfalse
when opening an existing database, leaving the existing vacuum mode untouched.We also change, the internal representation of pragma options was refactored to use a named struct
pragmaOption
for improved clarity.