| 17 | namespace storage { |
| 18 | |
| 19 | std::string OverflowFileHandle::readString(TransactionType trxType, const string_t& str) const { |
| 20 | if (string_t::isShortString(str.len)) { |
| 21 | return str.getAsShortString(); |
| 22 | } |
| 23 | PageCursor cursor; |
| 24 | TypeUtils::decodeOverflowPtr(str.overflowPtr, cursor.pageIdx, cursor.elemPosInPage); |
| 25 | std::string retVal; |
| 26 | retVal.reserve(str.len); |
| 27 | int32_t remainingLength = str.len; |
| 28 | while (remainingLength > 0) { |
| 29 | auto numBytesToReadInPage = |
| 30 | std::min(static_cast<uint32_t>(remainingLength), END_OF_PAGE - cursor.elemPosInPage); |
| 31 | auto startPosInSrc = retVal.size(); |
| 32 | read(trxType, cursor.pageIdx, [&](uint8_t* frame) { |
| 33 | // Replace rather than append, since optimistic read may call the function multiple |
| 34 | // times |
| 35 | retVal.replace(startPosInSrc, numBytesToReadInPage, |
| 36 | std::string_view(reinterpret_cast<const char*>(frame) + cursor.elemPosInPage, |
| 37 | numBytesToReadInPage)); |
| 38 | cursor.pageIdx = *reinterpret_cast<page_idx_t*>(frame + END_OF_PAGE); |
| 39 | }); |
| 40 | remainingLength -= numBytesToReadInPage; |
| 41 | // After the first page we always start reading from the beginning of the page. |
| 42 | cursor.elemPosInPage = 0; |
| 43 | } |
| 44 | return retVal; |
| 45 | } |
| 46 | |
| 47 | bool OverflowFileHandle::equals(TransactionType trxType, std::string_view keyToLookup, |
| 48 | const string_t& keyInEntry) const { |
no test coverage detected