From e091497357d3e80e2eeb2e6f5107c9c0a82ec8cf Mon Sep 17 00:00:00 2001 From: Benjamin Winger Date: Tue, 20 Feb 2024 10:53:08 -0500 Subject: [PATCH] Fix reading strings from the hash index overflow file 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 --- src/storage/storage_structure/disk_overflow_file.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/storage/storage_structure/disk_overflow_file.cpp b/src/storage/storage_structure/disk_overflow_file.cpp index e5944d6d83..1c2f45ad1f 100644 --- a/src/storage/storage_structure/disk_overflow_file.cpp +++ b/src/storage/storage_structure/disk_overflow_file.cpp @@ -32,10 +32,13 @@ std::string DiskOverflowFile::readString(TransactionType trxType, const ku_strin auto numBytesToReadInPage = std::min( static_cast(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(frame) + cursor.elemPosInPage, - numBytesToReadInPage); + numBytesToReadInPage)); nextPage = *(page_idx_t*)(frame + END_OF_PAGE); }); remainingLength -= numBytesToReadInPage;