| 22 | } |
| 23 | |
| 24 | ColumnChunkMetadata CompressedFlushBuffer::operator()(std::span<const uint8_t> buffer, |
| 25 | FileHandle* dataFH, const PageRange& entry, const ColumnChunkMetadata& metadata) const { |
| 26 | auto valuesRemaining = metadata.numValues; |
| 27 | const uint8_t* bufferStart = buffer.data(); |
| 28 | const auto compressedBuffer = std::make_unique<uint8_t[]>(LBUG_PAGE_SIZE); |
| 29 | auto numPages = 0u; |
| 30 | const auto numValuesPerPage = metadata.compMeta.numValues(LBUG_PAGE_SIZE, dataType); |
| 31 | DASSERT(numValuesPerPage * entry.numPages >= metadata.numValues); |
| 32 | while (valuesRemaining > 0) { |
| 33 | const auto compressedSize = alg->compressNextPage(bufferStart, valuesRemaining, |
| 34 | compressedBuffer.get(), LBUG_PAGE_SIZE, metadata.compMeta); |
| 35 | // Avoid underflows (when data is compressed to nothing, numValuesPerPage may be |
| 36 | // UINT64_MAX) |
| 37 | if (numValuesPerPage > valuesRemaining) { |
| 38 | valuesRemaining = 0; |
| 39 | } else { |
| 40 | valuesRemaining -= numValuesPerPage; |
| 41 | } |
| 42 | if (compressedSize < LBUG_PAGE_SIZE) { |
| 43 | memset(compressedBuffer.get() + compressedSize, 0, LBUG_PAGE_SIZE - compressedSize); |
| 44 | } |
| 45 | DASSERT(numPages < entry.numPages); |
| 46 | DASSERT(dataFH->getNumPages() >= entry.startPageIdx + numPages); |
| 47 | dataFH->writePageToFile(compressedBuffer.get(), entry.startPageIdx + numPages); |
| 48 | numPages++; |
| 49 | } |
| 50 | // Make sure that the on-disk file is the right length |
| 51 | if (!dataFH->isInMemoryMode() && numPages < entry.numPages) { |
| 52 | memset(compressedBuffer.get(), 0, LBUG_PAGE_SIZE); |
| 53 | while (numPages < entry.numPages) { |
| 54 | dataFH->writePageToFile(compressedBuffer.get(), entry.startPageIdx + numPages); |
| 55 | ++numPages; |
| 56 | } |
| 57 | } |
| 58 | return ColumnChunkMetadata(entry.startPageIdx, entry.numPages, metadata.numValues, |
| 59 | metadata.compMeta); |
| 60 | } |
| 61 | |
| 62 | namespace { |
| 63 | template<std::floating_point T> |
no test coverage detected