MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / operator()

Method operator()

src/storage/table/compression_flush_buffer.cpp:24–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24ColumnChunkMetadata 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
62namespace {
63template<std::floating_point T>

Callers 1

flushALPExceptionsFunction · 0.45

Calls 8

writePageToFileMethod · 0.80
isInMemoryModeMethod · 0.80
ColumnChunkMetadataClass · 0.50
dataMethod · 0.45
numValuesMethod · 0.45
compressNextPageMethod · 0.45
getMethod · 0.45
getNumPagesMethod · 0.45

Tested by

no test coverage detected