1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-27 21:01:50 +03:00

feat(brm): MCOL-5623 This patch changes the logic applied to save function for EM (#3076)

This commit is contained in:
Denis Khalikov
2023-12-27 09:48:29 +03:00
committed by GitHub
parent 7ca4b9da32
commit 318db3ef84
2 changed files with 28 additions and 8 deletions

View File

@ -1859,16 +1859,35 @@ void ExtentMap::save(const string& filename)
throw;
}
for (auto& lbidEMEntryPair : *fExtentMapRBTree)
// MCOL-5623 Prepare `ExtentMap` buffer before write.
const size_t emNumOfElements = fExtentMapRBTree->size();
auto emIterator = fExtentMapRBTree->begin();
size_t emIndex = 0;
while (emIndex < emNumOfElements)
{
EMEntry& emEntry = lbidEMEntryPair.second;
const uint32_t writeSize = sizeof(EMEntry);
char* writePos = reinterpret_cast<char*>(&emEntry);
uint32_t progress = 0;
const size_t emNumOfElementsInBatch = std::min(EM_SAVE_NUM_PER_BATCH, emNumOfElements - emIndex);
const size_t emSizeInBatch = emNumOfElementsInBatch * sizeof(EMEntry);
std::unique_ptr<char[]> extentMapBuffer(new char[emSizeInBatch]);
while (progress < writeSize)
const size_t endOfBatch = std::min(emIndex + EM_SAVE_NUM_PER_BATCH, emNumOfElements);
size_t offset = 0;
while (emIndex < endOfBatch)
{
auto err = out->write(writePos + progress, writeSize - progress);
EMEntry& emEntry = emIterator->second;
const size_t writeSize = sizeof(EMEntry);
char* source = reinterpret_cast<char*>(&emEntry);
std::memcpy(&extentMapBuffer[offset], source, writeSize);
offset += writeSize;
std::advance(emIterator, 1);
++emIndex;
}
// Double check.
idbassert(offset == emSizeInBatch);
offset = 0;
while (offset < emSizeInBatch)
{
auto err = out->write(&extentMapBuffer[offset], emSizeInBatch - offset);
if (err < 0)
{
releaseFreeList(READ);
@ -1876,7 +1895,7 @@ void ExtentMap::save(const string& filename)
releaseEMEntryTable(READ);
throw ios_base::failure("ExtentMap::save(): write failed. Check the error log.");
}
progress += err;
offset += err;
}
}