From 7bc8f9837aedfbc93ae917df04119cd3d0e4c57d Mon Sep 17 00:00:00 2001 From: Avril Date: Thu, 8 Oct 2020 15:36:39 +0100 Subject: [PATCH] temporarily disable compression --- .#Cargo.toml | 1 + Cargo.toml | 5 ++++- src/save.rs | 26 +++++++++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) create mode 120000 .#Cargo.toml diff --git a/.#Cargo.toml b/.#Cargo.toml new file mode 120000 index 0000000..1f74c0e --- /dev/null +++ b/.#Cargo.toml @@ -0,0 +1 @@ +avril@eientei.869:1602150887 \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index a16c3bd..2e28023 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +compress-chain = ["lzzzz"] + [profile.release] opt-level = 3 lto = "fat" @@ -22,6 +25,6 @@ log = "0.4.11" cfg-if = "1.0.0" futures = "0.3.6" serde_cbor = "0.11.1" -lzzzz = {version = "0.2", features=["tokio-io"]} +lzzzz = {version = "0.2", features=["tokio-io"], optional=true} serde = {version ="1.0", features=["derive"]} toml = "0.5.6" diff --git a/src/save.rs b/src/save.rs index ec09cf8..809cb5b 100644 --- a/src/save.rs +++ b/src/save.rs @@ -22,6 +22,7 @@ use futures::{ OptionFuture, }, }; +#[cfg(feature="compress-chain")] use lzzzz::{ lz4f::{ self, @@ -51,11 +52,14 @@ async fn save_now_to(chain: &Chain, to: impl AsRef) -> io::Result< .truncate(true) .open(to).await?; let chain = serde_cbor::to_vec(chain).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; - { + { + #[cfg(feature="compress-chain")] let mut file = AsyncWriteCompressor::new(&mut file, PreferencesBuilder::new() - .compression_level(lz4f::CLEVEL_HIGH).build())?; + .compression_level(lz4f::CLEVEL_HIGH).build())?; file.write_all(&chain[..]).await?; + #[cfg(feature="compress-chain")] file.flush().await?; + #[cfg(feature="compress-chain")] file.shutdown().await?; } file.flush().await?; @@ -64,9 +68,9 @@ async fn save_now_to(chain: &Chain, to: impl AsRef) -> io::Result< } /// Start the save loop for this chain -pub async fn host(state: State) +pub async fn host(mut state: State) { - let to = &state.config().file; + let to = state.config().file.to_owned(); let interval = state.config().save_interval(); while Arc::strong_count(state.when()) > 1 { { @@ -78,11 +82,17 @@ pub async fn host(state: State) info!("Saved chain to {:?}", to); } } + + tokio::select!{ + _ = OptionFuture::from(interval.map(|interval| time::delay_for(interval))) => {}, + _ = state.on_shutdown() => { + break; + } + } + state.when().notified().await; if state.has_shutdown() { break; } - OptionFuture::from(interval.map(|interval| time::delay_for(interval))).await; - state.when().notified().await; } trace!("Saver exiting"); } @@ -91,10 +101,12 @@ pub async fn host(state: State) pub async fn load(from: impl AsRef) -> io::Result> { debug!("Loading chain from {:?}", from.as_ref()); - let file = OpenOptions::new() + #[allow(unused_mut)] + let mut file = OpenOptions::new() .read(true) .open(from).await?; let mut whole = Vec::new(); + #[cfg(feature="compress-chain")] let mut file = AsyncReadDecompressor::new(file)?; tokio::io::copy(&mut file, &mut whole).await?; whole.flush().await?;