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
[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"

@ -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<String>, to: impl AsRef<Path>) -> 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<String>, to: impl AsRef<Path>) -> 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<Path>) -> io::Result<Chain<String>>
{
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?;

Loading…
Cancel
Save