Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/rollback/cloud_rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::util::{get_real_key, storage_db, StorageDb};
use std::path::Path;

pub async fn cloud_storage_rollback(config_path: &Path, rollback_backup_height: u64) {
pub async fn cloud_storage_rollback(config_path: &Path, rollback_cloud_height: u64) {
let storage_db = storage_db(config_path).await;
let StorageDb::Opendal(storager) = &storage_db else {
panic!("cloud rollback not support rocksdb")
Expand All @@ -33,22 +33,23 @@ pub async fn cloud_storage_rollback(config_path: &Path, rollback_backup_height:
if let Ok(remote_height_bytes) = remote.read(&get_real_key(0, &1u64.to_be_bytes())).await {
let mut buf: [u8; 8] = [0; 8];
buf.clone_from_slice(&remote_height_bytes.to_vec()[..8]);
let current_backup_height = u64::from_be_bytes(buf);
println!("current_backup_height: {current_backup_height}");
let current_cloud_height = u64::from_be_bytes(buf);
println!("current_cloud_height: {current_cloud_height}");
println!("rollback_cloud_height: {rollback_cloud_height}");
// value of key(0, 1) include backup height(u64) and backup index(u32)
// when rollback_backup_height == current_backup_height, maybe the backup of current height hasn't completed
if rollback_backup_height >= current_backup_height {
panic!(
"rollback backup_height({}) >= current backup_height({})",
rollback_backup_height, current_backup_height
// when rollback_cloud_height == current_cloud_height, maybe the backup of current height hasn't completed
if rollback_cloud_height >= current_cloud_height {
println!(
"rollback_cloud_height({}) >= current_cloud_height({}), ignore rollback",
rollback_cloud_height, current_cloud_height
);
return;
}
println!("rollback_backup_height: {rollback_backup_height}");

// value of key(0, 1) include backup height(u64) and backup index(u32)
// rollback to the height, we should set key(0, 1) as (height + 1, 0)
let mut buf = Vec::new();
let height = rollback_backup_height + 1;
let height = rollback_cloud_height + 1;
buf.extend_from_slice(&height.to_be_bytes());
buf.extend_from_slice(&[0u8; 4]);
remote
Expand Down
5 changes: 3 additions & 2 deletions src/rollback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ pub async fn rollback(config_path: &Path, height: u64, clean_consensus_data: boo
println!("current height: {}", current_height);
println!("rollback height: {}", height);
if height >= current_height {
panic!(
"rollback height({}) >= current height({})",
println!(
"rollback height({}) >= current height({}), ignore rollback",
height, current_height
);
return;
}

// rollback storage
Expand Down
Loading