pub mod arena;
pub mod bitmap_index;
pub mod btree_index;
pub mod engine;
pub mod file_lock;
pub mod hash_index;
pub mod multi_column_index;
pub mod persistence;
pub mod registry;
pub mod scanner;
pub mod snapshot;
pub mod streaming_result;
pub mod table;
pub mod timestamp;
pub mod transaction;
pub mod version_store;
pub mod wal_manager;
pub mod zonemap;
pub use bitmap_index::BitmapIndex;
pub use btree_index::{
intersect_multiple_sorted_ids, intersect_sorted_ids, union_multiple_sorted_ids,
union_sorted_ids, BTreeIndex,
};
pub use engine::{CleanupHandle, MVCCEngine};
pub use hash_index::HashIndex;
pub use multi_column_index::{CompositeKey, MultiColumnIndex};
pub use persistence::{
deserialize_row_version, deserialize_value, serialize_row_version, serialize_value,
IndexMetadata, PersistenceManager, PersistenceMeta, DEFAULT_KEEP_SNAPSHOTS,
DEFAULT_SNAPSHOT_INTERVAL,
};
pub use registry::{TransactionRegistry, INVALID_TRANSACTION_ID, RECOVERY_TRANSACTION_ID};
pub use scanner::{EmptyScanner, MVCCScanner, RangeScanner, SingleRowScanner};
pub use snapshot::{DiskVersionStore, SnapshotReader, SnapshotWriter};
pub use streaming_result::{AggregationScanner, StreamingResult, VisibleRowInfo};
pub use table::MVCCTable;
pub use timestamp::get_fast_timestamp;
pub use transaction::{MvccTransaction, TransactionEngineOperations, TransactionState};
pub use version_store::{
RowVersion, TransactionVersionStore, VersionStore, VisibilityChecker, WriteSetEntry,
};
pub use wal_manager::{
CheckpointMetadata, WALEntry, WALManager, WALOperationType, DEFAULT_WAL_BUFFER_SIZE,
DEFAULT_WAL_FLUSH_TRIGGER, DEFAULT_WAL_MAX_SIZE,
};
pub use zonemap::{
ColumnZoneMap, PruneStats, TableZoneMap, ZoneMapBuilder, ZoneMapEntry, DEFAULT_SEGMENT_SIZE,
};
use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum MvccError {
#[error("no transaction provided")]
NoTransaction,
#[error("primary key violation: duplicate key")]
PrimaryKeyViolation,
#[error("invalid or unknown table")]
InvalidTable,
#[error("invalid row data")]
InvalidRow,
#[error("transaction already closed")]
TransactionClosed,
#[error("engine is not open")]
EngineNotOpen,
#[error("engine is already open")]
EngineAlreadyOpen,
#[error("transaction registry is not accepting new transactions")]
NotAcceptingTransactions,
#[error("version not found for row {0}")]
VersionNotFound(i64),
#[error("write conflict detected")]
WriteConflict,
#[error("serialization error: {0}")]
Serialization(String),
#[error("persistence error: {0}")]
Persistence(String),
}
impl From<MvccError> for crate::core::Error {
fn from(err: MvccError) -> Self {
match err {
MvccError::NoTransaction => crate::core::Error::internal("no transaction provided"),
MvccError::PrimaryKeyViolation => crate::core::Error::primary_key_constraint(0),
MvccError::InvalidTable => crate::core::Error::TableNotFound,
MvccError::InvalidRow => crate::core::Error::internal("invalid row data"),
MvccError::TransactionClosed => {
crate::core::Error::internal("transaction already closed")
}
MvccError::EngineNotOpen => crate::core::Error::EngineNotOpen,
MvccError::EngineAlreadyOpen => crate::core::Error::EngineAlreadyOpen,
MvccError::NotAcceptingTransactions => {
crate::core::Error::internal("not accepting new transactions")
}
MvccError::VersionNotFound(row_id) => {
crate::core::Error::internal(format!("version not found for row {}", row_id))
}
MvccError::WriteConflict => crate::core::Error::internal("write conflict detected"),
MvccError::Serialization(msg) => {
crate::core::Error::internal(format!("serialization error: {}", msg))
}
MvccError::Persistence(msg) => {
crate::core::Error::internal(format!("persistence error: {}", msg))
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mvcc_error_display() {
assert_eq!(
MvccError::NoTransaction.to_string(),
"no transaction provided"
);
assert_eq!(
MvccError::PrimaryKeyViolation.to_string(),
"primary key violation: duplicate key"
);
assert_eq!(
MvccError::TransactionClosed.to_string(),
"transaction already closed"
);
}
#[test]
fn test_mvcc_error_to_core_error() {
let err: crate::core::Error = MvccError::InvalidTable.into();
assert!(matches!(err, crate::core::Error::TableNotFound));
let err: crate::core::Error = MvccError::PrimaryKeyViolation.into();
assert!(matches!(
err,
crate::core::Error::PrimaryKeyConstraint { .. }
));
}
}