MCPcopy Create free account
hub / github.com/apple/foundationdb / readRangeInDb

Function readRangeInDb

fdbserver/KeyValueStoreShardedRocksDB.actor.cpp:516–580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

514};
515
516int readRangeInDb(PhysicalShard* shard, const KeyRangeRef& range, int rowLimit, int byteLimit, RangeResult* result) {
517 if (rowLimit == 0 || byteLimit == 0) {
518 return 0;
519 }
520
521 int accumulatedRows = 0;
522 int accumulatedBytes = 0;
523 // TODO: Pass read timeout.
524 const int readRangeTimeout = SERVER_KNOBS->ROCKSDB_READ_RANGE_TIMEOUT;
525 rocksdb::Status s;
526 auto options = getReadOptions();
527 // TODO: define single shard read timeout.
528 const uint64_t deadlineMircos = shard->db->GetEnv()->NowMicros() + readRangeTimeout * 1000000;
529 options.deadline = std::chrono::microseconds(deadlineMircos / 1000000);
530
531 // When using a prefix extractor, ensure that keys are returned in order even if they cross
532 // a prefix boundary.
533 options.auto_prefix_mode = (SERVER_KNOBS->ROCKSDB_PREFIX_LEN > 0);
534 if (rowLimit >= 0) {
535 ReadIterator readIter = shard->readIterPool->getIterator();
536 auto cursor = readIter.iter;
537 cursor->Seek(toSlice(range.begin));
538 while (cursor->Valid() && toStringRef(cursor->key()) < range.end) {
539 KeyValueRef kv(toStringRef(cursor->key()), toStringRef(cursor->value()));
540 ++accumulatedRows;
541 accumulatedBytes += sizeof(KeyValueRef) + kv.expectedSize();
542 result->push_back_deep(result->arena(), kv);
543 // Calling `cursor->Next()` is potentially expensive, so short-circut here just in case.
544 if (result->size() >= rowLimit || accumulatedBytes >= byteLimit) {
545 break;
546 }
547 cursor->Next();
548 }
549 s = cursor->status();
550 shard->readIterPool->returnIterator(readIter);
551 } else {
552 ReadIterator readIter = shard->readIterPool->getIterator();
553 auto cursor = readIter.iter;
554 cursor->SeekForPrev(toSlice(range.end));
555 if (cursor->Valid() && toStringRef(cursor->key()) == range.end) {
556 cursor->Prev();
557 }
558 while (cursor->Valid() && toStringRef(cursor->key()) >= range.begin) {
559 KeyValueRef kv(toStringRef(cursor->key()), toStringRef(cursor->value()));
560 ++accumulatedRows;
561 accumulatedBytes += sizeof(KeyValueRef) + kv.expectedSize();
562 result->push_back_deep(result->arena(), kv);
563 // Calling `cursor->Prev()` is potentially expensive, so short-circut here just in case.
564 if (result->size() >= -rowLimit || accumulatedBytes >= byteLimit) {
565 break;
566 }
567 cursor->Prev();
568 }
569 s = cursor->status();
570 shard->readIterPool->returnIterator(readIter);
571 }
572
573 if (!s.ok()) {

Callers 2

initMethod · 0.85
actionMethod · 0.85

Calls 13

NextMethod · 0.80
okMethod · 0.80
getReadOptionsFunction · 0.70
toSliceFunction · 0.70
toStringRefFunction · 0.70
logRocksDBErrorFunction · 0.70
getIteratorMethod · 0.45
keyMethod · 0.45
valueMethod · 0.45
expectedSizeMethod · 0.45
push_back_deepMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected