MCPcopy Create free account
hub / github.com/baidu/tera / MakeRoomForWrite

Method MakeRoomForWrite

src/leveldb/persistent_cache/persistent_cache_impl.cc:280–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278}
279
280Status PersistentCacheImpl::MakeRoomForWrite(int64_t size) {
281 std::lock_guard<std::mutex> _(lock_);
282 assert(size_.Get() <= opt_.cache_size);
283
284 if (size + size_.Get() <= opt_.cache_size) {
285 // there is enough space to write
286 size_.Add(size);
287 return Status::OK();
288 }
289
290 // there is not enough space to fit the requested data
291 // we can clear some space by evicting cold data
292 while (size + size_.Get() > opt_.cache_size) {
293 std::unique_ptr<CacheFile> f(metadata_.Evict());
294 if (!f) {
295 // nothing is evictable
296 return Status::IOError("No space for writing persistent cache.");
297 }
298 assert(!f->refs_);
299 if (DeleteFileAndReleaseCache(f.get()).ok()) {
300 LEVELDB_LOG("Remove evicted cache file: %lu.rc.", f->cacheid());
301 }
302 }
303
304 size_.Add(size);
305 assert(size_.Get() <= opt_.cache_size);
306 return Status::OK();
307}
308
309bool PersistentCacheImpl::Insert(const Slice& key, CacheFile* file) {
310 std::lock_guard<std::mutex> _(lock_);

Callers 2

AppendMethod · 0.45
InitMethod · 0.45

Calls 7

cacheidMethod · 0.80
IOErrorFunction · 0.50
GetMethod · 0.45
AddMethod · 0.45
EvictMethod · 0.45
okMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected