fix snapshot bugs

This commit is contained in:
mpostma 2021-03-22 19:19:37 +01:00
parent d73fbdef2e
commit e9da191b7d
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
6 changed files with 36 additions and 21 deletions

View file

@ -2,9 +2,10 @@ use std::path::PathBuf;
use std::time::Duration;
use anyhow::bail;
use log::{error, info};
use tokio::fs;
use tokio::task::spawn_blocking;
use tokio::time::interval;
use tokio::time::sleep;
use crate::helpers::compression;
use super::index_actor::IndexActorHandle;
@ -38,11 +39,12 @@ impl<B> SnapshotService<B> {
}
pub async fn run(self) {
let mut interval = interval(self.snapshot_period);
loop {
interval.tick().await;
self.perform_snapshot().await.unwrap();
sleep(self.snapshot_period).await;
if let Err(e) = self.perform_snapshot().await {
error!("{}", e);
}
}
}
@ -57,6 +59,11 @@ impl<B> SnapshotService<B> {
fs::create_dir_all(&temp_snapshot_path).await?;
let uuids = self.uuid_resolver_handle.snapshot(temp_snapshot_path.clone()).await?;
if uuids.is_empty() {
return Ok(())
}
for uuid in uuids {
self.update_handle.snapshot(uuid, temp_snapshot_path.clone()).await?;
}
@ -69,6 +76,8 @@ impl<B> SnapshotService<B> {
fs::rename(temp_snapshot_file, &self.snapshot_path).await?;
info!("Created snapshot in {:?}.", self.snapshot_path);
Ok(())
}
}