Update getReadThrough() to return Key directly

And a few comment update
This commit is contained in:
Jay Zhuang 2023-04-18 13:12:46 -07:00
parent 8865be10dd
commit 8da1b875df
3 changed files with 16 additions and 13 deletions

View File

@ -103,7 +103,7 @@ ACTOR Future<Void> PipelinedReader::getNext_impl(PipelinedReader* self, Database
return Void();
}
begin = kvs.getReadThrough(begin.arena());
begin = kvs.getReadThrough();
break;
} catch (Error& e) {

View File

@ -750,11 +750,14 @@ struct GetRangeLimits {
struct RangeResultRef : VectorRef<KeyValueRef> {
constexpr static FileIdentifier file_identifier = 3985192;
bool more; // True if values remain in the *key* range requested (possibly beyond the
// limits requested), but not necessarily only if, for example, in getRangeStream(), 'more' is always set
// to true, as each stream fragment doesn't know if it's the last one. Instead, it uses
// `error_code_end_of_stream` for the end.
// False implies that no such values remain
// True if the range may have more keys in it (possibly beyond the specified limits).
// 'more' can be true even if there are no keys left in the range, e.g. if a shard boundary is hit, it may or may
// not have more keys left, but 'more' will be set to true in that case.
// Additionally, 'getRangeStream()' always sets 'more' to true and uses the 'end_of_stream' error to indicate that a
// range is exhausted.
// If 'more' is false, the range is guaranteed to have been exhausted.
bool more;
// Only present when 'more' is true, for example, when the read reaches the shard boundary, 'readThrough' is set to
// the shard boundary and the client's next range read should start with the 'readThrough'.
@ -765,18 +768,18 @@ struct RangeResultRef : VectorRef<KeyValueRef> {
// if reverse) of the range which was read.
Optional<KeyRef> readThrough;
// return the value represent the end (or beginning if reverse) of the range which was read
KeyRef getReadThrough(Arena& arena) const {
// return the value represent the end of the range which was read, it's only for non-reverse range read.
// TODO: add support for reverse range read
Key getReadThrough() const {
ASSERT(more);
if (readThrough.present()) {
return readThrough.get();
}
ASSERT(size() > 0);
// TODO: is this still right if reverse
return keyAfter(back().key, arena);
return keyAfter(back().key);
}
// Helper function to get the next range scan's BeginKeySelector, currently only for non-reverse range read.
// Helper function to get the next range scan's BeginKeySelector, it's only for non-reverse range read.
// TODO: add another function for reverse range read
KeySelectorRef nextBeginKeySelector() const {
ASSERT(more);

View File

@ -7617,7 +7617,7 @@ ACTOR Future<Void> fetchKeys(StorageServer* data, AddingShard* shard) {
data->byteSampleApplySet(*kvItr, invalidVersion);
}
if (this_block.more) {
blockBegin = this_block.getReadThrough(blockBegin.arena());
blockBegin = this_block.getReadThrough();
} else {
ASSERT(!this_block.readThrough.present());
blockBegin = rangeEnd;
@ -9717,7 +9717,7 @@ ACTOR Future<bool> createSstFileForCheckpointShardBytesSample(StorageServer* dat
numSampledKeys++;
}
if (readResult.more) {
readBegin = readResult.getReadThrough(readBegin.arena());
readBegin = readResult.getReadThrough();
ASSERT(readBegin <= readEnd);
} else {
break; // finish for current metaDataRangesIter