Create a new QueryCoordinator with specified session mode This method allows you to choose between Instance and Global session management. # Arguments `db_path` - Path to the database directory `mode` - Session management mode (Instance or Global) # Returns `Ok(Arc )` - Initialized coordinator ready for use `Err(String)` - Error message if initialization fails # Session Modes
(
db_path: impl AsRef<Path>,
mode: SessionMode,
)
| 156 | /// # Ok::<(), String>(()) |
| 157 | /// ``` |
| 158 | pub fn from_path_with_mode( |
| 159 | db_path: impl AsRef<Path>, |
| 160 | mode: SessionMode, |
| 161 | ) -> Result<Arc<Self>, String> { |
| 162 | let path = db_path.as_ref().to_path_buf(); |
| 163 | |
| 164 | // Initialize storage |
| 165 | let storage = Arc::new( |
| 166 | StorageManager::new(path.clone(), StorageMethod::DiskOnly, StorageType::Sled) |
| 167 | .map_err(|e| format!("Failed to initialize storage: {}", e))?, |
| 168 | ); |
| 169 | |
| 170 | // Initialize catalog manager |
| 171 | let catalog_manager = Arc::new(RwLock::new(CatalogManager::new(storage.clone()))); |
| 172 | |
| 173 | // Initialize transaction manager with database path |
| 174 | let transaction_manager = Arc::new( |
| 175 | TransactionManager::new(path.clone()) |
| 176 | .map_err(|e| format!("Failed to initialize transaction manager: {}", e))?, |
| 177 | ); |
| 178 | |
| 179 | // Initialize cache manager |
| 180 | let cache_config = crate::cache::CacheConfig::default(); |
| 181 | let cache_manager = |
| 182 | Some(Arc::new(CacheManager::new(cache_config).map_err(|e| { |
| 183 | format!("Failed to initialize cache manager: {}", e) |
| 184 | })?)); |
| 185 | |
| 186 | // Create session provider based on mode |
| 187 | let session_provider: Arc<dyn SessionProvider> = match mode { |
| 188 | SessionMode::Instance => { |
| 189 | // Instance mode: Each coordinator has isolated sessions |
| 190 | Arc::new(InstanceSessionProvider::new( |
| 191 | transaction_manager.clone(), |
| 192 | storage.clone(), |
| 193 | catalog_manager.clone(), |
| 194 | )) |
| 195 | } |
| 196 | SessionMode::Global => { |
| 197 | // Global mode: All coordinators share process-wide session pool |
| 198 | Arc::new(GlobalSessionProvider::new( |
| 199 | transaction_manager.clone(), |
| 200 | storage.clone(), |
| 201 | catalog_manager.clone(), |
| 202 | )) |
| 203 | } |
| 204 | }; |
| 205 | |
| 206 | // Create query executor |
| 207 | let executor = Arc::new( |
| 208 | QueryExecutor::new( |
| 209 | storage.clone(), |
| 210 | catalog_manager.clone(), |
| 211 | transaction_manager.clone(), |
| 212 | session_provider.clone(), |
| 213 | cache_manager, |
| 214 | ) |
| 215 | .map_err(|e| format!("Failed to initialize query executor: {}", e))?, |