#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(all(not(feature = "std"), not(feature = "external-clock")))]
compile_error!(
"kevy-store without `std` needs the `external-clock` feature: the TTL \
clock must be host-fed when std::time is unavailable"
);
extern crate alloc;
#[cfg(not(feature = "std"))]
pub(crate) mod nostd_prelude {
pub(crate) use alloc::boxed::Box;
pub(crate) use alloc::format;
pub(crate) use alloc::string::{String, ToString};
pub(crate) use alloc::vec::Vec;
}
#[cfg(not(feature = "std"))]
use nostd_prelude::*;
#[cfg(feature = "std")]
pub(crate) type SideMap<K, V> = std::collections::HashMap<K, V>;
#[cfg(not(feature = "std"))]
pub(crate) type SideMap<K, V> = kevy_map::KevyMap<K, V>;
mod accounting;
#[cfg(feature = "std")]
mod bio_drop;
#[cfg(not(feature = "std"))]
impl Store {
#[inline]
pub(crate) fn maybe_offload_drop(&mut self, old: Value) {
drop(old);
}
}
mod bitmap;
mod clock;
mod cond;
pub use cond::{InsertPosition, ListEnd, ScoreCompare, SetCondition};
mod defrag;
pub use defrag::{DefragHint, DefragStep};
mod entry;
mod error;
pub use bitmap::BitOp;
pub use error::{KevyError, KevyResult};
pub mod evict;
pub mod expire;
pub(crate) use entry::Entry;
pub use expire::ExpireStats;
pub use store_admin::DetachedEntries;
mod hash;
mod hash_read;
mod hash_weight;
pub use hash_read::FieldValuePairs;
mod hash_ttl;
pub use hash_ttl::{HExpireCode, HExpireCond};
mod keyspace;
mod keyspace_load;
mod keyspace_map;
mod list;
mod list_read;
pub mod list_seg;
mod notify;
mod rng;
mod row_watch;
mod row_watch_store;
pub use row_watch::{RowChange, RowChanges, RowWatch};
mod scan;
pub mod seg_map;
pub use notify::KeyspaceEvent;
mod list_ops;
mod set;
mod set_read;
mod small_set;
pub use small_set::{SmallSetData, SmallSetIter};
pub mod packed_row;
mod small_hash;
mod value_weight;
pub use small_hash::{SmallHashData, SmallHashIter};
mod small_list;
pub use small_list::{SmallListData, SmallListIter};
mod small_zset;
pub use small_zset::{SmallZSetData, SmallZSetIter};
mod snapshot;
pub use snapshot::SnapshotView;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod segrows;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod segrows_error;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod segwindow;
mod stream;
mod string;
mod string_rmw;
mod string_set;
mod tier;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod tier_batch;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod tier_codec;
mod tier_demote;
mod tier_serve;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod tier_state;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod tier_stats;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use segrows::SealedRows;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use segrows_error::SegRowsError;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use kevy_vlog::CompressionStats;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use tier::TierStats;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use tier_serve::{ColdBatchReader, ColdRead, PeekRow, SyncColdRead};
mod types;
pub use types::{EvictionPolicy, RenameOutcome, StoreError};
mod util;
mod value;
mod value_cold;
mod value_enum;
mod zset;
mod zset_algebra;
mod zset_range;
pub mod zset_seg;
pub use zset_algebra::{ZAggregate, zdiff, zinter, zintercard, zunion};
mod zset_flags;
pub use stream::{
APPROX_TRIM_LIMIT, AckMode, AutoclaimResult, ClaimMode, ConsumerGroup, ConsumerState,
EntryBatch, GroupBatch, GroupCreateMode, LoadedGroup, LoadedPelEntry, LoadedStreamEntry,
MissingStream, PelEntry, PendingExtended, PendingExtendedRow, PendingSummary, ReadGroupId,
StreamData, StreamId, StreamIdError, TrimMode, TrimTo, XAddIdSpec, XClaimOpts, now_unix_ms,
parse_explicit_id, parse_range_end, parse_range_start, parse_xadd_id,
};
pub use string::{GetReply, GetShared};
pub use util::glob_match;
pub use value::*;
pub use zset_flags::{ZaddFlags, ZaddReport};
#[cfg(any(feature = "external-clock", all(target_arch = "wasm32", target_os = "unknown")))]
pub use clock::set_clock_ns;
#[cfg(any(feature = "external-clock", all(target_arch = "wasm32", target_os = "unknown")))]
pub use clock::set_wall_clock_ms;
pub(crate) use clock::{deadline_at, now_ns, pack_deadline, remaining_ms};
use kevy_map::KevyMap;
#[derive(Debug, Default)]
pub struct Store {
pub(crate) map: keyspace_map::Keyspace,
pub(crate) defrag: defrag::DefragState,
pub(crate) rng: rng::Rng,
pub(crate) hfttl: SideMap<SmallBytes, KevyMap<SmallBytes, u64>>,
pub(crate) packed_rows: bool,
pub(crate) row_shapes: Vec<packed_row::ColumnNames>,
pub(crate) cached_ns: u64,
pub(crate) cached_clock: bool,
pub(crate) used_memory: u64,
pub(crate) maxmemory: u64,
pub(crate) memory_refused: bool,
pub(crate) write_gate: bool,
pub(crate) eviction_policy: EvictionPolicy,
pub(crate) evictions_total: u64,
pub(crate) clock_counter: u64,
pub(crate) keyspace_bytes: u64,
pub(crate) used_memory_peak: u64,
pub(crate) expired_keys_total: u64,
pub(crate) notify_capture: u8,
pub(crate) notify_events: Vec<(notify::KeyspaceEvent, Vec<u8>)>,
pub(crate) expired_keys: Vec<Vec<u8>>,
pub(crate) expires: u64,
pub(crate) watch_versions: SideMap<Vec<u8>, u64>,
#[cfg(feature = "std")]
pub(crate) bio_drop_sender: Option<value::BioDropSender>,
#[cfg(feature = "std")]
pub(crate) pending_drops: Vec<Value>,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) tier: Option<tier::TierState>,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) segrows: Option<segrows::SegRows>,
#[cfg_attr(any(not(feature = "std"), target_arch = "wasm32"), allow(dead_code))]
pub(crate) cold_backing: bool,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) tier_scratch: Option<Entry>,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) tier_peek: bool,
}
mod store_admin;
#[cfg(not(all(feature = "std", not(target_arch = "wasm32"))))]
impl Store {
pub fn row_seg_files(&self) -> Vec<(u32, alloc::string::String)> {
Vec::new()
}
}
pub(crate) use util::{apply_delta, key_heap_bytes_for};
const _: () = {
const fn send_sync<T: Send + Sync>() {}
send_sync::<Store>();
send_sync::<StoreError>();
send_sync::<KevyError>();
send_sync::<RenameOutcome>();
send_sync::<EvictionPolicy>();
send_sync::<SetCondition>();
send_sync::<ListEnd>();
send_sync::<InsertPosition>();
send_sync::<ScoreCompare>();
send_sync::<BitOp>();
send_sync::<ExpireStats>();
send_sync::<DetachedEntries>();
send_sync::<HExpireCond>();
send_sync::<KeyspaceEvent>();
send_sync::<SnapshotView>();
send_sync::<ZAggregate>();
send_sync::<StreamData>();
send_sync::<StreamId>();
send_sync::<StreamIdError>();
send_sync::<XAddIdSpec>();
send_sync::<XClaimOpts>();
send_sync::<MissingStream>();
send_sync::<AckMode>();
send_sync::<ClaimMode>();
send_sync::<ConsumerGroup>();
send_sync::<ConsumerState>();
send_sync::<PelEntry>();
send_sync::<GroupCreateMode>();
send_sync::<ReadGroupId>();
send_sync::<PendingSummary>();
send_sync::<PendingExtended>();
send_sync::<AutoclaimResult>();
send_sync::<LoadedGroup>();
send_sync::<GetReply<'static>>();
send_sync::<GetShared>();
send_sync::<Value>();
send_sync::<Score>();
send_sync::<ScoreBound>();
send_sync::<ZaddFlags>();
send_sync::<ZaddReport>();
send_sync::<packed_row::PackedRow>();
};
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
const _: () = {
const fn send_sync<T: Send + Sync>() {}
send_sync::<SealedRows>();
send_sync::<SegRowsError>();
send_sync::<TierStats>();
send_sync::<ColdRead>();
send_sync::<SyncColdRead>();
};
#[cfg(test)]
mod tests;
#[cfg(test)]
mod tests_list_seg;
#[cfg(test)]
mod tests_live_entry;
#[cfg(test)]
mod tests_memory;
#[cfg(test)]
mod tests_range_past_the_end;
#[cfg(test)]
mod tests_row_watch;
#[cfg(test)]
mod tests_score_order;
#[cfg(test)]
mod tests_seg_map;
#[cfg(test)]
mod tests_snapshot;
#[cfg(test)]
mod tests_string_encoding;
#[cfg(all(test, feature = "std", not(target_arch = "wasm32")))]
mod tests_tier;
#[cfg(all(test, feature = "std", not(target_arch = "wasm32")))]
mod tests_tier_budget;
#[cfg(all(test, feature = "std", not(target_arch = "wasm32")))]
mod tests_tier_pack;
#[cfg(all(test, feature = "std", not(target_arch = "wasm32")))]
mod tests_tier_peek;
#[cfg(test)]
mod tests_zadd_same_score;
#[cfg(test)]
mod tests_zset_seg;