mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-27 10:59:04 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7b7d56a02 | |||
| c73bb726d0 | |||
| eb84015075 |
@@ -1559,6 +1559,7 @@ impl HealStorageAPI for ECStoreHealStorage {
|
||||
|
||||
match self.ecstore.get_bucket_info(bucket, &Default::default()).await {
|
||||
Ok(info) => Ok(Some(info)),
|
||||
Err(StorageError::VolumeNotFound | StorageError::BucketNotFound(_)) => Ok(None),
|
||||
Err(e) => {
|
||||
error!(
|
||||
target: "rustfs::heal::storage",
|
||||
@@ -1577,13 +1578,8 @@ impl HealStorageAPI for ECStoreHealStorage {
|
||||
}
|
||||
|
||||
async fn mrf_bucket_incarnation_id(&self, bucket: &str) -> Result<Option<Uuid>> {
|
||||
match self.ecstore.bucket_incarnation_id(bucket).await {
|
||||
Ok(incarnation) => Ok(Some(incarnation)),
|
||||
// A missing bucket leaves the current identity unresolved. It is
|
||||
// not a retirement receipt for an unknown source generation.
|
||||
Err(StorageError::BucketNotFound(_)) => Ok(None),
|
||||
Err(error) => Err(Error::Storage(error)),
|
||||
}
|
||||
// A missing identity leaves the source generation unresolved for MRF replay.
|
||||
self.bucket_incarnation_id(bucket).await
|
||||
}
|
||||
|
||||
async fn replacement_bucket_incarnation(&self, bucket: &str) -> Result<Option<Uuid>> {
|
||||
@@ -1828,11 +1824,11 @@ impl HealStorageAPI for ECStoreHealStorage {
|
||||
}
|
||||
|
||||
async fn bucket_incarnation_id(&self, bucket: &str) -> Result<Option<Uuid>> {
|
||||
self.ecstore
|
||||
.bucket_incarnation_id(bucket)
|
||||
.await
|
||||
.map(Some)
|
||||
.map_err(Error::Storage)
|
||||
match self.ecstore.bucket_incarnation_id(bucket).await {
|
||||
Ok(id) => Ok(Some(id)),
|
||||
Err(StorageError::BucketNotFound(_)) => Ok(None),
|
||||
Err(error) => Err(Error::Storage(error)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn heal_object(
|
||||
|
||||
@@ -460,13 +460,14 @@ impl HealTask {
|
||||
progress.update_stage(2, 4);
|
||||
}
|
||||
|
||||
// Step 3: Heal bucket structure
|
||||
// Check control flags before each iteration to ensure timely cancellation.
|
||||
// Crash recovery queues a snapshot of names. Check the live generation under the
|
||||
// lifecycle fence before repairing directories that DeleteBucket may have removed.
|
||||
let crash_recovery = self.source == HealRequestSource::AutoHeal && self.heal_endpoints.is_empty();
|
||||
let bucket_heal_opts = HealOpts {
|
||||
recursive: false,
|
||||
dry_run: self.options.dry_run,
|
||||
remove: false,
|
||||
recreate: self.options.recreate_missing,
|
||||
recreate: self.options.recreate_missing && !crash_recovery,
|
||||
scan_mode: self.options.scan_mode,
|
||||
update_parity: self.options.update_parity,
|
||||
no_lock: self.options.no_lock,
|
||||
@@ -485,6 +486,11 @@ impl HealTask {
|
||||
}
|
||||
let expected = if let Some((_, manager, _)) = replacement_resume.as_ref() {
|
||||
Some(manager.replacement_bucket_incarnation(bucket).await?)
|
||||
} else if crash_recovery {
|
||||
let Some(incarnation) = self.await_with_control(self.storage.bucket_incarnation_id(bucket)).await? else {
|
||||
continue;
|
||||
};
|
||||
Some(incarnation)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -500,6 +506,7 @@ impl HealTask {
|
||||
Ok(result) => {
|
||||
self.record_result_item(result).await;
|
||||
}
|
||||
Err(Error::StaleBucketIncarnation { .. }) if crash_recovery => continue,
|
||||
Err(err) => {
|
||||
// Cancellation and timeout keep their classification; only
|
||||
// a storage failure may be reclassified as a namespace change.
|
||||
|
||||
@@ -35,8 +35,8 @@ use uuid::Uuid;
|
||||
|
||||
mod storage_api;
|
||||
use storage_api::integration::{
|
||||
BucketInfo, BucketOperations, DeleteBucketOptions, DiskAPI, DiskError, DiskStore, ObjectIO, ObjectOperations, ObjectOptions,
|
||||
ObjectToDelete, PutObjReader, ReadOptions, ShardIntegrityWriteMode,
|
||||
BucketInfo, BucketOperations, DeleteBucketOptions, DiskAPI, DiskError, DiskStore, EcstoreStorageError, ObjectIO,
|
||||
ObjectOperations, ObjectOptions, ObjectToDelete, PutObjReader, ReadOptions, ShardIntegrityWriteMode,
|
||||
};
|
||||
|
||||
const BUCKET: &str = "concurrent-delete";
|
||||
@@ -522,7 +522,7 @@ async fn delete_during_root(case: DeleteCase) {
|
||||
assert_version(&env, &control, false).await;
|
||||
}
|
||||
|
||||
fn run_delete_case(case: DeleteCase) {
|
||||
fn run_heal_scenario<F: Future<Output = ()>>(scenario: impl FnOnce() -> F + Send + 'static) {
|
||||
// Incarnation-bound repairs use a spawned owner; retain the server's stack
|
||||
// budget for the whole scenario, including its foreground DELETE. block_on
|
||||
// alone would poll that future on libtest's smaller calling-thread stack.
|
||||
@@ -537,13 +537,17 @@ fn run_delete_case(case: DeleteCase) {
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("concurrent delete runtime");
|
||||
runtime.block_on(delete_during_root(case));
|
||||
runtime.block_on(scenario());
|
||||
})
|
||||
.expect("concurrent delete scenario thread starts")
|
||||
.join()
|
||||
.expect("concurrent delete scenario must not panic");
|
||||
}
|
||||
|
||||
fn run_delete_case(case: DeleteCase) {
|
||||
run_heal_scenario(move || delete_during_root(case));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn admin_root_completes_after_old_version_delete() {
|
||||
@@ -577,25 +581,7 @@ fn admin_root_completes_after_unversioned_delete() {
|
||||
#[test]
|
||||
#[serial]
|
||||
fn admin_root_rejects_recreated_bucket_before_successor_repair() {
|
||||
// Incarnation-bound repairs use a spawned owner; retain the server's stack
|
||||
// budget for the whole scenario. block_on alone would poll that future on
|
||||
// libtest's smaller calling-thread stack.
|
||||
let stack_size = 8 * 1024 * 1024;
|
||||
std::thread::Builder::new()
|
||||
.name("heal-concurrent-delete".to_owned())
|
||||
.stack_size(stack_size)
|
||||
.spawn(move || {
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(4)
|
||||
.thread_stack_size(stack_size)
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("concurrent delete runtime");
|
||||
runtime.block_on(recreated_bucket_repair());
|
||||
})
|
||||
.expect("concurrent delete scenario thread starts")
|
||||
.join()
|
||||
.expect("concurrent delete scenario must not panic");
|
||||
run_heal_scenario(recreated_bucket_repair);
|
||||
}
|
||||
|
||||
async fn recreated_bucket_repair() {
|
||||
@@ -644,3 +630,62 @@ async fn recreated_bucket_repair() {
|
||||
assert_eq!(fresh.get_status().await, HealTaskStatus::Completed);
|
||||
assert_version(&env, &successor, false).await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn crash_recovery_skips_deleted_bucket_and_repairs_live_bucket() {
|
||||
run_heal_scenario(|| async {
|
||||
let directory = tempfile::tempdir().expect("crash recovery fixture");
|
||||
let env = TestECStoreEnv::builder().base_dir(directory.path()).build().await;
|
||||
let deleted = "a-deleted";
|
||||
let live = "z-live";
|
||||
env.make_bucket(deleted, false).await;
|
||||
env.make_bucket(live, false).await;
|
||||
let storage = Arc::new(ECStoreHealStorage::new(env.ecstore.clone()));
|
||||
let mut buckets: Vec<_> = storage.list_buckets().await.unwrap().into_iter().map(|b| b.name).collect();
|
||||
buckets.sort();
|
||||
assert_eq!(buckets, [deleted, live]);
|
||||
let mut request = HealRequest::new(
|
||||
HealType::ErasureSet {
|
||||
buckets,
|
||||
set_disk_id: "pool_0_set_0".to_owned(),
|
||||
},
|
||||
HealOptions::default(),
|
||||
HealPriority::Low,
|
||||
);
|
||||
request.source = HealRequestSource::AutoHeal;
|
||||
let task = HealTask::from_request(request, storage.clone());
|
||||
|
||||
env.ecstore
|
||||
.delete_bucket(deleted, &DeleteBucketOptions::default())
|
||||
.await
|
||||
.unwrap();
|
||||
let missing_live_volume = env.disk_paths[3].join(live);
|
||||
tokio::fs::remove_dir(&missing_live_volume).await.unwrap();
|
||||
let result = task.execute().await;
|
||||
|
||||
for disk in &env.disk_paths {
|
||||
assert!(!disk.join(deleted).exists(), "stale recovery recreated the deleted bucket on {disk:?}");
|
||||
}
|
||||
result.expect("recovery must still process the surviving bucket");
|
||||
assert!(missing_live_volume.is_dir(), "recovery must restore the live bucket's missing directory");
|
||||
let write = env
|
||||
.ecstore
|
||||
.put_object(deleted, "probe", &mut PutObjReader::from_vec(vec![1]), &ObjectOptions::default())
|
||||
.await;
|
||||
assert!(
|
||||
matches!(write, Err(EcstoreStorageError::BucketNotFound(_) | EcstoreStorageError::VolumeNotFound)),
|
||||
"{write:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
storage
|
||||
.list_buckets()
|
||||
.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|b| b.name)
|
||||
.collect::<Vec<_>>(),
|
||||
[live]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user