2
impl Drop for DBWrapper {
fn drop(&mut self) {
    if util::fs::exists(self.path.as_str()) {
        DB::destroy(&DBOptions::new(), self.path.as_str()).expect("destroy failed");
    } 
   
}

I use Drop trait to delete data after no one was using it. Usually it works well. But sometimes historical data has not been deleted.

After logging and checking, I found that the drop() has never been called. So I realized someone must still hold the DBWrapper, but it was hard to find out who is holding it because all the queries of the DBWrapper had already been finished.

So I want know is there any tool for this problem so I can use it to find out who is holding the object? Thanks in advance.

Tian Li
  • 66
  • 6
  • What database are you using? The answer to this is likely database specific. – Lie Ryan Mar 16 '21 at 03:08
  • @LieRyan It is a rocksdb wrapper. – Tian Li Mar 16 '21 at 03:24
  • So is the DbWrapper stored in a ref counted type (`Arc` / `Rc`) or ? – harmic Mar 16 '21 at 04:06
  • @harmic Yes, it is stored in Arc, then put in map. When the data is out-dated, the Arc will be removed from the map. Ideally, the DbWrapper will be dropped after queries finished. – Tian Li Mar 16 '21 at 04:35
  • We're going to need the specifics of your use-case, there is no general purpose mechanism for tracking drops... beyond noticing it not happening as you've done. Arcs don't track the referrers. If you're removing Arcs from a map and expecting their contents to be dropped you can check the `.strong_count() == 1`, but if it isn't 1 that still doesn't tell you the culprit, just that the contents won't be dropped yet. – kmdreko Mar 16 '21 at 05:46
  • This is a quite complex system. There is a long-running query engine, receives queries and executes query operators. The DbWrapper provides basic query APIs and returns iterators to query operators. My guess is the query engine / operator not releasing the iterator as it was expected to. But it is too hard to find this bug from all the codes of the query engine / operators. @kmdreko – Tian Li Mar 16 '21 at 06:05

0 Answers0