aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-17 21:14:06 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-17 21:14:06 +0200
commitf62b54f1dffe9b76aab47d32ba7f47411d5a58af (patch)
treea92b57684d3512a5cb8ee80c7d3845419cad8d69 /src
parentace07da7c17d4eeec8b29b9eea2ae84c0d76088c (diff)
downloadgarage-f62b54f1dffe9b76aab47d32ba7f47411d5a58af.tar.gz
garage-f62b54f1dffe9b76aab47d32ba7f47411d5a58af.zip
Fix add to resync on incref
Diffstat (limited to 'src')
-rw-r--r--src/block.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/block.rs b/src/block.rs
index a0701b97..1e4c52dc 100644
--- a/src/block.rs
+++ b/src/block.rs
@@ -136,17 +136,18 @@ impl BlockManager {
}
pub fn block_incref(&self, hash: &Hash) -> Result<(), Error> {
- let new_rc = self.rc.merge(&hash, vec![1])?;
- if new_rc.map(|x| u64_from_bytes(&x[..]) == 0).unwrap_or(true) {
- self.put_to_resync(&hash, BLOCK_RW_TIMEOUT.as_millis() as u64)?;
+ let old_rc = self.rc.get(&hash)?;
+ self.rc.merge(&hash, vec![1])?;
+ if old_rc.map(|x| u64_from_bytes(&x[..]) == 0).unwrap_or(true) {
+ self.put_to_resync(&hash, 2 * BLOCK_RW_TIMEOUT.as_millis() as u64)?;
}
Ok(())
}
pub fn block_decref(&self, hash: &Hash) -> Result<(), Error> {
let new_rc = self.rc.merge(&hash, vec![0])?;
- if new_rc.is_none() {
- self.put_to_resync(&hash, 2 * BLOCK_RW_TIMEOUT.as_millis() as u64)?;
+ if new_rc.map(|x| u64_from_bytes(&x[..]) == 0).unwrap_or(true) {
+ self.put_to_resync(&hash, BLOCK_RW_TIMEOUT.as_millis() as u64)?;
}
Ok(())
}