use crate::armour::migration::TypedMigrationFn;
use crate::codec::Codec;
use crate::error::DbResult;
use crate::hook::TypedWriteHook;
use crate::key::Key;
use crate::tree_meta::CollectionMeta;
use crate::{TypedMap, TypedTree};
pub(crate) trait ManagedOpen {
type Key;
type Val;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize>;
fn flush_for_migration(&self) -> DbResult<()>;
fn replay_init(&self);
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> crate::error::DbResult<usize> {
let _ = (db, stored_fingerprint);
Ok(0)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
let _ = arc;
}
fn register_tx_metadata(&self, _db: &crate::armour::Db) -> DbResult<()> {
Ok(())
}
fn build_ttl_index(&self) -> DbResult<()> {
Ok(())
}
fn projections_enabled(&self) -> bool {
false
}
fn reconcile_projections(&self) -> DbResult<()> {
Ok(())
}
fn bind_counter_dirty(&self, _db: &crate::armour::Db, _name: &'static str) {}
fn mark_counter_dirty(&self) -> DbResult<()> {
Ok(())
}
fn reconcile_counters(&self) -> DbResult<u64> {
Ok(0)
}
fn counter_target_names(&self) -> Vec<&'static str> {
Vec::new()
}
}
impl<T, C, H> ManagedOpen for TypedTree<T::SelfId, T, C, H>
where
T: CollectionMeta + Clone + Send + Sync + 'static,
T::SelfId: Key + Ord + Send + Sync,
C: Codec<T> + Sync + 'static,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
TypedTree::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
self.durable_flush()
}
fn replay_init(&self) {
TypedTree::replay_init(self)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> crate::error::DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
TypedTree::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn build_ttl_index(&self) -> DbResult<()> {
TypedTree::build_ttl_index(self)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
TypedTree::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
TypedTree::mark_counter_dirty(self)
}
fn reconcile_counters(&self) -> DbResult<u64> {
TypedTree::reconcile_counters(self)
}
fn counter_target_names(&self) -> Vec<&'static str> {
TypedTree::counter_target_names(self)
}
}
impl<T, C, H> ManagedOpen for TypedMap<T::SelfId, T, C, H>
where
T: CollectionMeta + Clone + Send + Sync + 'static,
T::SelfId: Key + Send + Sync + std::hash::Hash + Eq,
C: Codec<T> + Sync + 'static,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
TypedMap::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
self.durable_flush()
}
fn replay_init(&self) {
TypedMap::replay_init(self)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> crate::error::DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
TypedMap::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn build_ttl_index(&self) -> DbResult<()> {
TypedMap::build_ttl_index(self)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
TypedMap::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
TypedMap::mark_counter_dirty(self)
}
fn reconcile_counters(&self) -> DbResult<u64> {
TypedMap::reconcile_counters(self)
}
fn counter_target_names(&self) -> Vec<&'static str> {
TypedMap::counter_target_names(self)
}
}
use crate::durability::{Bitcask, Fixed};
use crate::{ZeroMap, ZeroTree};
impl<T, const V: usize, H> ManagedOpen for ZeroTree<T::SelfId, V, T, H, Bitcask>
where
T: CollectionMeta
+ Copy
+ zerocopy::IntoBytes
+ zerocopy::FromBytes
+ zerocopy::Immutable
+ Send
+ Sync
+ 'static,
T::SelfId: Key + Ord + Send + Sync,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
ZeroTree::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
ZeroTree::flush(self)
}
fn replay_init(&self) {
ZeroTree::replay_init(self)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> crate::error::DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
ZeroTree::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn build_ttl_index(&self) -> DbResult<()> {
ZeroTree::build_ttl_index(self)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
ZeroTree::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.tx_inner().counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
self.tx_inner().mark_counter_dirty()
}
fn reconcile_counters(&self) -> DbResult<u64> {
self.tx_inner().reconcile_counters()
}
fn counter_target_names(&self) -> Vec<&'static str> {
self.tx_inner().counter_target_names()
}
}
impl<T, const V: usize, H> ManagedOpen for ZeroTree<T::SelfId, V, T, H, Fixed>
where
T: CollectionMeta
+ Copy
+ zerocopy::IntoBytes
+ zerocopy::FromBytes
+ zerocopy::Immutable
+ Send
+ Sync
+ 'static,
T::SelfId: Key + Ord + Send + Sync,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
ZeroTree::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
ZeroTree::flush(self)
}
fn replay_init(&self) {
ZeroTree::replay_init(self)
}
fn build_ttl_index(&self) -> DbResult<()> {
ZeroTree::build_ttl_index(self)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> crate::error::DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
ZeroTree::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
ZeroTree::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.tx_inner().counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
self.tx_inner().mark_counter_dirty()
}
fn reconcile_counters(&self) -> DbResult<u64> {
self.tx_inner().reconcile_counters()
}
fn counter_target_names(&self) -> Vec<&'static str> {
self.tx_inner().counter_target_names()
}
}
impl<T, const V: usize, H> ManagedOpen for ZeroMap<T::SelfId, V, T, H, Bitcask>
where
T: CollectionMeta
+ Copy
+ zerocopy::IntoBytes
+ zerocopy::FromBytes
+ zerocopy::Immutable
+ Send
+ Sync
+ 'static,
T::SelfId: Key + Send + Sync + std::hash::Hash + Eq,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
ZeroMap::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
ZeroMap::flush(self)
}
fn replay_init(&self) {
ZeroMap::replay_init(self)
}
fn build_ttl_index(&self) -> DbResult<()> {
ZeroMap::build_ttl_index(self)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> crate::error::DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
ZeroMap::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
ZeroMap::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.tx_inner().counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
self.tx_inner().mark_counter_dirty()
}
fn reconcile_counters(&self) -> DbResult<u64> {
self.tx_inner().reconcile_counters()
}
fn counter_target_names(&self) -> Vec<&'static str> {
self.tx_inner().counter_target_names()
}
}
impl<T, const V: usize, H> ManagedOpen for ZeroMap<T::SelfId, V, T, H, Fixed>
where
T: CollectionMeta
+ Copy
+ zerocopy::IntoBytes
+ zerocopy::FromBytes
+ zerocopy::Immutable
+ Send
+ Sync
+ 'static,
T::SelfId: Key + Send + Sync + std::hash::Hash + Eq,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
ZeroMap::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
ZeroMap::flush(self)
}
fn replay_init(&self) {
ZeroMap::replay_init(self)
}
fn build_ttl_index(&self) -> DbResult<()> {
ZeroMap::build_ttl_index(self)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> crate::error::DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
ZeroMap::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
ZeroMap::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.tx_inner().counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
self.tx_inner().mark_counter_dirty()
}
fn reconcile_counters(&self) -> DbResult<u64> {
self.tx_inner().reconcile_counters()
}
fn counter_target_names(&self) -> Vec<&'static str> {
self.tx_inner().counter_target_names()
}
}
#[cfg(feature = "var-collections")]
mod var_typed_managed {
use super::*;
use crate::VarTypedMap;
use crate::VarTypedTree;
impl<T, C, H> ManagedOpen for VarTypedTree<T::SelfId, T, C, H>
where
T: CollectionMeta + Clone + Send + Sync + 'static,
T::SelfId: Key + Ord + Send + Sync,
C: Codec<T> + Clone + Sync + 'static,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
VarTypedTree::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
self.durable_flush()
}
fn replay_init(&self) {
VarTypedTree::replay_init(self)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
VarTypedTree::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn build_ttl_index(&self) -> DbResult<()> {
VarTypedTree::build_ttl_index(self)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
VarTypedTree::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.as_inner().counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
self.as_inner().mark_counter_dirty()
}
fn reconcile_counters(&self) -> DbResult<u64> {
self.as_inner().reconcile_counters()
}
fn counter_target_names(&self) -> Vec<&'static str> {
self.as_inner().counter_target_names()
}
}
impl<T, C, H> ManagedOpen for VarTypedMap<T::SelfId, T, C, H>
where
T: CollectionMeta + Clone + Send + Sync + 'static,
T::SelfId: Key + Send + Sync + std::hash::Hash + Eq,
C: Codec<T> + Clone + Sync + 'static,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
VarTypedMap::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
self.durable_flush()
}
fn replay_init(&self) {
VarTypedMap::replay_init(self)
}
fn bind_tx_arc(arc: &std::sync::Arc<Self>)
where
Self: Sized,
{
VarTypedMap::bind_tx_self(arc);
}
fn register_tx_metadata(&self, db: &crate::armour::Db) -> DbResult<()> {
self.tx_install_projection_metadata(db)
}
fn replay_pending_tx_log(
&self,
db: &crate::armour::Db,
stored_fingerprint: Option<u64>,
) -> DbResult<usize> {
crate::txn::replay::replay_pending(db, self, stored_fingerprint)
}
fn build_ttl_index(&self) -> DbResult<()> {
VarTypedMap::build_ttl_index(self)
}
fn projections_enabled(&self) -> bool {
H::PROJECTS
}
fn reconcile_projections(&self) -> DbResult<()> {
VarTypedMap::reconcile_projections(self)
}
fn bind_counter_dirty(&self, db: &crate::armour::Db, name: &'static str) {
let dirty = crate::counter_dirty::CounterDirty::new(name, db.counter_dirty_weak());
let _ = self.as_inner().counter_dirty.set(dirty);
}
fn mark_counter_dirty(&self) -> DbResult<()> {
self.as_inner().mark_counter_dirty()
}
fn reconcile_counters(&self) -> DbResult<u64> {
self.as_inner().reconcile_counters()
}
fn counter_target_names(&self) -> Vec<&'static str> {
self.as_inner().counter_target_names()
}
}
}
#[cfg(feature = "fjall")]
mod lsm_managed {
use super::*;
use crate::lsm::LsmTree;
impl<T, C, H> ManagedOpen for LsmTree<T::SelfId, T, C, H>
where
T: CollectionMeta + Clone + Send + Sync + 'static,
T::SelfId: Key + Ord + Send + Sync + 'static,
C: Codec<T> + Clone + Sync,
H: TypedWriteHook<T::SelfId, T> + 'static,
{
type Key = T::SelfId;
type Val = T;
fn migrate_inner(
&self,
mfn: &TypedMigrationFn<Self::Key, Self::Val>,
dry_run: bool,
) -> DbResult<usize> {
LsmTree::migrate_inner(self, mfn, dry_run)
}
fn flush_for_migration(&self) -> DbResult<()> {
LsmTree::flush(self)
}
fn replay_init(&self) {
LsmTree::replay_init(self)
}
}
}