#![warn(clippy::unwrap_used)]
#[cfg(feature = "armour")]
mod access;
mod batch;
#[cfg(feature = "var-collections")]
mod byte_view;
#[cfg(feature = "var-collections")]
mod cache;
#[cfg(feature = "typed-tree")]
pub mod codec;
pub mod compaction;
mod config;
mod const_map;
mod const_tree;
#[cfg(feature = "encryption")]
mod crypto;
mod ctx;
#[cfg(feature = "ctx-gates")]
#[doc(hidden)]
pub mod ctx_gates_sync;
#[cfg(feature = "var-collections")]
mod decoded_cache;
mod disk_loc;
pub mod durability;
mod engine;
mod entry;
mod error;
pub mod fixed;
mod flusher;
#[cfg(feature = "replication")]
pub(crate) mod frame_reader;
mod held_ops;
mod hint;
mod hook;
mod io;
mod key;
mod lock;
mod map_index;
mod meta;
#[cfg(feature = "typed-tree")]
mod projection;
mod recovery;
#[cfg(feature = "encryption")]
mod salt;
mod scope;
mod shard;
mod shutdown;
#[cfg(any(feature = "loom", miri, feature = "bench-internals"))]
pub mod skiplist;
#[cfg(not(any(feature = "loom", miri, feature = "bench-internals")))]
mod skiplist;
mod sweeper;
mod sync;
#[cfg(all(test, feature = "typed-tree"))]
mod test_faults;
mod tree_meta;
mod ttl;
#[allow(dead_code)]
mod txlog;
mod txn_depth;
pub(crate) use txn_depth::AtomicDepthGuard;
#[cfg(feature = "armour")]
#[cfg(not(feature = "test-faults"))]
#[allow(dead_code)]
mod txn;
#[cfg(all(feature = "armour", feature = "test-faults"))]
#[allow(dead_code)]
pub mod txn;
#[cfg(feature = "armour")]
pub use txn::{Tx, TxConfig};
mod upsert;
#[cfg(feature = "var-collections")]
mod value_cache;
#[cfg(feature = "var-collections")]
mod var_map;
#[cfg(feature = "var-collections")]
mod var_tree;
#[cfg(feature = "typed-tree")]
mod zero_map;
#[cfg(feature = "typed-tree")]
mod zero_tree;
#[cfg(feature = "typed-tree")]
mod typed_map;
#[cfg(feature = "typed-tree")]
mod typed_tree;
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
mod var_typed_map;
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
mod var_typed_tree;
#[cfg(feature = "replication")]
pub mod replication;
#[cfg(feature = "replication")]
pub mod fixed_replication;
pub mod docs;
#[cfg(feature = "armour")]
pub mod armour;
#[cfg(feature = "schema")]
pub mod schema;
#[cfg(feature = "fjall")]
pub mod lsm;
#[cfg(feature = "armour")]
pub use armour_core;
pub use batch::Applied;
#[allow(deprecated)]
pub use batch::BatchWrite;
#[cfg(feature = "var-collections")]
pub use byte_view::ByteView;
#[cfg(feature = "bitcode-codec")]
pub use codec::BitcodeCodec;
#[cfg(feature = "typed-tree")]
pub use codec::Codec;
#[cfg(feature = "typed-tree")]
pub use codec::InspectionEncoding;
#[cfg(feature = "postcard-codec")]
pub use codec::PostcardCodec;
#[cfg(feature = "rapira-codec")]
pub use codec::RapiraCodec;
#[cfg(feature = "typed-tree")]
pub use codec::ZerocopyCodec;
#[cfg(feature = "bytemuck-codec")]
pub use codec::{BytemuckCodec, BytemuckSliceCodec, BytemuckVec};
pub use compaction::Compactor;
#[cfg(feature = "var-collections")]
pub use config::CacheConfig;
pub use config::Config;
pub use config::IoBackend;
pub use config::Workload;
pub use const_map::{ConstMap, ConstMapIterView, ConstMapShard};
pub use const_tree::{ConstIter, ConstShard, ConstTree};
#[cfg(feature = "encryption")]
pub use crypto::PageCipher;
pub use error::{DbError, DbResult, FencedShard, SchemaMismatchKind, TxFailStage};
pub use fixed::{FixedConfig, FixedMap, FixedTree, FixedWorkload};
pub use flusher::Flusher;
#[cfg(feature = "typed-tree")]
pub use hook::TypedWriteHook;
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
pub use hook::VarTypedHookAdapter;
#[cfg(feature = "typed-tree")]
pub use hook::ZeroHookAdapter;
pub use hook::{NoHook, WriteHook};
pub use key::{Key, Location};
pub use map_index::{Dir, KeyPage, Page};
#[doc(hidden)]
pub use projection::{CountingIndex, FailFirstDeleteIndex, FailNPutsIndex};
#[cfg(feature = "typed-tree")]
pub use projection::{
DEFAULT_MAX_PROJECTED_BYTES, DEFAULT_MAX_PROJECTED_ROWS, IndexKeyed, IndexTargets, Indexed,
PendingProjection, ProjectableIndex, ProjectionSink,
};
pub use scope::{
ConstMapKeyIter, ConstMapRowIter, ConstTreeKeyIter, ConstTreeRowIter, MapScan, MappedPage,
OrderedScan, OwnedRows, Scope, TreeScan,
};
#[cfg(feature = "fjall")]
pub use scope::{LsmKeyIter, LsmRowIter};
#[cfg(feature = "typed-tree")]
pub use scope::{
MapKeyIter, MapRowIter, TreeKeyIter, TreeRowIter, ZeroMapKeyIter, ZeroMapRowIter,
ZeroTreeKeyIter, ZeroTreeRowIter,
};
#[cfg(feature = "var-collections")]
pub use scope::{VarMapKeyIter, VarMapRowIter, VarTreeKeyIter, VarTreeRowIter};
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
pub use scope::{VarTypedMapKeyIter, VarTypedMapRowIter, VarTypedTreeKeyIter, VarTypedTreeRowIter};
pub use shutdown::ShutdownSignal;
pub use sweeper::{SweepPassResult, Sweeper};
pub use tree_meta::{CollectionMeta, TreeMeta};
pub use ttl::{SweepOutcome, TtlHook, TtlPolicy};
#[cfg(feature = "typed-tree")]
pub use typed_map::{TypedMap, TypedMapIterView, TypedMapShard};
#[cfg(feature = "typed-tree")]
pub use typed_tree::{TypedIter, TypedRef, TypedShard, TypedTree};
pub use upsert::{IntoUpsert, Upsert};
#[cfg(feature = "var-collections")]
pub use var_map::{VarMap, VarMapShard};
#[cfg(feature = "var-collections")]
pub use var_tree::{VarIter, VarShard, VarTree};
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
pub use var_typed_map::{VarTypedMap, VarTypedMapIterView, VarTypedMapShard};
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
pub use var_typed_tree::{VarTypedIter, VarTypedShard, VarTypedTree};
#[cfg(feature = "typed-tree")]
pub use zero_map::{ZeroMap, ZeroMapIterView, ZeroMapShard};
#[cfg(feature = "typed-tree")]
pub use zero_tree::{ZeroIter, ZeroShard, ZeroTree};
#[doc(hidden)]
pub use disk_loc::DiskLoc;
#[doc(hidden)]
pub use entry::{
EntryHeader, FLAGS_MASK, SEQUENCE_MASK, SOFT_DELETE_BIT, TOMBSTONE_BIT, compute_crc32,
entry_size, serialize_entry,
};
#[doc(hidden)]
pub use hint::{HintEntry, hint_entry_size, parse_hint_entries};
use std::mem::size_of;
pub(crate) fn shard_for_key<K: Key>(
key: &K,
shard_prefix_bits: usize,
shard_count: usize,
) -> usize {
if shard_prefix_bits == 0 || shard_prefix_bits >= size_of::<K>() * 8 {
let hash = xxhash_rust::xxh3::xxh3_64(key.as_bytes());
return (hash as usize) % shard_count;
}
let full_bytes = shard_prefix_bits / 8;
let extra_bits = shard_prefix_bits % 8;
let hash = if extra_bits == 0 {
xxhash_rust::xxh3::xxh3_64(&key.as_bytes()[..full_bytes])
} else {
let mut buf = K::zeroed();
buf.as_bytes_mut()[..full_bytes + 1].copy_from_slice(&key.as_bytes()[..full_bytes + 1]);
let mask = !((1u8 << (8 - extra_bits)) - 1);
buf.as_bytes_mut()[full_bytes] = key.as_bytes()[full_bytes] & mask;
xxhash_rust::xxh3::xxh3_64(&buf.as_bytes()[..full_bytes + 1])
};
(hash as usize) % shard_count
}
pub enum MigrateAction<V> {
Keep,
Update(V),
Delete,
}
#[cfg(feature = "typed-tree")]
#[macro_export]
macro_rules! zero_tree {
($V:ty) => {
$crate::ZeroTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $crate::NoHook>,
>
};
($V:ty, fixed) => {
$crate::ZeroTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $crate::NoHook>,
$crate::durability::Fixed,
>
};
($V:ty, $H:ty) => {
$crate::ZeroTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $H>,
$crate::durability::Bitcask,
>
};
($V:ty, $H:ty, fixed) => {
$crate::ZeroTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $H>,
$crate::durability::Fixed,
>
};
}
#[cfg(feature = "typed-tree")]
#[macro_export]
macro_rules! zero_map {
($V:ty) => {
$crate::ZeroMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $crate::NoHook>,
>
};
($V:ty, fixed) => {
$crate::ZeroMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $crate::NoHook>,
$crate::durability::Fixed,
>
};
($V:ty, $H:ty) => {
$crate::ZeroMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $H>,
$crate::durability::Bitcask,
>
};
($V:ty, $H:ty, fixed) => {
$crate::ZeroMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$V,
$crate::TtlHook<$V, $H>,
$crate::durability::Fixed,
>
};
}
#[macro_export]
macro_rules! const_tree {
($V:ty) => {
$crate::ConstTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
>
};
($V:ty, fixed) => {
$crate::ConstTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$crate::NoHook,
$crate::durability::Fixed,
>
};
($V:ty, $H:ty) => {
$crate::ConstTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$H,
$crate::durability::Bitcask,
>
};
($V:ty, $H:ty, fixed) => {
$crate::ConstTree<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$H,
$crate::durability::Fixed,
>
};
}
#[macro_export]
macro_rules! const_map {
($V:ty) => {
$crate::ConstMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
>
};
($V:ty, fixed) => {
$crate::ConstMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$crate::NoHook,
$crate::durability::Fixed,
>
};
($V:ty, $H:ty) => {
$crate::ConstMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$H,
$crate::durability::Bitcask,
>
};
($V:ty, $H:ty, fixed) => {
$crate::ConstMap<
<$V as $crate::CollectionMeta>::SelfId,
{ ::std::mem::size_of::<$V>() },
$H,
$crate::durability::Fixed,
>
};
}
#[cfg(feature = "typed-tree")]
#[macro_export]
macro_rules! typed_tree {
($V:ty, $C:ty) => {
$crate::TypedTree<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $crate::NoHook>,
>
};
($V:ty, $C:ty, $H:ty) => {
$crate::TypedTree<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $H>,
>
};
}
#[cfg(feature = "typed-tree")]
#[macro_export]
macro_rules! typed_map {
($V:ty, $C:ty) => {
$crate::TypedMap<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $crate::NoHook>,
>
};
($V:ty, $C:ty, $H:ty) => {
$crate::TypedMap<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $H>,
>
};
}
#[cfg(feature = "var-collections")]
#[macro_export]
macro_rules! var_tree {
($V:ty) => {
$crate::VarTree<<$V as $crate::CollectionMeta>::SelfId>
};
($V:ty, $H:ty) => {
$crate::VarTree<<$V as $crate::CollectionMeta>::SelfId, $H>
};
}
#[cfg(feature = "var-collections")]
#[macro_export]
macro_rules! var_map {
($V:ty) => {
$crate::VarMap<<$V as $crate::CollectionMeta>::SelfId>
};
($V:ty, $H:ty) => {
$crate::VarMap<<$V as $crate::CollectionMeta>::SelfId, $H>
};
}
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
#[macro_export]
macro_rules! var_typed_tree {
($V:ty, $C:ty) => {
$crate::VarTypedTree<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $crate::NoHook>,
>
};
($V:ty, $C:ty, $H:ty) => {
$crate::VarTypedTree<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $H>,
>
};
}
#[cfg(all(feature = "typed-tree", feature = "var-collections"))]
#[macro_export]
macro_rules! var_typed_map {
($V:ty, $C:ty) => {
$crate::VarTypedMap<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $crate::NoHook>,
>
};
($V:ty, $C:ty, $H:ty) => {
$crate::VarTypedMap<
<$V as $crate::CollectionMeta>::SelfId,
$V,
$C,
$crate::TtlHook<$V, $H>,
>
};
}