redb_extras/partition/
mod.rs

1//! Generic partitioned storage module.
2//!
3//! This module provides reusable infrastructure for sharded and segmented storage
4//! that is independent of value types. It can be used with any value type that
5//! implements the necessary traits.
6
7use std::fmt;
8
9/// Errors specific to the partition layer.
10/// These are concerned with generic storage mechanics and are independent of value types.
11#[derive(Debug)]
12pub enum PartitionError {
13    /// Invalid shard count configuration
14    InvalidShardCount(u16),
15
16    /// Invalid segment size configuration
17    InvalidSegmentSize(usize),
18
19    /// Meta table operations failed
20    MetaOperationFailed(String),
21
22    /// Segment scan failed
23    SegmentScanFailed(String),
24
25    /// Database operation failed
26    DatabaseError(String),
27
28    /// Encoding operation failed
29    EncodingError(String),
30}
31
32impl std::error::Error for PartitionError {
33    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
34        None
35    }
36}
37
38impl fmt::Display for PartitionError {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            PartitionError::InvalidShardCount(count) => {
42                write!(
43                    f,
44                    "Invalid shard count {}: must be between 1 and 65535",
45                    count
46                )
47            }
48            PartitionError::InvalidSegmentSize(size) => {
49                write!(f, "Invalid segment size {}: must be greater than 0", size)
50            }
51            PartitionError::MetaOperationFailed(msg) => {
52                write!(f, "Meta table operation failed: {}", msg)
53            }
54            PartitionError::SegmentScanFailed(msg) => {
55                write!(f, "Segment scan failed: {}", msg)
56            }
57            PartitionError::DatabaseError(msg) => {
58                write!(f, "Database error: {}", msg)
59            }
60            PartitionError::EncodingError(ref err) => {
61                write!(f, "Encoding error: {}", err)
62            }
63        }
64    }
65}
66
67pub mod config;
68pub mod scan;
69pub mod shard;
70pub mod table;
71pub mod traits;
72
73// Re-export main types for public API
74pub use config::PartitionConfig;
75pub use scan::{enumerate_segments, find_head_segment, SegmentInfo, SegmentIterator};
76pub use table::{PartitionedRead, PartitionedTable, PartitionedWrite};