aboutsummaryrefslogtreecommitdiff
path: root/src/garage/repair/offline.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-08 17:37:16 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-08 17:37:16 +0200
commitf8a6fff2b7bb754fa315e1c00b0f6adea4586fa8 (patch)
tree8b55826e376717486280f89776d1073ef61b0aad /src/garage/repair/offline.rs
parent425fe56be8226615a366a7131e4f52ecac81371a (diff)
downloadgarage-f8a6fff2b7bb754fa315e1c00b0f6adea4586fa8.tar.gz
garage-f8a6fff2b7bb754fa315e1c00b0f6adea4586fa8.zip
First implementation of counter repair procedure
Diffstat (limited to 'src/garage/repair/offline.rs')
-rw-r--r--src/garage/repair/offline.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/garage/repair/offline.rs b/src/garage/repair/offline.rs
new file mode 100644
index 00000000..853bfdf3
--- /dev/null
+++ b/src/garage/repair/offline.rs
@@ -0,0 +1,52 @@
+use std::path::PathBuf;
+
+use tokio::sync::watch;
+
+use garage_util::background::*;
+use garage_util::config::*;
+use garage_util::error::*;
+
+use garage_model::garage::Garage;
+
+use crate::cli::structs::*;
+
+pub async fn offline_repair(config_file: PathBuf, opt: OfflineRepairOpt) -> Result<(), Error> {
+ if !opt.yes {
+ return Err(Error::Message(
+ "Please add the --yes flag to launch repair operation".into(),
+ ));
+ }
+
+ info!("Loading configuration...");
+ let config = read_config(config_file)?;
+
+ info!("Initializing background runner...");
+ let (done_tx, done_rx) = watch::channel(false);
+ let (background, await_background_done) = BackgroundRunner::new(16, done_rx);
+
+ info!("Initializing Garage main data store...");
+ let garage = Garage::new(config.clone(), background)?;
+
+ info!("Launching repair operation...");
+ match opt.what {
+ OfflineRepairWhat::K2VItemCounters => {
+ #[cfg(feature = "k2v")]
+ garage
+ .k2v
+ .counter_table
+ .offline_recount_all(&garage.k2v.item_table)?;
+ #[cfg(not(feature = "k2v"))]
+ error!("K2V not enabled in this build.");
+ }
+ }
+
+ info!("Repair operation finished, shutting down Garage internals...");
+ done_tx.send(true).unwrap();
+ drop(garage);
+
+ await_background_done.await?;
+
+ info!("Cleaning up...");
+
+ Ok(())
+}