diff options
author | Alex Auvolat <alex@adnab.me> | 2021-03-15 15:26:29 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-03-15 15:26:29 +0100 |
commit | 097c339d981dba0420af17d30d1221181d8bf1d7 (patch) | |
tree | 0d91832b3fb89b95bb4341ca580619f7081378a9 /src/model/block.rs | |
parent | bdcbdd1cd854bd8125458af0ac20b8682f810967 (diff) | |
download | garage-097c339d981dba0420af17d30d1221181d8bf1d7.tar.gz garage-097c339d981dba0420af17d30d1221181d8bf1d7.zip |
Fix race condition
Diffstat (limited to 'src/model/block.rs')
-rw-r--r-- | src/model/block.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/model/block.rs b/src/model/block.rs index 9426f683..5934f20c 100644 --- a/src/model/block.rs +++ b/src/model/block.rs @@ -28,6 +28,7 @@ use crate::garage::Garage; pub const INLINE_THRESHOLD: usize = 3072; const BLOCK_RW_TIMEOUT: Duration = Duration::from_secs(42); +const BLOCK_GC_TIMEOUT: Duration = Duration::from_secs(60); const NEED_BLOCK_QUERY_TIMEOUT: Duration = Duration::from_secs(5); const RESYNC_RETRY_TIMEOUT: Duration = Duration::from_secs(10); @@ -175,7 +176,10 @@ impl BlockManager { if data::blake2sum(&data[..]) != *hash { let _lock = self.data_dir_lock.lock().await; - warn!("Block {:?} is corrupted. Renaming to .corrupted and resyncing.", hash); + warn!( + "Block {:?} is corrupted. Renaming to .corrupted and resyncing.", + hash + ); let mut path2 = path.clone(); path2.set_extension(".corrupted"); fs::rename(path, path2).await?; @@ -225,7 +229,7 @@ impl BlockManager { pub fn block_decref(&self, hash: &Hash) -> Result<(), Error> { let new_rc = self.rc.merge(&hash, vec![0])?; if new_rc.map(|x| u64_from_bytes(&x[..]) == 0).unwrap_or(true) { - self.put_to_resync(&hash, Duration::from_secs(0))?; + self.put_to_resync(&hash, BLOCK_GC_TIMEOUT)?; } Ok(()) } @@ -470,7 +474,7 @@ impl BlockManager { }; let mut hash = [0u8; 32]; hash.copy_from_slice(&hash_bytes[..]); - self.put_to_resync(&hash.into(),Duration::from_secs(0))?; + self.put_to_resync(&hash.into(), Duration::from_secs(0))?; } if *must_exit.borrow() { |