Repository navigation
fix(core): reclaim deleted SQLite pages incrementally - #58730
Open
ganeshgawali2007-arch wants to merge 1 commit into
Open
ganeshgawali2007-arch wants to merge 1 commit into
ganeshgawali2007-arch wants to merge 1 commit into
Conversation
New databases were created with auto_vacuum=NONE because the driver enabled WAL before Database configured any pragmas, so deleted rows stayed on the freelist permanently. Configure new file databases with incremental auto-vacuum before WAL, and reclaim a bounded number of free pages after migration and after an event aggregate is removed. Existing NONE/FULL databases are left untouched because converting them needs an offline VACUUM. Fixes anomalyco#47591
Contributor
There was a problem hiding this comment.
Looks good. I reproduced the problem on the base by running the new database-storage tests there: a new database gets auto_vacuum=0, and nothing is reclaimed on reopen or after bus.remove. All of those pass with this change. The nearby database, bus and session suites pass (95 tests) and tsc -b is clean. I couldn't run the CLI end to end in my environment, so the check is at the Database.layer level, which is what #47591's reproduction describes.
I checked the risky spots and found no problems:
- Both the Bun and Node drivers skip only
journal_mode=WALwhendisableWALis set, and WAL is enabled right after the auto-vacuum pragma. On workerd these pragmas are not run at all, as before. - Two processes opening the same new file at once is harmless, because a later
auto_vacuumpragma is ignored once the header exists. - Session deletion is the only caller of
bus.remove, and it runs outside any transaction, so the reclaim and checkpoint aren't inside one.
Public API is unchanged.
One note for maintainers: open PR #56365 makes the core part of this same change.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #47591
Type of change
What does this PR do?
New databases were created with
auto_vacuum=NONEbecause the SQLite driver enables WAL while opening the file, creating the header beforeDatabasecan set any pragmas. SQLite ignores later auto-vacuum changes, so deleted pages stayed on the freelist and the file never shrank.PRAGMA auto_vacuum=INCREMENTALbefore enabling WAL, then continue with the existing pragmas.VACUUM, which is not safe during multi-process startup.Existing databases created before this change can be converted while OpenCode is stopped:
How did you verify your code works?
cd packages/core && bun test test/database-storage.test.ts— 6 pass; 3 of them fail against the previous code.cd packages/core && bun run typecheck— 1,650 files, no type errors.database*.test.tsandbus.test.ts— 85 pass.Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Related: #33356, #55282, #54618, #58124