1use ahash::RandomState;
2use crossbeam_skiplist::SkipMap;
3use parking_lot::RwLock;
4use scc::HashMap;
5use std::sync::Arc;
6
7use crate::core::record::Record;
8use crate::core::ttl_sweep::TtlSweeper;
9use crate::stats::Statistics;
10use crate::storage::free_space::FreeSpaceManager;
11use crate::storage::metadata::Metadata;
12use crate::storage::write_buffer::WriteBuffer;
13
14pub use self::builder::{StoreBuilder, StoreConfig};
16
17pub mod atomic;
19pub mod builder;
20pub mod init;
21pub mod internal;
22pub mod json_patch;
23pub mod operations;
24pub mod persistence;
25pub mod range;
26pub mod recovery;
27pub mod ttl;
28
29pub struct FeoxStore {
39 pub(super) hash_table: HashMap<Vec<u8>, Arc<Record>, RandomState>,
41
42 pub(super) tree: Arc<SkipMap<Vec<u8>, Arc<Record>>>,
44
45 pub(super) stats: Arc<Statistics>,
47
48 pub(super) write_buffer: Option<Arc<WriteBuffer>>,
50
51 pub(super) free_space: Arc<RwLock<FreeSpaceManager>>,
53
54 pub(super) _metadata: Arc<RwLock<Metadata>>,
56
57 pub(super) memory_only: bool,
59 pub(super) enable_caching: bool,
60 pub(super) max_memory: Option<usize>,
61
62 pub(super) cache: Option<Arc<super::cache::ClockCache>>,
64 #[cfg(unix)]
65 pub(super) device_fd: Option<i32>,
66 pub(super) device_size: u64,
67 pub(super) device_file: Option<std::fs::File>,
68
69 pub(super) disk_io: Option<Arc<RwLock<crate::storage::io::DiskIO>>>,
71
72 pub(super) ttl_sweeper: Arc<RwLock<Option<TtlSweeper>>>,
74
75 pub(super) enable_ttl: bool,
77}
78
79impl FeoxStore {
80 pub fn builder() -> StoreBuilder {
95 StoreBuilder::new()
96 }
97
98 pub fn contains_key(&self, key: &[u8]) -> bool {
102 self.hash_table.contains(key)
103 }
104
105 pub fn len(&self) -> usize {
107 self.stats
108 .record_count
109 .load(std::sync::atomic::Ordering::Acquire) as usize
110 }
111
112 pub fn is_empty(&self) -> bool {
114 self.len() == 0
115 }
116
117 pub fn memory_usage(&self) -> usize {
119 self.stats
120 .memory_usage
121 .load(std::sync::atomic::Ordering::Acquire)
122 }
123
124 pub fn stats(&self) -> crate::stats::StatsSnapshot {
126 self.stats.snapshot()
127 }
128
129 pub fn flush(&self) {
131 self.flush_all()
132 }
133}