changeset 91:1fa0d7075169

Don't panic when lock is poisoned
author Thomas Krause <krauseto@hu-berlin.de>
date Mon, 24 Feb 2020 11:15:30 +0100
parents 5301c7548da3
children b5d670aed9a0
files src/table_reader.rs
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/table_reader.rs	Mon Feb 17 19:36:18 2020 +0100
+++ b/src/table_reader.rs	Mon Feb 24 11:15:30 2020 +0100
@@ -15,8 +15,6 @@
 
 use integer_encoding::FixedIntWriter;
 
-const LOCK_POISONED: &str = "Lock poisoned";
-
 /// Reads the table footer.
 fn read_footer(f: &dyn RandomAccess, size: usize) -> Result<Footer> {
     let mut buf = vec![0; table_builder::FULL_FOOTER_LENGTH];
@@ -55,7 +53,7 @@
 
         let filter_block_reader = Table::read_filter_block(&metaindex_block, file.as_ref(), &opt)?;
         let cache_id = {
-            let mut block_cache = opt.block_cache.write().expect(LOCK_POISONED);
+            let mut block_cache = opt.block_cache.write()?;
             block_cache.new_cache_id()
         };
 
@@ -113,7 +111,7 @@
     /// cache.
     fn read_block(&self, location: &BlockHandle) -> Result<Block> {
         let cachekey = self.block_cache_handle(location.offset());
-        let mut block_cache = self.opt.block_cache.write().expect(LOCK_POISONED);
+        let mut block_cache = self.opt.block_cache.write()?;
         if let Some(block) = block_cache.get(&cachekey) {
             return Ok(block.clone());
         }
@@ -348,6 +346,8 @@
 
     use super::*;
 
+    const LOCK_POISONED: &str = "Lock poisoned";
+
     fn build_data() -> Vec<(&'static str, &'static str)> {
         vec![
             // block 1