Component Deep Dive: src/main.rs
main.rs is the assembly point for the storage engine components. While it does not yet run an event loop or expose an API, it demonstrates how caches, IO, metadata, and the page handler are instantiated and wired together.
Source Snapshot
src/main.rs
22 fn main() {
23 let compressed_page_cache = Arc::new(RwLock::new(PageCache::<PageCacheEntryCompressed>::new()));
24 let uncompressed_page_cache = Arc::new(RwLock::new(PageCache::<PageCacheEntryUncompressed>::new()));
25 let page_io = Arc::new(PageIO{});
26 let metadata_store = Arc::new(RwLock::new(TableMetaStore::new()));
27 let compressor = Arc::new(Compressor::new());
28 let page_handler = PageHandler{ … };
34 drop(uncompressed_page_cache);
35 drop(compressed_page_cache);
36 drop(page_io);
37 drop(compressor);
38 }
Wiring Diagram
┌──────────────────────────────────────────────────────────────────┐
│ main() │
│ │
│ compressed_page_cache = Arc<RwLock<PageCache<Compressed>>> │
│ uncompressed_page_cache = Arc<RwLock<PageCache<Uncompressed>>> │
│ page_io = Arc<PageIO> │
│ metadata_store = Arc<RwLock<TableMetaStore>> │
│ compressor = Arc<Compressor> │
│ │
│ page_handler = PageHandler { │
│ page_io: Arc::clone(&page_io), │
│ uncompressed_page_cache: Arc::clone(&uncompressed_page_cache),│
│ compressed_page_cache : Arc::clone(&compressed_page_cache), │
│ compressor: Arc::clone(&compressor), │
│ } │
└──────────────────────────────────────────────────────────────────┘
All core components are wrapped in Arc to support sharing across threads. Caches and metadata stores are further wrapped in RwLock to permit concurrent reads and serialized writes.
Intent
- Demonstrate Construction: Serves as a reference for other binaries/tests to instantiate the engine.
- Highlight Dependencies: Shows that
PageHandlerrequires both cache layers, the compressor, and the IO subsystem. - Resource Ownership: The explicit
dropcalls at the end are placeholders emphasizing cleanup; they are redundant in Rust but communicate ownership expectations for future expansion.
ASCII Topology
Arc<RwLock<PageCache<Uncompressed>>> Arc<RwLock<PageCache<Compressed>>>
╲ ╱
╲ ╱
▼ ▼
PageHandler
│
▼
Arc<PageIO>
│
▼
Disk Operations
Metadata (TableMetaStore) is constructed but not yet passed to any component; future wiring will inject it into request handlers alongside the PageHandler.
Future Steps
- Replace the placeholder
dropcalls with initialization of the operation layer (e.g., expose RPC endpoints or a CLI). - Seed the metadata store with initial pages (bootstrap) before handling writes.
- Integrate the scheduler and WAL once they mature.