MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / loadGraphsFromCatalog

Method loadGraphsFromCatalog

src/main/database_manager.cpp:289–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289void DatabaseManager::loadGraphsFromCatalog(storage::MemoryManager* memoryManager,
290 main::ClientContext* clientContext) {
291 auto mainCatalog = clientContext->getDatabase()->getCatalog();
292 // Use DUMMY_CHECKPOINT_TRANSACTION since we're loading from disk during startup
293 // and there's no active transaction yet
294 auto* transaction = &transaction::DUMMY_CHECKPOINT_TRANSACTION;
295 auto graphEntries = mainCatalog->getGraphEntries(transaction);
296
297 for (auto* graphEntry : graphEntries) {
298 auto graphName = graphEntry->getName();
299
300 // Check if graph is already loaded
301 auto upperCaseName = StringUtils::getUpper(graphName);
302 bool alreadyLoaded = false;
303 for (auto& graph : graphs) {
304 if (StringUtils::getUpper(graph->getCatalogName()) == upperCaseName) {
305 alreadyLoaded = true;
306 break;
307 }
308 }
309 if (alreadyLoaded) {
310 continue;
311 }
312
313 // Load the graph
314 auto catalog = std::make_unique<catalog::Catalog>();
315 catalog->setCatalogName(graphName);
316 auto dbPath = clientContext->getDatabasePath();
317 auto graphPath = DBConfig::isDBPathInMemory(dbPath) ?
318 ":" + graphName :
319 storage::StorageUtils::getGraphPath(dbPath, graphName);
320
321 // Check if graph file exists before trying to load
322 auto vfs = common::VirtualFileSystem::GetUnsafe(*clientContext);
323 if (!DBConfig::isDBPathInMemory(dbPath) && !vfs->fileOrPathExists(graphPath)) {
324 // Graph file doesn't exist, skip this graph
325 continue;
326 }
327
328 auto storageManager = std::make_unique<storage::StorageManager>(graphPath, false, false,
329 *memoryManager, false, clientContext->getDBConfig()->enableDefaultHashIndex, vfs);
330 storageManager->initDataFileHandle(vfs, clientContext);
331 if (storageManager->getDataFH()->getNumPages() > 0) {
332 storage::Checkpointer::readCheckpoint(clientContext, catalog.get(),
333 storageManager.get());
334 }
335 catalog->setStorageManager(std::move(storageManager));
336
337 graphs.push_back(std::move(catalog));
338
339 // Set first loaded graph as default if no default set
340 if (defaultGraph == "") {
341 defaultGraph = graphName;
342 }
343 }
344}
345
346bool DatabaseManager::hasGraph(const std::string& graphName) {

Callers 1

initMembersMethod · 0.80

Calls 12

getCatalogMethod · 0.80
getGraphEntriesMethod · 0.80
getDBConfigMethod · 0.80
initDataFileHandleMethod · 0.80
getDatabaseMethod · 0.45
getNameMethod · 0.45
getDatabasePathMethod · 0.45
fileOrPathExistsMethod · 0.45
getNumPagesMethod · 0.45
getDataFHMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected