From aa7051b6e1693e97c5852c12eca669be71c50321 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Sat, 30 Mar 2024 11:51:53 +0530 Subject: [PATCH] storage: Fix 32-bit checksums (test) and update backup dir Also added changelog entry --- CHANGELOG.md | 4 ++++ server/help_text/help | 5 +++++ server/src/engine/storage/v2/mod.rs | 5 ++++- server/src/engine/storage/v2/raw/journal/raw/tests/mod.rs | 7 ++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 708eedfb..f02ab680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All changes in this project will be noted in this file. ## Version 0.8.1 +### Additions + +- Added support for manual repair with the `skyd repair` command + ### Fixes - Fixed migration from v1 SE (released with v0.8.0-beta) to v2 SE (released in v0.8.0) diff --git a/server/help_text/help b/server/help_text/help index e1a54e75..94b3c79f 100644 --- a/server/help_text/help +++ b/server/help_text/help @@ -13,6 +13,9 @@ Usage: skyd [OPTION]... skyd is the Skytable database server daemon and can be used to serve database requests. +Commands: + repair Check and repair any detected database storage errors + Flags: -h, --help Display this help menu and exit. -v, --version Display the version number and exit. @@ -36,5 +39,7 @@ Notes: - If no `--mode` is provided, we default to `dev` - You must provide `--auth-root-password` to set the default root password - To use TLS, you must provide both `--tlscert` and `--tlskey` + - When you run `repair`, your previous data is backed up in the `backups/` folder. + Restore if needed. For further assistance, refer to the official documentation here: https://docs.skytable.org \ No newline at end of file diff --git a/server/src/engine/storage/v2/mod.rs b/server/src/engine/storage/v2/mod.rs index 5978e4d0..6635cc8f 100644 --- a/server/src/engine/storage/v2/mod.rs +++ b/server/src/engine/storage/v2/mod.rs @@ -168,7 +168,10 @@ pub fn restore(cfg: &Configuration) -> RuntimeResult { pub fn repair() -> RuntimeResult<()> { // back up all files - let backup_dir = format!("backups/{}-before-repair-backup", util::time_now_string()); + let backup_dir = format!( + "backups/{}-before-recovery-process", + util::time_now_string() + ); context::set_dmsg("creating backup directory"); FileSystem::create_dir_all(&backup_dir)?; context::set_dmsg("backing up GNS"); diff --git a/server/src/engine/storage/v2/raw/journal/raw/tests/mod.rs b/server/src/engine/storage/v2/raw/journal/raw/tests/mod.rs index e21c755d..7afdcf2f 100644 --- a/server/src/engine/storage/v2/raw/journal/raw/tests/mod.rs +++ b/server/src/engine/storage/v2/raw/journal/raw/tests/mod.rs @@ -114,7 +114,7 @@ impl_db_event!( checksum.update(&length_bytes); checksum.update(&me_bytes); buf.extend(&(checksum.finish().to_le_bytes())); // checksum - buf.extend(&(me.0.len() as u64).to_le_bytes()); // length + buf.extend(&length_bytes); // length buf.extend(me.0.as_bytes()); // payload }, DbEventPop as 1, @@ -173,7 +173,8 @@ impl RawJournalAdapter for SimpleDBJournal { match meta { EventMeta::NewKey => { let checksum = u64::from_le_bytes(file.read_block()?); - let length = u64::from_le_bytes(file.read_block()?) as usize; + let length_u64 = u64::from_le_bytes(file.read_block()?); + let length = length_u64 as usize; let mut payload = Vec::::new(); if length > SANE_MEM_LIMIT_BYTES || payload.try_reserve_exact(length as usize).is_err() @@ -186,7 +187,7 @@ impl RawJournalAdapter for SimpleDBJournal { } file.tracked_read(&mut payload)?; let mut this_checksum = SCrc64::new(); - this_checksum.update(&length.to_le_bytes()); + this_checksum.update(&length_u64.to_le_bytes()); this_checksum.update(&payload); match String::from_utf8(payload) { Ok(k) if this_checksum.finish() == checksum => gs.data.borrow_mut().push(k),