| 367 | } // namespace |
| 368 | |
| 369 | void 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 | |
| 417 | void AsyncDataCacheTest::loadBatch( |
| 418 | uint64_t fileNum, |
nothing calls this directly
no test coverage detected