aboutsummaryrefslogtreecommitdiff
path: root/src/garage
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-02-23 21:27:28 +0100
committerAlex Auvolat <alex@adnab.me>2021-02-23 21:27:28 +0100
commit20e6e9fa2035ac12946bf0dcd5b8049090955bde (patch)
tree96c9a1a72833b16672b69e588c625248f9b40857 /src/garage
parentbf25c95fe2fda4ded2e3ca14499e3991e7243532 (diff)
downloadgarage-20e6e9fa2035ac12946bf0dcd5b8049090955bde.tar.gz
garage-20e6e9fa2035ac12946bf0dcd5b8049090955bde.zip
Update sled & try to debug deadlock (but its in sled...)
Diffstat (limited to 'src/garage')
-rw-r--r--src/garage/Cargo.toml3
-rw-r--r--src/garage/server.rs23
2 files changed, 24 insertions, 2 deletions
diff --git a/src/garage/Cargo.toml b/src/garage/Cargo.toml
index 254645c7..03bc472d 100644
--- a/src/garage/Cargo.toml
+++ b/src/garage/Cargo.toml
@@ -28,7 +28,8 @@ sha2 = "0.8"
log = "0.4"
pretty_env_logger = "0.4"
-sled = "0.31"
+sled = "0.34"
+old_sled = { package = "sled", version = "0.31" }
structopt = { version = "0.3", default-features = false }
toml = "0.5"
diff --git a/src/garage/server.rs b/src/garage/server.rs
index ec78c067..2e109f8b 100644
--- a/src/garage/server.rs
+++ b/src/garage/server.rs
@@ -40,7 +40,28 @@ pub async fn run_server(config_file: PathBuf) -> Result<(), Error> {
info!("Opening database...");
let mut db_path = config.metadata_dir.clone();
db_path.push("db");
- let db = sled::open(db_path).expect("Unable to open DB");
+ let db = match sled::open(&db_path) {
+ Ok(db) => db,
+ Err(e) => {
+ warn!("Old DB could not be openned ({}), attempting migration.", e);
+ let old = old_sled::open(&db_path).expect("Unable to open old DB for migration");
+ let mut new_path = config.metadata_dir.clone();
+ new_path.push("db2");
+ let new = sled::open(&new_path).expect("Unable to open new DB for migration");
+ new.import(old.export());
+ if old.checksum().expect("unable to compute old db checksum")
+ != new.checksum().expect("unable to compute new db checksum")
+ {
+ panic!("db checksums don't match after migration");
+ }
+ drop(new);
+ drop(old);
+ std::fs::remove_dir_all(&db_path).expect("Cannot remove old DB folder");
+ std::fs::rename(new_path, &db_path)
+ .expect("Cannot move new DB folder to correct place");
+ sled::open(db_path).expect("Unable to open new DB after migration")
+ }
+ };
info!("Initialize RPC server...");
let mut rpc_server = RpcServer::new(config.rpc_bind_addr.clone(), config.rpc_tls.clone());