| 141 | } |
| 142 | |
| 143 | void ShadowFile::flushAll(main::ClientContext& context) const { |
| 144 | // Write header page to file. |
| 145 | ShadowFileHeader header; |
| 146 | header.numShadowPages = shadowPageRecords.size(); |
| 147 | header.databaseID = StorageManager::Get(context)->getOrInitDatabaseID(context); |
| 148 | const auto headerBuffer = std::make_unique<uint8_t[]>(LBUG_PAGE_SIZE); |
| 149 | memcpy(headerBuffer.get(), &header, sizeof(ShadowFileHeader)); |
| 150 | DASSERT(shadowingFH && !shadowingFH->isInMemoryMode()); |
| 151 | shadowingFH->writePageToFile(headerBuffer.get(), 0); |
| 152 | // Flush shadow pages to file. |
| 153 | shadowingFH->flushAllDirtyPagesInFrames(); |
| 154 | // Append shadow page records to the end of the file. |
| 155 | const auto writer = std::make_shared<BufferedFileWriter>(*shadowingFH->getFileInfo()); |
| 156 | writer->setFileOffset(shadowingFH->getNumPages() * LBUG_PAGE_SIZE); |
| 157 | Serializer ser(writer); |
| 158 | DASSERT(shadowPageRecords.size() + 1 == shadowingFH->getNumPages()); |
| 159 | ser.serializeVector(shadowPageRecords); |
| 160 | writer->flush(); |
| 161 | // Sync the file to disk. |
| 162 | writer->sync(); |
| 163 | } |
| 164 | |
| 165 | void ShadowFile::clear(BufferManager& bm) { |
| 166 | DASSERT(shadowingFH); |