buckethead.storage.snapshot¶
Pure flush() and restore() primitives. No threading, no lifecycle —
that's core.BucketSQLite's job.
buckethead.storage.snapshot
¶
Snapshot primitives: flush() and restore().
Pure functions — no threading, no lifecycle, no signal handling. The flush loop and signal/atexit wiring live in lifecycle.py (Phase 5); BucketSQLite.start() and .stop() orchestrate both (Phase 6).
See plan/build-plan.md — Phase 4.
SnapshotError
¶
Bases: Exception
Base class for snapshot-related failures.
SnapshotCorruptError
¶
Bases: SnapshotError
Raised when a downloaded snapshot fails SQLite integrity checks.
FlushResult
dataclass
¶
Outcome of a single flush() call.
restore
¶
restore(
conn: Connection, bucket_client: BucketClient, key: str
) -> bool
Download the snapshot at key and hydrate it into conn.
Returns True if a snapshot was found and restored, False if no
snapshot object exists at that key. Raises SnapshotCorruptError
if the downloaded file fails PRAGMA integrity_check.
Source code in src/buckethead/storage/snapshot.py
flush
¶
flush(
conn: Connection,
bucket_client: BucketClient,
key: str,
*,
keep_previous: bool,
last_hash: str | None = None,
) -> FlushResult
Back up conn to a temp file and upload it to key.
Dirty-bit optimization: the temp file is hashed (SHA-256) and if the
hash matches last_hash, neither the upload nor the .prev copy
runs. Callers pass back the snapshot_hash from the previous
FlushResult so the next call can skip when nothing has changed.
On read-heavy workloads this eliminates both the upload and the
copy R2 class-A operations when the DB is idle.
keep_previous has its normal semantics when we do upload: if a
prior snapshot exists at key, server-side copy it to key+".prev"
before overwriting. First-ever flush skips the copy (no source yet).