Skip to content

Commit

Permalink
Fix reading strings from the hash index overflow file
Browse files Browse the repository at this point in the history
When there is multi-threaded contention, data was being appended to the
result multiple times because of how optimisticRead behaves.
Replacing the relevant portion of the string instead of appending makes
sure that the result is correct and overwrites the null data from
previous runs when the optimisticRead finally manages a successful read.

Fixes #2916
  • Loading branch information
benjaminwinger committed Feb 20, 2024
1 parent 1416881 commit e091497
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/storage/storage_structure/disk_overflow_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ std::string DiskOverflowFile::readString(TransactionType trxType, const ku_strin
auto numBytesToReadInPage = std::min(
static_cast<uint32_t>(remainingLength), END_OF_PAGE - cursor.elemPosInPage);
page_idx_t nextPage;
auto startPosInSrc = retVal.size();
bufferManager->optimisticRead(*fileHandleToPin, pageIdxToPin, [&](uint8_t* frame) {
retVal +=
// Replace rather than append, since optimistic read may call the function multiple
// times
retVal.replace(startPosInSrc, numBytesToReadInPage,
std::string_view(reinterpret_cast<const char*>(frame) + cursor.elemPosInPage,
numBytesToReadInPage);
numBytesToReadInPage));
nextPage = *(page_idx_t*)(frame + END_OF_PAGE);
});
remainingLength -= numBytesToReadInPage;
Expand Down

0 comments on commit e091497

Please sign in to comment.