Skip to content

Conversation

@psrvere
Copy link
Contributor

@psrvere psrvere commented Dec 22, 2025

Closes #57
Closes #61

Implements consistent point-in-time snapshot API in the rust SDK

  • discovers and creates tables and indexes from sqlite_schema
  • clones data for each table
  • fsync is switched off for faster writes

Implements consistent point-in-time snapshot API in the rust SDK
- discovers and creates tables and indexes from sqlite_schema
- clones data for each table
- fsync is switched off for faster writes

Signed-off-by: Prateek Singh Rathore <[email protected]>
@penberg
Copy link
Collaborator

penberg commented Dec 22, 2025

Hey @psrvere, interesting approach. The idea here is that the immediate transaction ensures that there are no new WAL entries, which seems to be safe. However, I suspect this is going to be pretty slow for larger databases because it's all going through the SQL interface as far as I can tell. IMHO, a better long-term strategy is to do this in turso.git and just make a copy of the database file itself while blocking concurrent writers.

@psrvere
Copy link
Contributor Author

psrvere commented Dec 22, 2025

Thanks for the feedback @penberg. Yes, copying the file would be much faster. I saw a similar SQL based implementation in turso CLI and hence assumed that if its good there, it should be good in AgentFS.

Let me do a file copy snapshot implementation in turso and share a draft PR soon.

psrvere added a commit to psrvere/turso that referenced this pull request Dec 24, 2025
This addresses feedback from tursodatabase/agentfs#119 suggesting that snapshot functionality should be implemented in turso.git using direct fily copying rather than SQL-based row by row copying.
Comment: https:://github.com/tursodatabase/agentfs/pull/119#issuecomment-3681336678

- extract core logic from Pager::checkpoint function to a new Pager::checkpoing_internal function and add a flag to keep_lock during the Finalize phase
- create wrapper functions Pager::checkpoint, Pager::checkpoint_with_lock and Pager::block_checkpoint_keep_lock
- add Connection::snapshot API that checkpoints while keeping the lock and copies the database file

The lock is held to avoid a race condition after finishing checkpointing and before copying the file when concurrent writers can write to db.

Signed-off-by: Prateek Singh Rathore <[email protected]>
psrvere added a commit to psrvere/turso that referenced this pull request Dec 24, 2025
This addresses feedback from tursodatabase/agentfs#119 suggesting that snapshot functionality should be implemented in turso.git using direct fily copying rather than SQL-based row by row copying.
Comment: https:://github.com/tursodatabase/agentfs/pull/119#issuecomment-3681336678

- extract core logic from Pager::checkpoint function to a new Pager::checkpoing_internal function and add a flag to keep_lock during the Finalize phase
- create wrapper functions Pager::checkpoint, Pager::checkpoint_with_lock and Pager::block_checkpoint_keep_lock
- add Connection::snapshot API that checkpoints while keeping the lock and copies the database file

The lock is held to avoid a race condition after finishing checkpointing and before copying the file when concurrent writers can write to db.

Signed-off-by: Prateek Singh Rathore <[email protected]>
@psrvere
Copy link
Contributor Author

psrvere commented Dec 24, 2025

@penberg - I created tursodatabase/turso#4346 PR for adding snapshot API to Connection. Please review.
Once that PR gets merged, I will close this one and create a new PR using that API.

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.

agentfs snapshot command Snapshotting

2 participants