use std::sync::Arc;
use arc_swap::ArcSwap;
use tessarikv_constants::COMMIT_RING_SLOTS;
use tessarikv_sync::{Sequencer, SnapshotRegistry};
use super::view::View;
use super::{Db, commits, keyspaces};
use crate::DbOptions;
use crate::statistics::Statistics;
impl Db {
pub(super) fn open_in_memory(options: &DbOptions) -> Self {
Self {
sequencer: Arc::new(Sequencer::new(0, COMMIT_RING_SLOTS)),
commits: commits::Commits::new(options.serializable_transactions()),
view: Arc::new(ArcSwap::from_pointee({
let named = options.keyspaces().iter().zip(1_u32..);
let (tables, names) = keyspaces::tables_for(
options,
named.map(|((name, _), id)| (id, name.as_str())),
);
View::recovered(tables, names, Vec::new())
})),
snapshots: Arc::new(SnapshotRegistry::new()),
#[cfg(test)]
switching: std::sync::atomic::AtomicBool::new(false),
#[cfg(test)]
limiter: None,
log: None,
installer: None,
statistics: options.statistics().then(|| Arc::new(Statistics::new())),
_lock: None,
}
}
}