diff --git a/src/rollback/cloud_rollback.rs b/src/rollback/cloud_rollback.rs index 0361003..c3c3f60 100644 --- a/src/rollback/cloud_rollback.rs +++ b/src/rollback/cloud_rollback.rs @@ -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") @@ -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 diff --git a/src/rollback/mod.rs b/src/rollback/mod.rs index 3ff484c..39452f0 100644 --- a/src/rollback/mod.rs +++ b/src/rollback/mod.rs @@ -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