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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! Public configuration types for the persistence layer.
//!
//! [`PersistConfig`] is what a caller hands to [`crate::PersistedIndex`].
//! As of v0.3 it implements the snapshot subset (path, fsync policy) plus
//! the **write-ahead log** (`wal_enabled`). The compression variants are
//! present so the v0.4 wiring lands without an API break; until then they
//! are rejected at construction with a clear
//! [`crate::PersistError::Unsupported`] rather than panicking or silently
//! no-oping.
use PathBuf;
use Duration;
/// How aggressively the persistence layer fsyncs to durable storage.
///
/// Snapshot saves honor `Always` and `Never` (and treat `Periodic` as
/// `Always`, since a snapshot is a single write). For WAL appends,
/// `Periodic(interval)` `fsync`s no more than once per `interval`,
/// trading a bounded window of un-`fsync`ed tail records for throughput.
///
/// # Examples
///
/// ```
/// use iqdb_persist::FsyncPolicy;
/// use std::time::Duration;
///
/// let _ = FsyncPolicy::Always;
/// let _ = FsyncPolicy::Periodic(Duration::from_secs(1));
/// let _ = FsyncPolicy::Never;
/// ```
/// Compression applied to the snapshot payload on save (v0.4+).
///
/// `Zstd` and `Lz4` are gated behind the `zstd` / `lz4` cargo features.
/// Selecting a scheme whose feature is not compiled in returns
/// [`crate::PersistError::Unsupported`] at [`crate::PersistedIndex`]
/// construction — never a panic or a silent fallback. Compression applies
/// only to snapshots; the WAL is always stored uncompressed.
///
/// # Examples
///
/// ```
/// use iqdb_persist::Compression;
///
/// let none = Compression::None;
/// let zstd = Compression::Zstd { level: 3 };
/// let lz4 = Compression::Lz4;
/// let _ = (none, zstd, lz4);
/// ```
/// Configuration for [`crate::PersistedIndex`].
///
/// Construct with [`PersistConfig::new`] (recommended) and override the
/// fields you want, or start from [`PersistConfig::default`] for a
/// no-path placeholder + sensible knobs.
///
/// # Examples
///
/// ```
/// use iqdb_persist::{Compression, FsyncPolicy, PersistConfig};
/// use std::path::PathBuf;
///
/// let cfg = PersistConfig::new("/tmp/my-snapshot.iqdb");
/// assert_eq!(cfg.path, PathBuf::from("/tmp/my-snapshot.iqdb"));
/// assert_eq!(cfg.fsync_policy, FsyncPolicy::Always);
/// assert_eq!(cfg.compression, Compression::None);
/// assert!(!cfg.wal_enabled);
/// ```