reifydb-store-commit 0.9.1

Commit buffer holding committed multi-version rows before they are swept to persistent storage
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 ReifyDB

#![cfg_attr(not(debug_assertions), deny(clippy::disallowed_methods))]
#![cfg_attr(debug_assertions, warn(clippy::disallowed_methods))]
#![cfg_attr(not(debug_assertions), deny(warnings))]
#![allow(clippy::tabs_in_doc_comments)]

pub mod entry;
pub mod rows;
pub mod store;

use std::collections::HashMap;

use reifydb_codec::key::encoded::EncodedKey;
use reifydb_core::{common::CommitVersion, interface::store::EntryKind, key::typed::OpaqueKey};
use reifydb_store::coverage::cursor::{Cursor, ScannedStop};
use reifydb_value::util::cowvec::CowVec;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum MultiVersionScope {
	AsOf {
		read: CommitVersion,
	},
	Between {
		after: CommitVersion,
		read: CommitVersion,
	},
}

impl MultiVersionScope {
	#[inline]
	pub fn read(&self) -> CommitVersion {
		match self {
			Self::AsOf {
				read,
			}
			| Self::Between {
				read,
				..
			} => *read,
		}
	}

	#[inline]
	pub fn contains(&self, v: CommitVersion) -> bool {
		match self {
			Self::AsOf {
				read,
			} => v <= *read,
			Self::Between {
				after,
				read,
			} => v > *after && v <= *read,
		}
	}
}

pub type TierBatch = HashMap<EntryKind, Vec<(EncodedKey, Option<CowVec<u8>>)>>;

#[derive(Debug, Clone)]
pub enum VersionedGetResult {
	Value {
		value: CowVec<u8>,
		version: CommitVersion,
	},
	Tombstone,
	NotFound,
}

impl VersionedGetResult {
	pub fn value(self) -> Option<CowVec<u8>> {
		match self {
			VersionedGetResult::Value {
				value,
				..
			} => Some(value),
			VersionedGetResult::Tombstone | VersionedGetResult::NotFound => None,
		}
	}
}

#[derive(Debug, Clone)]
pub struct RawEntry<K = EncodedKey> {
	pub key: K,
	pub version: CommitVersion,
	pub value: Option<CowVec<u8>>,
}

#[derive(Debug, Clone)]
pub struct RangeBatch<K = EncodedKey> {
	pub entries: Vec<RawEntry<K>>,
	pub has_more: bool,
}

impl<K> RangeBatch<K> {
	pub fn empty() -> Self {
		Self {
			entries: Vec::new(),
			has_more: false,
		}
	}

	pub fn is_empty(&self) -> bool {
		self.entries.is_empty()
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RangeStop {
	Scanned,
	AbsentTable,
}

pub type RangeCursor = Cursor<RangeStop, OpaqueKey>;

impl ScannedStop for RangeStop {
	fn scanned(&self) -> bool {
		matches!(self, RangeStop::Scanned)
	}
}

#[derive(Debug, Default)]
pub struct HistoricalSweep {
	pub entries: Vec<(EncodedKey, CommitVersion)>,
	pub remaining: u64,
}