MCPcopy Create free account
hub / github.com/facebook/CacheLib / allocateImpl

Method allocateImpl

cachelib/interface/components/FlashCacheComponent.cpp:331–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329}
330
331folly::coro::Task<Result<FlashCacheComponent::AllocData>>
332FlashCacheComponent::allocateImpl(const HashedKey& key, uint32_t valueSize) {
333 auto ret = co_await onWorkerThread(
334 [=, this]() {
335 return cache_->allocateForInsert(key, valueSize, /* canWait */ false);
336 },
337 [this](auto&& result) {
338 if (result.hasValue()) {
339 // Successfully allocated Region memory but coroutine was cancelled -
340 // close the descriptor to release refcount on the Region
341 auto& [desc, slotSize, _, _2] = result.value();
342 cache_->addHole(slotSize);
343 cache_->regionManager_.close(std::move(desc));
344 }
345 });
346 if (ret.hasValue()) {
347 co_return std::move(ret).value();
348 } else {
349 co_return makeError(Error::Code::ALLOCATE_FAILED,
350 "could not allocate space in a region");
351 }
352}
353
354template <typename CacheItemT>
355folly::coro::Task<Result<AllocatedHandle>> FlashCacheComponent::allocateGeneric(

Callers

nothing calls this directly

Calls 5

allocateForInsertMethod · 0.80
hasValueMethod · 0.80
addHoleMethod · 0.80
valueMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected