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::error::Result;
10use crate::stats::Statistics;
11use crate::storage::free_space::FreeSpaceManager;
12use crate::storage::metadata::Metadata;
13use crate::storage::write_buffer::WriteBuffer;
14
15pub use self::builder::{StoreBuilder, StoreConfig};
17
18pub mod atomic;
20pub mod builder;
21pub mod init;
22pub mod internal;
23pub mod json_patch;
24pub mod operations;
25pub mod persistence;
26pub mod range;
27pub mod recovery;
28pub mod ttl;
29
30pub struct FeoxStore {
40 pub(super) hash_table: HashMap<Vec<u8>, Arc<Record>, RandomState>,
42
43 pub(super) tree: Arc<SkipMap<Vec<u8>, Arc<Record>>>,
45
46 pub(super) stats: Arc<Statistics>,
48
49 pub(super) write_buffer: Option<Arc<WriteBuffer>>,
51
52 pub(super) free_space: Arc<RwLock<FreeSpaceManager>>,
54
55 pub(super) _metadata: Arc<RwLock<Metadata>>,
57
58 pub(super) memory_only: bool,
60 pub(super) enable_caching: bool,
61 pub(super) max_memory: Option<usize>,
62
63 pub(super) cache: Option<Arc<super::cache::ClockCache>>,
65 #[cfg(unix)]
66 pub(super) device_fd: Option<i32>,
67 pub(super) device_size: u64,
68 pub(super) device_file: Option<std::fs::File>,
69
70 pub(super) disk_io: Option<Arc<RwLock<crate::storage::io::DiskIO>>>,
72
73 pub(super) ttl_sweeper: Arc<RwLock<Option<TtlSweeper>>>,
75
76 pub(super) enable_ttl: bool,
78}
79
80impl FeoxStore {
81 pub fn builder() -> StoreBuilder {
96 StoreBuilder::new()
97 }
98
99 pub fn contains_key(&self, key: &[u8]) -> bool {
103 self.hash_table.contains(key)
104 }
105
106 pub fn len(&self) -> usize {
108 self.stats
109 .record_count
110 .load(std::sync::atomic::Ordering::Acquire) as usize
111 }
112
113 pub fn is_empty(&self) -> bool {
115 self.len() == 0
116 }
117
118 pub fn memory_usage(&self) -> usize {
120 self.stats
121 .memory_usage
122 .load(std::sync::atomic::Ordering::Acquire)
123 }
124
125 pub fn stats(&self) -> crate::stats::StatsSnapshot {
127 self.stats.snapshot()
128 }
129
130 pub fn flush(&self) -> Result<()> {
132 self.flush_all()
133 }
134}