aboutsummaryrefslogtreecommitdiff
path: root/src/block/repair.rs
diff options
context:
space:
mode:
authorJonathan Davies <jpds@protonmail.com>2023-03-09 15:34:14 +0000
committerJonathan Davies <jpds@protonmail.com>2023-03-09 16:38:36 +0000
commitb70cc0a94087bfd70931ff6741299823b48ad291 (patch)
tree32685c1cc8581b234c0f1221be5b4ca439898c5c /src/block/repair.rs
parent9e061d5a70f35db7c62c79089567ef4dc226e413 (diff)
downloadgarage-b70cc0a94087bfd70931ff6741299823b48ad291.tar.gz
garage-b70cc0a94087bfd70931ff6741299823b48ad291.zip
block/repair.rs: Added migration for ScrubWorkerPersisted's time_next_run_scrub.
Fixes: #520.
Diffstat (limited to 'src/block/repair.rs')
-rw-r--r--src/block/repair.rs54
1 files changed, 44 insertions, 10 deletions
diff --git a/src/block/repair.rs b/src/block/repair.rs
index 10d46291..006cc866 100644
--- a/src/block/repair.rs
+++ b/src/block/repair.rs
@@ -5,7 +5,6 @@ use std::time::Duration;
use async_trait::async_trait;
use rand::Rng;
-use serde::{Deserialize, Serialize};
use tokio::fs;
use tokio::select;
use tokio::sync::mpsc;
@@ -162,6 +161,50 @@ impl Worker for RepairWorker {
// and whose parameter (esp. speed) can be controlled at runtime.
// ---- ---- ----
+mod v081 {
+ use serde::{Deserialize, Serialize};
+
+ #[derive(Serialize, Deserialize)]
+ pub struct ScrubWorkerPersisted {
+ pub tranquility: u32,
+ pub(crate) time_last_complete_scrub: u64,
+ pub(crate) corruptions_detected: u64,
+ }
+
+ impl garage_util::migrate::InitialFormat for ScrubWorkerPersisted {}
+}
+
+mod v082 {
+ use serde::{Deserialize, Serialize};
+
+ use super::v081;
+
+ #[derive(Serialize, Deserialize)]
+ pub struct ScrubWorkerPersisted {
+ pub tranquility: u32,
+ pub(crate) time_last_complete_scrub: u64,
+ pub(crate) time_next_run_scrub: u64,
+ pub(crate) corruptions_detected: u64,
+ }
+
+ impl garage_util::migrate::Migrate for ScrubWorkerPersisted {
+ type Previous = v081::ScrubWorkerPersisted;
+
+ fn migrate(old: v081::ScrubWorkerPersisted) -> ScrubWorkerPersisted {
+ use crate::repair::randomize_next_scrub_run_time;
+
+ ScrubWorkerPersisted {
+ tranquility: old.tranquility,
+ time_last_complete_scrub: old.time_last_complete_scrub,
+ time_next_run_scrub: randomize_next_scrub_run_time(),
+ corruptions_detected: old.corruptions_detected,
+ }
+ }
+ }
+}
+
+pub use v082::*;
+
pub struct ScrubWorker {
manager: Arc<BlockManager>,
rx_cmd: mpsc::Receiver<ScrubWorkerCommand>,
@@ -172,14 +215,6 @@ pub struct ScrubWorker {
persister: PersisterShared<ScrubWorkerPersisted>,
}
-#[derive(Serialize, Deserialize)]
-pub struct ScrubWorkerPersisted {
- pub tranquility: u32,
- pub(crate) time_last_complete_scrub: u64,
- pub(crate) time_next_run_scrub: u64,
- pub(crate) corruptions_detected: u64,
-}
-
fn randomize_next_scrub_run_time() -> u64 {
// Take SCRUB_INTERVAL and mix in a random interval of 10 days to attempt to
// balance scrub load across different cluster nodes.
@@ -194,7 +229,6 @@ fn randomize_next_scrub_run_time() -> u64 {
next_run_timestamp
}
-impl garage_util::migrate::InitialFormat for ScrubWorkerPersisted {}
impl Default for ScrubWorkerPersisted {
fn default() -> Self {
ScrubWorkerPersisted {