pub mod backpressure;
pub mod footer;
pub mod header;
pub mod ingest;
pub mod models;
pub mod reader;
pub mod section;
pub mod section_columnar;
pub mod value_separator;
#[cfg(not(target_arch = "wasm32"))]
pub mod writer;
pub use backpressure::{CompactionDebtTracker, WriteThrottleConfig};
pub use footer::FileFooter;
pub use header::{FileFlags, FileHeader};
pub use ingest::{ExternalSectionIngest, KeyRange};
pub use models::{
bincode_config, ColumnDefinition, EphemeralDataGcConfig, IndexDefinition, IntentEntry,
IntentSection, IntentType, LockEntry, LockSection, LockType, Metadata, RaftEntryType,
RaftLogEntry, RaftLogSection, RangeMetadata, TableSchema, VectorIndexMetadata, VectorMetric,
};
#[cfg(not(target_arch = "wasm32"))]
pub use reader::AlopexFileReader;
#[cfg(target_arch = "wasm32")]
pub use reader::{AlopexFileReader, WasmReaderConfig};
#[cfg(target_arch = "wasm32")]
pub use reader::{BufferRangeLoader, RangeLoader};
pub use reader::{FileReader, FileSource, PrefetchFuture};
pub use section::{SectionEntry, SectionIndex, SectionType};
#[cfg(not(target_arch = "wasm32"))]
pub use section_columnar::ColumnarSectionWriter;
pub use section_columnar::{ColumnarSectionReader, SECTION_TYPE_COLUMNAR};
pub use value_separator::{LargeValuePointer, ValueRef, ValueSeparationConfig, ValueSeparator};
#[cfg(not(target_arch = "wasm32"))]
pub use writer::AlopexFileWriter;
use thiserror::Error;
pub const MAGIC: [u8; 4] = *b"ALPX";
pub const REVERSE_MAGIC: [u8; 4] = *b"XPLA";
pub const HEADER_SIZE: usize = 64;
pub const FOOTER_SIZE: usize = 64;
pub const SECTION_ENTRY_SIZE: usize = 40;
pub const VERSION_MAJOR: u16 = 0;
pub const VERSION_MINOR: u16 = 1;
pub const VERSION_PATCH: u16 = 0;
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct FileVersion {
pub major: u16,
pub minor: u16,
pub patch: u16,
}
impl FileVersion {
pub const fn new(major: u16, minor: u16, patch: u16) -> Self {
Self {
major,
minor,
patch,
}
}
pub const CURRENT: Self = Self::new(VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
}
#[repr(C)]
#[derive(Debug, Error, PartialEq, Eq)]
pub enum FormatError {
#[error("Invalid magic number: expected ALPX, found {found:?}")]
InvalidMagic {
found: [u8; 4],
},
#[error(
"Incompatible version: file version {file:?} is newer than reader version {reader:?}. Please upgrade Alopex DB."
)]
IncompatibleVersion {
file: FileVersion,
reader: FileVersion,
},
#[error("Section {section_id} is corrupted: expected checksum {expected:#x}, found {found:#x}. The section may be damaged.")]
CorruptedSection {
section_id: u32,
expected: u32,
found: u32,
},
#[error("File appears to be incomplete (missing or invalid footer). This may indicate a crash during write.")]
IncompleteWrite,
#[error("Key range [{start:?}, {end:?}) overlaps with existing section {section_id}")]
KeyRangeOverlap {
start: Vec<u8>,
end: Vec<u8>,
section_id: u32,
},
#[error("Compression algorithm {algorithm} is not supported in this build")]
UnsupportedCompression {
algorithm: u8,
},
#[error("Compression failed for algorithm {algorithm}")]
CompressionFailed {
algorithm: u8,
},
#[error("Decompression failed for algorithm {algorithm}")]
DecompressionFailed {
algorithm: u8,
},
#[error("Checksum algorithm {algorithm} is not supported in this build")]
UnsupportedChecksum {
algorithm: u8,
},
#[error("Invalid pointer: section_id={section_id}, offset={offset}, length={length}")]
InvalidPointer {
section_id: u32,
offset: u64,
length: u64,
},
#[error("Checksum mismatch: expected {expected:#x}, found {found:#x}")]
ChecksumMismatch {
expected: u64,
found: u64,
},
#[error("Invalid key range: start={start:?}, end={end:?}")]
InvalidKeyRange {
start: Vec<u8>,
end: Vec<u8>,
},
#[error("Invalid external section: {message}")]
IngestValidationFailed {
message: &'static str,
},
}