| 54 | StorageManager::~StorageManager() = default; |
| 55 | |
| 56 | void StorageManager::initDataFileHandle(VirtualFileSystem* vfs, main::ClientContext* context) { |
| 57 | if (inMemory) { |
| 58 | dataFH = memoryManager.getBufferManager()->getFileHandle(databasePath, |
| 59 | FileHandle::O_PERSISTENT_FILE_IN_MEM, vfs, context); |
| 60 | } else { |
| 61 | auto flag = readOnly ? FileHandle::O_PERSISTENT_FILE_READ_ONLY : |
| 62 | FileHandle::O_PERSISTENT_FILE_CREATE_NOT_EXISTS; |
| 63 | if (!readOnly) { |
| 64 | flag |= FileHandle::O_LOCKED_PERSISTENT_FILE; |
| 65 | } |
| 66 | dataFH = memoryManager.getBufferManager()->getFileHandle(databasePath, flag, vfs, context); |
| 67 | if (dataFH->getNumPages() == 0) { |
| 68 | if (!readOnly) { |
| 69 | // Reserve the first page for the database header. |
| 70 | dataFH->getPageManager()->allocatePage(); |
| 71 | // Write a dummy database header page. |
| 72 | const auto* initialHeader = getOrInitDatabaseHeader(*context); |
| 73 | auto headerWriter = |
| 74 | std::make_shared<InMemFileWriter>(*MemoryManager::Get(*context)); |
| 75 | Serializer headerSerializer(headerWriter); |
| 76 | initialHeader->serialize(headerSerializer); |
| 77 | dataFH->getFileInfo()->writeFile(headerWriter->getPage(0).data(), LBUG_PAGE_SIZE, |
| 78 | StorageConstants::DB_HEADER_PAGE_IDX); |
| 79 | dataFH->getFileInfo()->syncFile(); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void StorageManager::closeFileHandle() { |
| 86 | if (dataFH != nullptr) { |
no test coverage detected