Skip to content

Ensure external streams checkpoint on commit#2652

Merged
JKamsker merged 2 commits intodevfrom
codex/create-repro-for-litedb-update-issue
Sep 27, 2025
Merged

Ensure external streams checkpoint on commit#2652
JKamsker merged 2 commits intodevfrom
codex/create-repro-for-litedb-update-issue

Conversation

@JKamsker
Copy link
Copy Markdown
Collaborator

@JKamsker JKamsker commented Sep 27, 2025

Replacement for #2641
This pull request introduces improvements to how LiteDB handles checkpointing when using external streams, particularly ensuring data durability and correct restoration of checkpoint settings. It also adds new tests to verify these behaviors. The most important changes are grouped below.

Checkpointing Behavior Improvements:

  • In the LiteDatabase constructor, when using an external data stream without a dedicated log stream and the stream is writable, the database now forces checkpointing by setting the Pragmas.CHECKPOINT value to 1 to ensure commits are flushed to the data stream. The original checkpoint value is saved for later restoration.
  • Upon disposal of the LiteDatabase instance, if the checkpoint value was overridden, it is restored to its original value to avoid side effects in subsequent uses.
  • The checkpoint logic in the transaction engine now triggers when the log file size is greater than or equal to the checkpoint size (previously it was strictly greater), ensuring that checkpointing occurs at the correct threshold.

Testing Enhancements:

  • Added a new test class IssueCheckpointFlush_Tests with tests verifying that:
    • Committed changes are not lost when closing an external stream without a checkpoint.
    • The checkpoint size is correctly restored after using a stream constructor.
    • The stream constructor allows opening the database in read-only mode.

Internal Structure:

  • Introduced a private field _checkpointOverride in LiteDatabase to track any temporary changes to the checkpoint setting.

@JKamsker JKamsker changed the title Codex/create repro for litedb update issue Ensure external streams checkpoint on commit Sep 27, 2025
@JKamsker JKamsker merged commit bf3987f into dev Sep 27, 2025
2 checks passed
@JKamsker JKamsker deleted the codex/create-repro-for-litedb-update-issue branch September 27, 2025 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant