RebelDBβ’ is a modern database engine implemented in Zig, focusing on efficient memory management, flexible data storage, and optimized encoding strategies. This document outlines the core architectural components and design decisions that shape the system.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RebelDB Engine β
βββββββββββββββββ¬ββββββββββββββββ¬βββββββββββββββ¬ββββββββββββββ€
β Page β Value β Memory β Encoding β
β Management β Storage β Management β System β
βββββββββββββββββΌββββββββββββββββΌβββββββββββββββΌββββββββββββββ€
β - ByteAligned β - Int β - HeapAlloc β - VarInt β
β - NibbleAlign β - Str β - PageAlloc β - LexOrder β
β - Static/Dyn β - Blob β - MemFile β - Efficient β
βββββββββββββββββ΄ββββββββββββββββ΄βββββββββββββββ΄ββββββββββββββ
-
Page Management
- Flexible page configurations
- Alignment strategies (Byte/Nibble)
- Capacity options (Static/Dynamic)
- Mutability control (Readonly/Mutable)
-
Value Storage
- Integer representation
- String handling
- Blob storage
- Block management
-
Memory Management
- Heap allocation
- Page allocation
- Memory file handling
- Resource cleanup
-
Encoding System
- Variable-length integers
- Lexicographical ordering
- Efficient space usage
- Performance optimization
ββββββββββββββββ¬ββββββββββββββββββββββ¬ββββββββββββββββββ
β Header β Values β Indices β
β β (Growing β) β (β Growing) β
ββββββββββββββββ΄ββββββββββββββββββββββ΄ββββββββββββββββββ
-
Header
- Page metadata
- Configuration information
- Capacity details
-
Values Section
- Grows forward from header
- Variable-length entries
- Aligned storage
-
Indices Section
- Grows backward from end
- Fixed-size entries
- Alignment-specific format
- Object (packed union)
pub const Object = packed union {
val: Value,
addr: packed struct { index: Index, page: PageId }
};
- Page Configuration
Page(IndexType, Capacity, Indices, Mutability)
- IndexType: Type used for indexing
- Capacity: Static or Dynamic
- Indices: ByteAligned or NibbleAligned
- Mutability: Readonly or Mutable
- Value Types
- Integers (variable-length encoded)
- Strings (length-prefixed)
- Blobs (binary data)
- Blocks (structured data)
Decision: Implement a page-based storage system with flexible configuration options.
Rationale:
- Efficient memory management
- Configurable alignment for different use cases
- Balance between flexibility and performance
- Support for various data types and sizes
Decision: Use a custom variable-length integer encoding scheme.
Rationale:
- Space efficiency for different value ranges
- Preserved lexicographical ordering
- Optimized performance for common cases
- Flexible storage requirements
Decision: Implement values growing forward and indices growing backward within pages.
Rationale:
- Efficient space utilization
- Reduced fragmentation
- Simple allocation strategy
- Clear separation of concerns
Decision: Use Zig's compile-time features for configuration.
Rationale:
- Type safety at compile time
- Flexible configuration options
- Performance optimization
- Clear interface boundaries
- Page reuse strategies
- Efficient allocation patterns
- Minimal fragmentation
- Resource cleanup
- Fast encoding/decoding
- Space efficiency
- Sort order preservation
- Cache-friendly access
- Alignment options for different needs
- Static vs Dynamic trade-offs
- Mutability control
- Index optimization
- Concurrent access patterns
- Advanced caching strategies
- Extended type support
- Enhanced error handling
- Page allocation strategies
- Encoding improvements
- Memory layout optimization
- Index structure refinements