MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / checkpointSegment

Method checkpointSegment

src/storage/table/list_column.cpp:345–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345std::vector<std::unique_ptr<ColumnChunkData>> ListColumn::checkpointSegment(
346 ColumnCheckpointState&& checkpointState, PageAllocator& pageAllocator,
347 bool canSplitSegment) const {
348 if (checkpointState.segmentCheckpointStates.empty()) {
349 return {};
350 }
351 auto& persistentListChunk = checkpointState.persistentData.cast<ListChunkData>();
352 const auto persistentDataChunk = persistentListChunk.getDataColumnChunk();
353
354 auto listDataChunkCheckpointStates = createListDataChunkCheckpointStates(persistentListChunk,
355 checkpointState.segmentCheckpointStates);
356
357 // First, check if we can checkpoint list data chunk in place.
358 SegmentState chunkState;
359 checkpointState.persistentData.initializeScanState(chunkState, this);
360 ColumnCheckpointState listDataCheckpointState(*persistentDataChunk,
361 std::move(listDataChunkCheckpointStates));
362 const auto listDataCanCheckpointInPlace = dataColumn->canCheckpointInPlace(
363 chunkState.childrenStates[ListChunkData::DATA_COLUMN_CHILD_READ_STATE_IDX],
364 listDataCheckpointState);
365 if (!listDataCanCheckpointInPlace) {
366 // If we cannot checkpoint list data chunk in place, we need to checkpoint the whole chunk
367 // out of place.
368 return checkpointColumnChunkOutOfPlace(chunkState, checkpointState, pageAllocator,
369 canSplitSegment);
370 }
371
372 const auto persistentListDataSize = persistentDataChunk->getNumValues();
373
374 // In place checkpoint for list data.
375 dataColumn->checkpointColumnChunkInPlace(
376 chunkState.childrenStates[ListChunkData::DATA_COLUMN_CHILD_READ_STATE_IDX],
377 listDataCheckpointState, pageAllocator);
378
379 // Checkpoint offset data.
380 std::vector<SegmentCheckpointState> offsetChunkCheckpointStates;
381
382 DASSERT(std::is_sorted(checkpointState.segmentCheckpointStates.begin(),
383 checkpointState.segmentCheckpointStates.end(),
384 [](const auto& a, const auto& b) { return a.startRowInData < b.startRowInData; }));
385 std::vector<std::unique_ptr<ColumnChunkData>> offsetsToWrite;
386 uint64_t totalAppendedListSize = 0;
387 for (const auto& segmentCheckpointState : checkpointState.segmentCheckpointStates) {
388 offsetsToWrite.push_back(
389 ColumnChunkFactory::createColumnChunkData(*mm, LogicalType::UINT64(), false,
390 segmentCheckpointState.numRows, ResidencyState::IN_MEMORY));
391 const auto& listChunk = segmentCheckpointState.chunkData.cast<ListChunkData>();
392 for (auto i = 0u; i < segmentCheckpointState.numRows; i++) {
393 // When checkpointing the data chunks we append each list in the checkpoint state to the
394 // end of the data This loop processes the lists in the same order, so the offsets match
395 // the ones used by the data chunk checkpoint
396 totalAppendedListSize +=
397 listChunk.getListSize(segmentCheckpointState.startRowInData + i);
398 offsetsToWrite.back()->setValue<offset_t>(
399 persistentListDataSize + totalAppendedListSize, i);
400 }
401 offsetChunkCheckpointStates.push_back(SegmentCheckpointState{*offsetsToWrite.back(), 0,
402 segmentCheckpointState.offsetInSegment, segmentCheckpointState.numRows});

Callers

nothing calls this directly

Calls 12

emptyMethod · 0.45
initializeScanStateMethod · 0.45
canCheckpointInPlaceMethod · 0.45
getNumValuesMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
getListSizeMethod · 0.45
syncNumValuesMethod · 0.45

Tested by

no test coverage detected