1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! # wal-backup
//!
//! Embedded SQLite WAL replication to S3-compatible object storage.
//!
//! **Not a sidecar — a library.** Your app links the crate, calls
//! [`DurabilityLayer::open()`], and gets automatic S3 backup in the background.
//!
//! # Architecture
//!
//! ```text
//! Your App → DurabilityLayer → SQLite DB (local, fast)
//! └→ S3 Bucket (backup, source of truth)
//! ```
//!
//! One process, one DB, one bucket prefix. Always.
//! The bucket is a backup, not a replication bus.
//!
//! # Quick Start
//!
//! ```ignore
//! use std::sync::Arc;
//! use wal_backup::{Config, DurabilityLayer, ObjectStoreBucket, SyncMode};
//!
//! let store = wal_backup::build_s3_store_from_env("my-bucket")?;
//! let bucket = Arc::new(
//! ObjectStoreBucket::new(store, "my-app".to_string())?
//! .with_writer_id("server-1"),
//! );
//!
//! let config = Config::new("/data/my.db")
//! .with_sync_mode(SyncMode::Immediate);
//!
//! let layer = DurabilityLayer::open(config, bucket).await?;
//!
//! // Write SQL — WAL frames ship to S3 automatically
//! layer.with_conn(|conn| {
//! conn.execute("INSERT INTO users (name) VALUES (?)", ["Alice"])
//! }).await?;
//!
//! // Graceful shutdown: checkpoint + final sync + release locks
//! layer.shutdown().await?;
//! ```
//!
//! # Multi-writer protection
//!
//! Two processes writing to the same bucket prefix = silent data corruption.
//! wal-backup prevents this at three levels:
//!
//! - **flock** (`.db.lock`): Two processes, same machine, same DB → [`Error::DatabaseLocked`]
//! - **lock.json** (bucket): Two processes, anywhere, same prefix → [`Error::ReplicaLocked`]
//! - **writer.json** (bucket): Wrong server opening the wrong prefix → [`Error::WrongWriter`]
//!
//! # Error handling
//!
//! ```ignore
//! match DurabilityLayer::open(config, bucket).await {
//! Err(e) if e.is_database_locked() => { /* another process on this machine */ }
//! Err(e) if e.is_replica_locked() => { /* another process anywhere */ }
//! Err(e) if e.is_wrong_writer() => { /* wrong bucket prefix */ }
//! Err(e) => return Err(e.into()),
//! Ok(layer) => { /* use it */ }
//! }
//! ```
pub use ;
pub use DurabilityLayer;
pub use HealthReport;
pub use ;
pub use CompressedBucketStore;
pub use EncryptedBucketStore;
pub use build_s3_store;
pub use build_s3_store_from_env;
pub use BucketStore;
pub use ObjectStoreBucket;
pub use ;
pub use L1File;
pub use Manifest;
pub use compute_sha256_file;
pub use WalFile;
pub use WalFrame;
pub use WalHeader;