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

Method get

fdbclient/NativeAPI.actor.cpp:5198–5256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5196}
5197
5198Future<Optional<Value>> Transaction::get(const Key& key, Snapshot snapshot) {
5199 ++trState->cx->transactionLogicalReads;
5200 ++trState->cx->transactionGetValueRequests;
5201 // ASSERT (key < allKeys.end);
5202
5203 // There are no keys in the database with size greater than the max key size
5204 if (key.size() > getMaxReadKeySize(key)) {
5205 return Optional<Value>();
5206 }
5207
5208 auto ver = getReadVersion();
5209
5210 /* if (!systemKeys.contains(key))
5211 return Optional<Value>(Value()); */
5212
5213 if (!snapshot)
5214 tr.transaction.read_conflict_ranges.push_back(tr.arena, singleKeyRange(key, tr.arena));
5215
5216 UseTenant useTenant = UseTenant::True;
5217 if (key == metadataVersionKey) {
5218 // It is legal to read the metadata version key inside of a tenant.
5219 // This will return the global metadata version key.
5220 useTenant = UseTenant::False;
5221 ++trState->cx->transactionMetadataVersionReads;
5222 if (!ver.isReady() || metadataVersion.isSet()) {
5223 return metadataVersion.getFuture();
5224 } else {
5225 if (ver.isError()) {
5226 return ver.getError();
5227 }
5228 if (ver.get() == trState->cx->metadataVersionCache[trState->cx->mvCacheInsertLocation].first) {
5229 return trState->cx->metadataVersionCache[trState->cx->mvCacheInsertLocation].second;
5230 }
5231
5232 Version v = ver.get();
5233 int hi = trState->cx->mvCacheInsertLocation;
5234 int lo = (trState->cx->mvCacheInsertLocation + 1) % trState->cx->metadataVersionCache.size();
5235
5236 while (hi != lo) {
5237 int cu = hi > lo ? (hi + lo) / 2
5238 : ((hi + trState->cx->metadataVersionCache.size() + lo) / 2) %
5239 trState->cx->metadataVersionCache.size();
5240 if (v == trState->cx->metadataVersionCache[cu].first) {
5241 return trState->cx->metadataVersionCache[cu].second;
5242 }
5243 if (cu == lo) {
5244 break;
5245 }
5246 if (v < trState->cx->metadataVersionCache[cu].first) {
5247 hi = cu;
5248 } else {
5249 lo = (cu + 1) % trState->cx->metadataVersionCache.size();
5250 }
5251 }
5252 }
5253 }
5254
5255 return getValue(trState, key, ver, useTenant);

Callers

nothing calls this directly

Calls 10

getMaxReadKeySizeFunction · 0.85
singleKeyRangeFunction · 0.85
getMethod · 0.65
sizeMethod · 0.45
push_backMethod · 0.45
isReadyMethod · 0.45
isSetMethod · 0.45
getFutureMethod · 0.45
isErrorMethod · 0.45
getErrorMethod · 0.45

Tested by

no test coverage detected