pub enum SyncMode {
FastThenSafe,
Safe,
Async,
Threshold(usize),
Fast,
}
Expand description
Disk synchronization mode.
This controls how/when the database syncs its data to disk.
Regardless of the variant chosen, dropping Env
will always cause it to fully sync to disk.
§Sync vs Async
All invariants except SyncMode::Async
& SyncMode::Fast
are synchronous
, as in the database will wait until the OS has
finished syncing all the data to disk before continuing.
SyncMode::Async
& SyncMode::Fast
are asynchronous
, meaning
the database will NOT wait until the data is fully synced to disk
before continuing. Note that this doesn’t mean the database itself
won’t be synchronized between readers/writers, but rather that the
data on disk may not be immediately synchronized after a write.
Something like:
db.put("key", value);
db.get("key");
will be fine, most likely pulling from memory instead of disk.
§SOMEDAY
Dynamic sync’s are not yet supported.
Only:
are supported, all other variants will panic on crate::Env::open
.
Variants§
FastThenSafe
Use SyncMode::Fast
until fully synced,
then use SyncMode::Safe
.
Safe
Fully sync to disk per transaction.
Every database transaction commit will fully sync all data to disk, synchronously, so the database (writer) halts until synced.
This is expected to be very slow.
This maps to:
- LMDB without any special sync flags
redb::Durability::Immediate
Async
Asynchrously sync to disk per transaction.
This is the same as SyncMode::Safe
,
but the syncs will be asynchronous, i.e.
each transaction commit will sync to disk,
but only eventually, not necessarily immediately.
This maps to:
Threshold(usize)
Fully sync to disk after we cross this transaction threshold.
After committing usize
amount of database
transactions, it will be sync to disk.
0
behaves the same as SyncMode::Safe
, and a ridiculously large
number like usize::MAX
is practically the same as SyncMode::Fast
.
Fast
Only flush at database shutdown.
This is the fastest, yet unsafest option.
It will cause the database to never actively sync, letting the OS decide when to flush data to disk1.
This maps to:
§Corruption
In the case of a system crash, the database may become corrupted when using this option.
Semantically, this variant would actually map to
redb::Durability::None
, however due to#149
, this is not possible. As such, when using theredb
backend, transaction writes “should be persistent some time afterWriteTransaction::commit
returns.” Thus,SyncMode::Async
will map to the sameredb::Durability::Eventual
asSyncMode::Fast
. ↩
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SyncMode
impl<'de> Deserialize<'de> for SyncMode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for SyncMode
impl Ord for SyncMode
Source§impl PartialOrd for SyncMode
impl PartialOrd for SyncMode
impl Copy for SyncMode
impl Eq for SyncMode
impl StructuralPartialEq for SyncMode
Auto Trait Implementations§
impl Freeze for SyncMode
impl RefUnwindSafe for SyncMode
impl Send for SyncMode
impl Sync for SyncMode
impl Unpin for SyncMode
impl UnwindSafe for SyncMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes
Size for each variant:
FastThenSafe
: 0 bytesSafe
: 0 bytesAsync
: 0 bytesThreshold
: 8 bytesFast
: 0 bytes