store_io_engine/force.rs
1//! Forced data sync per region (D-102, G7): a runtime option on a region's
2//! handles, never stored on disk.
3
4use std::sync::atomic::Ordering;
5
6use store_io_platform::Platform;
7
8use crate::region::{AppendRegion, PageRegion, Slot};
9
10macro_rules! force_data_sync {
11 ($region:ident) => {
12 impl<P: Platform> $region<P>
13 where
14 P::Queue: Send,
15 {
16 /// Makes every barrier on this region (for a slot, every commit; and
17 /// `Submitter::barrier_all`)
18 /// issue the OS data sync (`fdatasync`, `FlushFileBuffers`), even
19 /// on a power-safe store, where writes are durable at completion
20 /// and a barrier is otherwise free; receipts then report
21 /// [`data_synced`](crate::DurableReceipt::data_synced). For data
22 /// whose durability should not rest on a power-safe
23 /// classification alone: a device trusted as power-safe that
24 /// still reports a volatile write cache has that cache flushed.
25 /// (On a device with no volatile cache the OS has nothing to send
26 /// it: the data is on media already. On Windows every power-safe
27 /// write is already followed by a data flush, so forcing adds
28 /// one.) It applies to every handle and generation of the region,
29 /// but is not stored: set it again after each open.
30 pub fn set_force_data_sync(&self, on: bool) {
31 self.state().force_sync.store(on, Ordering::Release);
32 }
33
34 /// Whether barriers on this region always flush (see
35 /// [`Self::set_force_data_sync`]).
36 #[must_use]
37 pub fn force_data_sync(&self) -> bool {
38 self.state().forced()
39 }
40 }
41 };
42}
43
44force_data_sync!(AppendRegion);
45force_data_sync!(PageRegion);
46force_data_sync!(Slot);