temporarily disable compression

serve
Avril 4 years ago
parent c5993b54e9
commit 7bc8f9837a
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -0,0 +1 @@
avril@eientei.869:1602150887

@ -7,6 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
compress-chain = ["lzzzz"]
[profile.release] [profile.release]
opt-level = 3 opt-level = 3
lto = "fat" lto = "fat"
@ -22,6 +25,6 @@ log = "0.4.11"
cfg-if = "1.0.0" cfg-if = "1.0.0"
futures = "0.3.6" futures = "0.3.6"
serde_cbor = "0.11.1" 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"]} serde = {version ="1.0", features=["derive"]}
toml = "0.5.6" toml = "0.5.6"

@ -22,6 +22,7 @@ use futures::{
OptionFuture, OptionFuture,
}, },
}; };
#[cfg(feature="compress-chain")]
use lzzzz::{ use lzzzz::{
lz4f::{ lz4f::{
self, self,
@ -52,10 +53,13 @@ async fn save_now_to(chain: &Chain<String>, to: impl AsRef<Path>) -> io::Result<
.open(to).await?; .open(to).await?;
let chain = serde_cbor::to_vec(chain).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; 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() 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?; file.write_all(&chain[..]).await?;
#[cfg(feature="compress-chain")]
file.flush().await?; file.flush().await?;
#[cfg(feature="compress-chain")]
file.shutdown().await?; file.shutdown().await?;
} }
file.flush().await?; file.flush().await?;
@ -64,9 +68,9 @@ async fn save_now_to(chain: &Chain<String>, to: impl AsRef<Path>) -> io::Result<
} }
/// Start the save loop for this chain /// 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(); let interval = state.config().save_interval();
while Arc::strong_count(state.when()) > 1 { while Arc::strong_count(state.when()) > 1 {
{ {
@ -78,11 +82,17 @@ pub async fn host(state: State)
info!("Saved chain to {:?}", to); 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() { if state.has_shutdown() {
break; break;
} }
OptionFuture::from(interval.map(|interval| time::delay_for(interval))).await;
state.when().notified().await;
} }
trace!("Saver exiting"); trace!("Saver exiting");
} }
@ -91,10 +101,12 @@ pub async fn host(state: State)
pub async fn load(from: impl AsRef<Path>) -> io::Result<Chain<String>> pub async fn load(from: impl AsRef<Path>) -> io::Result<Chain<String>>
{ {
debug!("Loading chain from {:?}", from.as_ref()); debug!("Loading chain from {:?}", from.as_ref());
let file = OpenOptions::new() #[allow(unused_mut)]
let mut file = OpenOptions::new()
.read(true) .read(true)
.open(from).await?; .open(from).await?;
let mut whole = Vec::new(); let mut whole = Vec::new();
#[cfg(feature="compress-chain")]
let mut file = AsyncReadDecompressor::new(file)?; let mut file = AsyncReadDecompressor::new(file)?;
tokio::io::copy(&mut file, &mut whole).await?; tokio::io::copy(&mut file, &mut whole).await?;
whole.flush().await?; whole.flush().await?;

Loading…
Cancel
Save