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

Function krmDecodeRanges

fdbclient/KeyRangeMap.actor.cpp:39–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39RangeResult krmDecodeRanges(KeyRef mapPrefix, KeyRange keys, RangeResult kv, bool align) {
40 ASSERT(!kv.more || kv.size() > 1);
41 KeyRange withPrefix =
42 KeyRangeRef(mapPrefix.toString() + keys.begin.toString(), mapPrefix.toString() + keys.end.toString());
43
44 RangeResult result;
45 result.arena().dependsOn(kv.arena());
46 result.arena().dependsOn(keys.arena());
47
48 // Always push a kv pair <= keys.begin.
49 KeyRef beginKey = keys.begin;
50 if (!align && !kv.empty() && kv.front().key.startsWith(mapPrefix) && kv.front().key < withPrefix.begin) {
51 beginKey = kv[0].key.removePrefix(mapPrefix);
52 }
53 ValueRef beginValue;
54 if (!kv.empty() && kv.front().key.startsWith(mapPrefix) && kv.front().key <= withPrefix.begin) {
55 beginValue = kv.front().value;
56 }
57 result.push_back(result.arena(), KeyValueRef(beginKey, beginValue));
58
59 for (int i = 0; i < kv.size(); i++) {
60 if (kv[i].key > withPrefix.begin && kv[i].key < withPrefix.end) {
61 KeyRef k = kv[i].key.removePrefix(mapPrefix);
62 result.push_back(result.arena(), KeyValueRef(k, kv[i].value));
63 } else if (kv[i].key >= withPrefix.end) {
64 kv.more = false;
65 // There should be at most 1 value past mapPrefix + keys.end.
66 ASSERT(i == kv.size() - 1);
67 break;
68 }
69 }
70
71 if (!kv.more) {
72 KeyRef endKey = keys.end;
73 if (!align && !kv.empty() && kv.back().key.startsWith(mapPrefix) && kv.back().key >= withPrefix.end) {
74 endKey = kv.back().key.removePrefix(mapPrefix);
75 }
76 ValueRef endValue;
77 if (!kv.empty()) {
78 // In the aligned case, carry the last value to be the end value.
79 if (align && kv.back().key.startsWith(mapPrefix) && kv.back().key > withPrefix.end) {
80 endValue = result.back().value;
81 } else {
82 endValue = kv.back().value;
83 }
84 }
85 result.push_back(result.arena(), KeyValueRef(endKey, endValue));
86 }
87 result.more = kv.more;
88
89 return result;
90}
91
92// Returns keys.begin, all transitional points in keys, and keys.end, and their values
93ACTOR Future<RangeResult> krmGetRanges(Transaction* tr, Key mapPrefix, KeyRange keys, int limit, int limitBytes) {

Calls 11

dependsOnMethod · 0.80
frontMethod · 0.80
KeyRangeRefClass · 0.50
KeyValueRefClass · 0.50
sizeMethod · 0.45
toStringMethod · 0.45
emptyMethod · 0.45
startsWithMethod · 0.45
removePrefixMethod · 0.45
push_backMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected