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

Function resolveKeySelectorFromCache

fdbclient/ReadYourWrites.actor.cpp:400–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398
399 template <class Iter>
400 static void resolveKeySelectorFromCache(KeySelector& key,
401 Iter& it,
402 KeyRef const& maxKey,
403 bool* readToBegin,
404 bool* readThroughEnd,
405 int* actualOffset) {
406 // If the key indicated by `key` can be determined without reading unknown data from the snapshot, then
407 // it.kv().key is the resolved key. If the indicated key is determined to be "off the beginning or end" of the
408 // database, it points to the first or last segment in the DB,
409 // and key is an equivalent key selector relative to the beginning or end of the database.
410 // Otherwise it points to an unknown segment, and key is an equivalent key selector whose base key is in or
411 // adjoining the segment.
412
413 key.removeOrEqual(key.arena());
414
415 bool alreadyExhausted = key.offset == 1;
416
417 it.skip(key.getKey()); // TODO: or precondition?
418
419 if (key.offset <= 0 && it.beginKey() == key.getKey() && key.getKey() != allKeys.begin)
420 --it;
421
422 ExtStringRef keykey = key.getKey();
423 bool keyNeedsCopy = false;
424
425 // Invariant: it.beginKey() <= keykey && keykey <= it.endKey() && (key.isBackward() ? it.beginKey() != keykey :
426 // it.endKey() != keykey) Maintaining this invariant, we transform the key selector toward firstGreaterOrEqual
427 // form until we reach an unknown range or the result
428 while (key.offset > 1 && !it.is_unreadable() && !it.is_unknown_range() && it.endKey() < maxKey) {
429 if (it.is_kv())
430 --key.offset;
431 ++it;
432 keykey = it.beginKey();
433 keyNeedsCopy = true;
434 }
435 while (key.offset < 1 && !it.is_unreadable() && !it.is_unknown_range() && it.beginKey() != allKeys.begin) {
436 if (it.is_kv()) {
437 ++key.offset;
438 if (key.offset == 1) {
439 keykey = it.beginKey();
440 keyNeedsCopy = true;
441 break;
442 }
443 }
444 --it;
445 keykey = it.endKey();
446 keyNeedsCopy = true;
447 }
448
449 if (!alreadyExhausted) {
450 *actualOffset = key.offset;
451 }
452
453 if (!it.is_unreadable() && !it.is_unknown_range() && key.offset < 1) {
454 *readToBegin = true;
455 key.setKey(allKeys.begin);
456 key.offset = 1;
457 return;

Calls 11

removeOrEqualMethod · 0.80
toArenaMethod · 0.80
getKeyMethod · 0.65
skipMethod · 0.45
beginKeyMethod · 0.45
is_unreadableMethod · 0.45
is_unknown_rangeMethod · 0.45
endKeyMethod · 0.45
is_kvMethod · 0.45
setKeyMethod · 0.45
is_empty_rangeMethod · 0.45

Tested by

no test coverage detected