mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-22 10:46:38 +00:00
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
This commit is contained in:
+14
-12
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user