benbjohnson / litestream

Streaming replication for SQLite.
https://litestream.io
Apache License 2.0
11.12k stars 256 forks source link

Use safe checkpointing before snapshots #522

Closed hifi closed 11 months ago

hifi commented 1 year ago

The intention of the code is to do a checkpoint before starting to write out the snapshot. Executing a manual checkpoint will at worst make Litestream lose the track of the WAL as it will in specific circumtances flush out the single page in the WAL file out.

Using the public checkpoint function of the database to issue a managed passive checkpoint will ensure the sequence table is written after and the position of the WAL isn't lost.

Fixes #521

hifi commented 1 year ago

This doesn't pass tests because they expect the WAL not to be checkpointed during snapshots. I'm looking into it if I can change the tests to match the new behavior but they are very specific about it and the first WAL index (0) is basically never used when we always checkpoint on snapshot.

hifi commented 1 year ago

Figured out the test fixes. Should be good if "losing" zero index is acceptable.