MCPcopy Create free account
hub / github.com/bytedance/bolt / loadOne

Method loadOne

bolt/common/caching/tests/AsyncDataCacheTest.cpp:369–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367} // namespace
368
369void AsyncDataCacheTest::loadOne(
370 uint64_t fileNum,
371 Request& request,
372 bool injectError) {
373 // Pattern for loading one pin.
374 RawFileCacheKey key{fileNum, request.offset};
375 for (;;) {
376 folly::SemiFuture<bool> loadFuture(false);
377 auto pin = cache_->findOrCreate(key, request.size, &loadFuture);
378 if (pin.empty()) {
379 // The pin was exclusive on another thread. Wait until it is no longer so
380 // and retry.
381 auto& exec = folly::QueuedImmediateExecutor::instance();
382 std::move(loadFuture).via(&exec).wait();
383 continue;
384 }
385 auto* entry = pin.checkedEntry();
386 if (entry->isShared()) {
387 // Already in RAM. Check the data.
388 checkContents(*entry);
389 BOLT_CHECK(!injectError, "Testing error");
390 return;
391 }
392 // We have an uninitialized entry in exclusive mode. We fill it with data
393 // and set it to shared. If we release this pin while still in exclusive
394 // mode, the entry will be erased.
395 if (cache_->ssdCache() != nullptr) {
396 auto& ssdFile = cache_->ssdCache()->file(key.fileNum);
397 auto ssdPin = ssdFile.find(key);
398 if (!ssdPin.empty()) {
399 std::vector<CachePin> pins;
400 std::vector<SsdPin> ssdPins;
401 // pin is exclusive and not copiable, so std::move.
402 pins.push_back(std::move(pin));
403 ssdPins.push_back(std::move(ssdPin));
404 ssdFile.load(ssdPins, pins);
405 entry->setExclusiveToShared();
406 return;
407 }
408 }
409 // Load from storage.
410 initializeContents(
411 entry->key().offset + entry->key().fileNum.id(), entry->data());
412 entry->setExclusiveToShared();
413 return;
414 }
415}
416
417void AsyncDataCacheTest::loadBatch(
418 uint64_t fileNum,

Callers

nothing calls this directly

Calls 14

findOrCreateMethod · 0.80
waitMethod · 0.80
checkedEntryMethod · 0.80
isSharedMethod · 0.80
ssdCacheMethod · 0.80
setExclusiveToSharedMethod · 0.80
keyMethod · 0.80
emptyMethod · 0.45
fileMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected