Background task manager #332
1 changed files with 19 additions and 8 deletions
|
@ -148,6 +148,7 @@ pub struct ScrubWorker {
|
||||||
struct ScrubWorkerPersisted {
|
struct ScrubWorkerPersisted {
|
||||||
tranquility: u32,
|
tranquility: u32,
|
||||||
time_last_complete_scrub: u64,
|
time_last_complete_scrub: u64,
|
||||||
|
corruptions_detected: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ScrubWorkerState {
|
enum ScrubWorkerState {
|
||||||
|
@ -179,6 +180,7 @@ impl ScrubWorker {
|
||||||
Err(_) => ScrubWorkerPersisted {
|
Err(_) => ScrubWorkerPersisted {
|
||||||
time_last_complete_scrub: 0,
|
time_last_complete_scrub: 0,
|
||||||
tranquility: 4,
|
tranquility: 4,
|
||||||
|
corruptions_detected: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
|
@ -253,20 +255,21 @@ impl Worker for ScrubWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn info(&self) -> Option<String> {
|
fn info(&self) -> Option<String> {
|
||||||
match &self.work {
|
let s = match &self.work {
|
||||||
ScrubWorkerState::Running(bsi) => Some(format!(
|
ScrubWorkerState::Running(bsi) => format!(
|
||||||
"{:.2}% done (tranquility = {})",
|
"{:.2}% done (tranquility = {})",
|
||||||
bsi.progress() * 100.,
|
bsi.progress() * 100.,
|
||||||
self.persisted.tranquility
|
self.persisted.tranquility
|
||||||
)),
|
),
|
||||||
ScrubWorkerState::Paused(_bsi, rt) => {
|
ScrubWorkerState::Paused(_bsi, rt) => {
|
||||||
Some(format!("Paused, resumes at {}", msec_to_rfc3339(*rt)))
|
format!("Paused, resumes at {}", msec_to_rfc3339(*rt))
|
||||||
}
|
}
|
||||||
ScrubWorkerState::Finished => Some(format!(
|
ScrubWorkerState::Finished => format!(
|
||||||
"Last completed scrub: {}",
|
"Last completed scrub: {}",
|
||||||
msec_to_rfc3339(self.persisted.time_last_complete_scrub)
|
msec_to_rfc3339(self.persisted.time_last_complete_scrub)
|
||||||
)),
|
),
|
||||||
}
|
};
|
||||||
|
Some(format!("{} ; corruptions detected: {}", s, self.persisted.corruptions_detected))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn work(
|
async fn work(
|
||||||
|
@ -283,7 +286,15 @@ impl Worker for ScrubWorker {
|
||||||
ScrubWorkerState::Running(bsi) => {
|
ScrubWorkerState::Running(bsi) => {
|
||||||
self.tranquilizer.reset();
|
self.tranquilizer.reset();
|
||||||
if let Some(hash) = bsi.next().await? {
|
if let Some(hash) = bsi.next().await? {
|
||||||
let _ = self.manager.read_block(&hash).await;
|
match self.manager.read_block(&hash).await {
|
||||||
|
Err(Error::CorruptData(_)) => {
|
||||||
|
error!("Found corrupt data block during scrub: {:?}", hash);
|
||||||
|
self.persisted.corruptions_detected += 1;
|
||||||
|
self.persister.save_async(&self.persisted).await?;
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
Ok(self
|
Ok(self
|
||||||
.tranquilizer
|
.tranquilizer
|
||||||
.tranquilize_worker(self.persisted.tranquility))
|
.tranquilize_worker(self.persisted.tranquility))
|
||||||
|
|
Loading…
Reference in a new issue