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

Method allocate

cachelib/interface/components/RAMCacheComponent.cpp:236–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236folly::coro::Task<Result<AllocatedHandle>> RAMCacheComponent::allocate(
237 Key key, uint32_t size, uint32_t creationTime, uint32_t ttlSecs) {
238 stats_->allocate_.throughput_.calls_.inc();
239 // Latency is not tracked here; CacheAllocator already tracks it via
240 // stats_.allocateLatency_. See getStats().
241
242 try {
243 auto implHandle = cache_->allocate(
244 defaultPool_, key, size + sizeof(RAMCacheItem), ttlSecs, creationTime);
245 if (!implHandle) {
246 stats_->allocate_.throughput_.errors_.inc();
247 co_return makeError(
248 Error::Code::NO_SPACE,
249 fmt::format("could not find room in cache for {}", key));
250 }
251 stats_->allocate_.throughput_.successes_.inc();
252 co_return tryCreateHandle<AllocatedHandle>(
253 *this, *RAMCacheItem::init(implHandle.get()));
254 } catch (const exception::RefcountOverflow& ro) {
255 XLOG(DFATAL) << "ERROR: refcount overflow in allocate which shouldn't be "
256 "possible (nobody else can access the item)";
257 stats_->allocate_.throughput_.errors_.inc();
258 co_return makeError(Error::Code::INC_REF_FAILED, ro.what());
259 } catch (const std::exception& e) {
260 stats_->allocate_.throughput_.errors_.inc();
261 co_return makeError(Error::Code::INVALID_ARGUMENTS, e.what());
262 }
263}
264
265folly::coro::Task<UnitResult> RAMCacheComponent::insert(
266 AllocatedHandle&& handle) {

Callers 4

CO_TEST_FFunction · 0.45
CO_TYPED_TESTFunction · 0.45
CO_TYPED_TESTFunction · 0.45
TYPED_TESTFunction · 0.45

Calls 3

whatMethod · 0.80
incMethod · 0.45
getMethod · 0.45

Tested by 4

CO_TEST_FFunction · 0.36
CO_TYPED_TESTFunction · 0.36
CO_TYPED_TESTFunction · 0.36
TYPED_TESTFunction · 0.36