MCPcopy Create free account
hub / github.com/couchbase/forestdb / bcache_remove_file

Function bcache_remove_file

src/blockcache.cc:1313–1347  ·  view source on GitHub ↗

remove file from filename dictionary MUST sure that there is no dirty block belongs to this FILE (or memory leak occurs)

Source from the content-addressed store, hash-verified

1311// MUST sure that there is no dirty block belongs to this FILE
1312// (or memory leak occurs)
1313bool bcache_remove_file(struct filemgr *file)
1314{
1315 bool rv = false;
1316 struct fnamedic_item *fname_item;
1317
1318 // Before proceeding with deletion, garbage collect zombie files
1319 _garbage_collect_zombie_fnames();
1320 fname_item = file->bcache;
1321
1322 if (fname_item) {
1323 // acquire lock
1324 spin_lock(&bcache_lock);
1325 // file must be empty
1326 if (!_file_empty(fname_item)) {
1327 spin_unlock(&bcache_lock);
1328 DBG("Warning: failed to remove fnamedic_item instance for a file '%s' "
1329 "because the fnamedic_item instance is not empty!\n",
1330 file->filename);
1331 return rv;
1332 }
1333
1334 // remove from fname dictionary hash table
1335 hash_remove(&fnamedic, &fname_item->hash_elem);
1336 spin_unlock(&bcache_lock);
1337
1338 // We don't need to grab the file buffer cache's partition locks
1339 // at once because this function is only invoked when there are
1340 // no database handles that access the file.
1341 if (_fname_try_free(fname_item)) {
1342 _fname_free(fname_item); // no other callers accessing this file
1343 rv = true;
1344 } // else fnamedic_item is in use by _bcache_evict. Deletion delayed
1345 }
1346 return rv;
1347}
1348
1349// flush and synchronize all dirty blocks of the FILE
1350// dirty blocks will be changed to clean blocks (not discarded)

Callers 2

filemgr_free_funcFunction · 0.85

Calls 5

_file_emptyFunction · 0.85
hash_removeFunction · 0.85
_fname_try_freeFunction · 0.85
_fname_freeFunction · 0.85

Tested by

no test coverage detected