aboutsummaryrefslogtreecommitdiff
path: root/src/block.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-11 23:53:32 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-11 23:53:32 +0200
commit9c931f5edacbaaab746ecf180fac2dd7062d0336 (patch)
treef29cfd82f573ac871408256a33e11f9153bae1da /src/block.rs
parent5dd59e437d5af84dfa2cf5dcc2c15807b971002d (diff)
downloadgarage-9c931f5edacbaaab746ecf180fac2dd7062d0336.tar.gz
garage-9c931f5edacbaaab746ecf180fac2dd7062d0336.zip
Keep network status & ring in a tokio::sync::watch
advantages - reads don't prevent preparing writes - can be followed from other parts of the system by cloning the receiver
Diffstat (limited to 'src/block.rs')
-rw-r--r--src/block.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/block.rs b/src/block.rs
index e78ddd78..e50dab38 100644
--- a/src/block.rs
+++ b/src/block.rs
@@ -1,15 +1,14 @@
use std::path::PathBuf;
+use futures_util::future::*;
use tokio::fs;
use tokio::prelude::*;
use tokio::sync::Mutex;
-use futures_util::future::*;
+use crate::background::*;
use crate::data::*;
use crate::error::Error;
use crate::proto::*;
-use crate::background::*;
-
pub struct BlockManager {
pub data_dir: PathBuf,
@@ -19,10 +18,11 @@ pub struct BlockManager {
impl BlockManager {
pub fn new(db: &sled::Db, data_dir: PathBuf) -> Self {
- let rc = db.open_tree("block_local_rc")
+ let rc = db
+ .open_tree("block_local_rc")
.expect("Unable to open block_local_rc tree");
rc.set_merge_operator(rc_merge);
- Self{
+ Self {
rc,
data_dir,
lock: Mutex::new(()),
@@ -81,18 +81,20 @@ impl BlockManager {
background.spawn(tokio::fs::remove_file(path).map_err(Into::into));
Ok(())
}
- Some(_) => Ok(())
+ Some(_) => Ok(()),
}
}
}
fn rc_merge(_key: &[u8], old: Option<&[u8]>, new: &[u8]) -> Option<Vec<u8>> {
- let old = old.map(|x| {
- assert!(x.len() == 8);
- let mut x8 = [0u8; 8];
- x8.copy_from_slice(x);
- u64::from_be_bytes(x8)
- }).unwrap_or(0);
+ let old = old
+ .map(|x| {
+ assert!(x.len() == 8);
+ let mut x8 = [0u8; 8];
+ x8.copy_from_slice(x);
+ u64::from_be_bytes(x8)
+ })
+ .unwrap_or(0);
assert!(new.len() == 1);
let new = match new[0] {
0 => {