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
//! Forced data sync per region (D-102, G7): a runtime option on a region's
//! handles, never stored on disk.
use std::sync::atomic::Ordering;
use store_io_platform::Platform;
use crate::region::{AppendRegion, PageRegion, Slot};
macro_rules! force_data_sync {
($region:ident) => {
impl<P: Platform> $region<P>
where
P::Queue: Send,
{
/// Makes every barrier on this region (for a slot, every commit; and
/// `Submitter::barrier_all`)
/// issue the OS data sync (`fdatasync`, `FlushFileBuffers`), even
/// on a power-safe store, where writes are durable at completion
/// and a barrier is otherwise free; receipts then report
/// [`data_synced`](crate::DurableReceipt::data_synced). For data
/// whose durability should not rest on a power-safe
/// classification alone: a device trusted as power-safe that
/// still reports a volatile write cache has that cache flushed.
/// (On a device with no volatile cache the OS has nothing to send
/// it: the data is on media already. On Windows every power-safe
/// write is already followed by a data flush, so forcing adds
/// one.) It applies to every handle and generation of the region,
/// but is not stored: set it again after each open.
pub fn set_force_data_sync(&self, on: bool) {
self.state().force_sync.store(on, Ordering::Release);
}
/// Whether barriers on this region always flush (see
/// [`Self::set_force_data_sync`]).
#[must_use]
pub fn force_data_sync(&self) -> bool {
self.state().forced()
}
}
};
}
force_data_sync!(AppendRegion);
force_data_sync!(PageRegion);
force_data_sync!(Slot);