Fixing a potential segfault in tag transactions (when the lru_cache was full, existing references would get dropped)

pmeunier
Jan 7, 2022, 6:45 PM
F2ZG4ZYOQLGYMBCB2EAZAI7XTYZGJ2ZIJW4IJ6JG6JYGWOVXD3LQC

Dependencies

  • [2] AETYXHGO Using an LruCache instead of a HashMap for loaded pages in a tag
  • [3] N3X5YP7P Adding tag/txn.rs, now that the parser allows it

Change contents

  • edit in libpijul/src/tag/txn.rs at line 3
    [3.98]
    [3.148]
    use std::collections::HashMap;
  • edit in libpijul/src/tag/txn.rs at line 5
    [3.170][2.0:60]()
    /// Size of the LRU cache.
    const CACHE_SIZE: usize = 1024;
  • replacement in libpijul/src/tag/txn.rs at line 32
    [3.788][2.61:141]()
    loaded: Mutex<lru_cache::LruCache<u64, Box<[u8; crate::tag::BLOCK_SIZE]>>>,
    [3.788]
    [3.856]
    loaded: Mutex<HashMap<u64, Box<[u8; crate::tag::BLOCK_SIZE]>>>,
  • replacement in libpijul/src/tag/txn.rs at line 71
    [2.588][2.588:658]()
    loaded: Mutex::new(lru_cache::LruCache::new(CACHE_SIZE)),
    [2.588]
    [3.1879]
    loaded: Mutex::new(HashMap::new()),
  • edit in libpijul/src/tag/txn.rs at line 78
    [3.2028]
    [3.2028]
    }
    /// Clear the cache, freeing memory.
    pub fn clear(&mut self) {
    // This function is only safe because it takes a mutable
    // borrow, and all references returned by the methods on
    // `TagTxn` return immutable borrows of `self`.
    self.loaded.lock().unwrap().clear()