| 47 | } |
| 48 | |
| 49 | AttachedLbugDatabase::AttachedLbugDatabase(std::string dbPath, std::string dbName, |
| 50 | std::string dbType, ClientContext* clientContext) |
| 51 | : AttachedDatabase{std::move(dbName), std::move(dbType), nullptr /* catalog */} { |
| 52 | auto vfs = common::VirtualFileSystem::GetUnsafe(*clientContext); |
| 53 | if (DBConfig::isDBPathInMemory(dbPath)) { |
| 54 | throw common::RuntimeException("Cannot attach an in-memory Lbug database. Please give a " |
| 55 | "path to an on-disk Lbug database directory."); |
| 56 | } |
| 57 | auto path = vfs->expandPath(clientContext, dbPath); |
| 58 | // Note: S3 directory path may end with a '/'. |
| 59 | if (path.ends_with('/')) { |
| 60 | path = path.substr(0, path.size() - 1); |
| 61 | } |
| 62 | if (!vfs->fileOrPathExists(path, clientContext)) { |
| 63 | throw common::RuntimeException( |
| 64 | std::format("Cannot attach a remote Lbug database due to invalid path: {}.", path)); |
| 65 | } |
| 66 | catalog = std::make_unique<catalog::Catalog>(); |
| 67 | validateEmptyWAL(path, clientContext); |
| 68 | storageManager = std::make_unique<storage::StorageManager>(path, true /* isReadOnly */, |
| 69 | clientContext->getDBConfig()->enableChecksums, *storage::MemoryManager::Get(*clientContext), |
| 70 | clientContext->getDBConfig()->enableCompression, |
| 71 | clientContext->getDBConfig()->enableDefaultHashIndex, vfs); |
| 72 | transactionManager = |
| 73 | std::make_unique<transaction::TransactionManager>(storageManager->getWAL()); |
| 74 | |
| 75 | storageManager->initDataFileHandle(vfs, clientContext); |
| 76 | if (storageManager->getDataFH()->getNumPages() > 0) { |
| 77 | storage::Checkpointer::readCheckpoint(clientContext, catalog.get(), storageManager.get()); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | } // namespace main |
| 82 | } // namespace lbug |
nothing calls this directly
no test coverage detected