| 150 | } |
| 151 | |
| 152 | void RelBatchInsert::appendNodeGroup(const RelGroupCatalogEntry& relGroupEntry, MemoryManager& mm, |
| 153 | transaction::Transaction* transaction, CSRNodeGroup& nodeGroup, |
| 154 | const RelBatchInsertInfo& relInfo, const RelBatchInsertLocalState& localState) { |
| 155 | const auto nodeGroupIdx = localState.nodeGroupIdx; |
| 156 | const auto startNodeOffset = storage::StorageUtils::getStartOffsetOfNodeGroup(nodeGroupIdx); |
| 157 | auto executionState = impl->initExecutionState(*partitionerSharedState, relInfo, nodeGroupIdx); |
| 158 | // Calculate num of source nodes in this node group. |
| 159 | // This will be used to set the num of values of the node group. |
| 160 | const auto numNodes = std::min(StorageConfig::NODE_GROUP_SIZE, |
| 161 | partitionerSharedState->getNumNodes(relInfo.partitioningIdx) - startNodeOffset); |
| 162 | // We optimistically flush new node group directly to disk in gapped CSR format. |
| 163 | // There is no benefit of leaving gaps for existing node groups, which is kept in memory. |
| 164 | const auto leaveGaps = nodeGroup.isEmpty(); |
| 165 | populateCSRHeader(relGroupEntry, *executionState, startNodeOffset, relInfo, localState, |
| 166 | numNodes, leaveGaps); |
| 167 | const auto& csrHeader = |
| 168 | dynamic_cast_checked<InMemChunkedCSRNodeGroup&>(*localState.chunkedGroup).getCSRHeader(); |
| 169 | impl->writeToTable(*executionState, csrHeader, localState, *sharedState, relInfo); |
| 170 | // Reset num of rows in the chunked group to fill gaps at the end of the node group. |
| 171 | const auto maxSize = csrHeader.getEndCSROffset(numNodes - 1); |
| 172 | auto numGapsAtEnd = maxSize - localState.chunkedGroup->getNumRows(); |
| 173 | DASSERT(localState.chunkedGroup->getCapacity() >= maxSize); |
| 174 | while (numGapsAtEnd > 0) { |
| 175 | const auto numGapsToFill = std::min(numGapsAtEnd, DEFAULT_VECTOR_CAPACITY); |
| 176 | localState.dummyAllNullDataChunk->state->getSelVectorUnsafe().setSelSize(numGapsToFill); |
| 177 | std::vector<ValueVector*> dummyVectors; |
| 178 | for (auto i = 0u; i < relInfo.columnTypes.size(); i++) { |
| 179 | dummyVectors.push_back(&localState.dummyAllNullDataChunk->getValueVectorMutable(i)); |
| 180 | } |
| 181 | const auto numGapsFilled = localState.chunkedGroup->append(dummyVectors, 0, numGapsToFill); |
| 182 | DASSERT(numGapsFilled == numGapsToFill); |
| 183 | numGapsAtEnd -= numGapsFilled; |
| 184 | } |
| 185 | DASSERT(localState.chunkedGroup->getNumRows() == maxSize); |
| 186 | |
| 187 | auto* relTable = sharedState->table->ptrCast<RelTable>(); |
| 188 | |
| 189 | InMemChunkedCSRNodeGroup sliceToWriteToDisk{ |
| 190 | dynamic_cast_checked<InMemChunkedCSRNodeGroup&>(*localState.chunkedGroup), |
| 191 | relInfo.outputDataColumns}; |
| 192 | appendNewChunkedGroup(mm, transaction, relInfo.insertColumnIDs, sliceToWriteToDisk, *relTable, |
| 193 | nodeGroup, relInfo.direction, *localState.optimisticAllocator); |
| 194 | dynamic_cast_checked<InMemChunkedCSRNodeGroup&>(*localState.chunkedGroup) |
| 195 | .mergeChunkedCSRGroup(sliceToWriteToDisk, relInfo.outputDataColumns); |
| 196 | |
| 197 | localState.chunkedGroup->resetToEmpty(); |
| 198 | } |
| 199 | |
| 200 | void RelBatchInsertImpl::finalizeStartCSROffsets(RelBatchInsertExecutionState&, |
| 201 | storage::InMemChunkedCSRHeader& csrHeader, const RelBatchInsertInfo&) { |
nothing calls this directly
no test coverage detected