From 16167b07d55711a96e668a206d324a30b44df4a9 Mon Sep 17 00:00:00 2001 From: "A.J. Beamon" Date: Thu, 6 Feb 2020 13:27:04 -0800 Subject: [PATCH] Step 4 of fixing storage server range reads: remove another unneeded iteration case in the forward direction when we don't exhaust our limits in the disk read. This also hopefully makes the code a bit clearer. --- fdbserver/storageserver.actor.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fdbserver/storageserver.actor.cpp b/fdbserver/storageserver.actor.cpp index ae3db2452b..5a8d7d984f 100644 --- a/fdbserver/storageserver.actor.cpp +++ b/fdbserver/storageserver.actor.cpp @@ -1126,20 +1126,19 @@ ACTOR Future readRange( StorageServer* data, Version version, ASSERT( atStorageVersion.size() <= limit ); if (data->storageVersion() > version) throw transaction_too_old(); - bool more = atStorageVersion.size()!=0; - - // merge the sets in [vStart,vEnd) with the sets on disk, stopping at the last key from disk if we read anything + // merge the sets in [vStart,vEnd) with the sets on disk, stopping at the last key from disk if we were limited int prevSize = result.data.size(); - merge( result.arena, result.data, atStorageVersion, vStart, vEnd, vCount, limit, more, *pLimitBytes ); + merge( result.arena, result.data, atStorageVersion, vStart, vEnd, vCount, limit, atStorageVersion.more, *pLimitBytes ); limit -= result.data.size() - prevSize; for (auto i = result.data.begin() + prevSize; i != result.data.end(); i++) *pLimitBytes -= sizeof(KeyValueRef) + i->expectedSize(); - // Setup for the next iteration - if (more) { // if there might be more data on disk, begin reading right after the last key read - readBegin = readBeginTemp = keyAfter( result.data.end()[-1].key ); - ASSERT( limit<=0 || *pLimitBytes<=0 || result.data.end()[-1].key == atStorageVersion.end()[-1].key ); + // We may have reached our limits in the read from disk, but combining with the MVCC window could have + // given us back some room + if (atStorageVersion.more && limit > 0 && *pLimitBytes > 0) { + ASSERT(result.data.end()[-1].key == atStorageVersion.end()[-1].key); + readBegin = readBeginTemp = keyAfter(result.data.end()[-1].key); } else if (vEnd && vEnd->isClearTo()) { ASSERT(vEnd->getEndKey() > readBegin); readBegin = vEnd->getEndKey();