mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-03 01:23:53 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c2b54aeb5 | |||
| 0de223d8e6 | |||
| 351bd12031 | |||
| a2381c8421 | |||
| 5eee702e88 |
@@ -1700,6 +1700,15 @@ mod tests {
|
||||
);
|
||||
|
||||
let mut cluster = RustFSTestClusterEnvironment::with_topology(topology.cluster_topology()).await?;
|
||||
let bucket = "heal-restart-during-rebuild";
|
||||
let mrf_fallback_scope = if !background_enabled {
|
||||
let path = PathBuf::from(&cluster.temp_dir).join("skip-outage-mrf-fallback");
|
||||
std::fs::write(&path, format!("{bucket}/cluster/written-while-node-down-"))?;
|
||||
cluster.set_env("RUSTFS_E2E_SKIP_MRF_FALLBACK_PATH", path.to_string_lossy().into_owned());
|
||||
Some(path)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
cluster.set_env("RUSTFS_UNSAFE_BYPASS_DISK_CHECK", "true");
|
||||
cluster.set_env("RUSTFS_HEAL_ENABLED", "true");
|
||||
if let Some(storage_class) = evidence_case.and_then(|case| case.storage_class_standard) {
|
||||
@@ -1748,7 +1757,6 @@ mod tests {
|
||||
cluster.start_with_binary(&server_binary).await?;
|
||||
let clients = cluster.create_all_clients()?;
|
||||
|
||||
let bucket = "heal-restart-during-rebuild";
|
||||
clients[0].create_bucket().bucket(bucket).send().await?;
|
||||
|
||||
let ReplacementDriveSelection {
|
||||
@@ -1944,6 +1952,21 @@ mod tests {
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(path) = &mrf_fallback_scope {
|
||||
let observed = path.with_extension("observed");
|
||||
let expected = format!("{bucket}/{outage_key}");
|
||||
let deadline = Instant::now() + Duration::from_secs(30);
|
||||
loop {
|
||||
if tokio::fs::read_to_string(&observed).await.ok().as_deref() == Some(expected.as_str()) {
|
||||
break;
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
return Err("outage repair did not reach the isolated best-effort fallback before target rejoin".into());
|
||||
}
|
||||
sleep(Duration::from_millis(50)).await;
|
||||
}
|
||||
}
|
||||
|
||||
assert!(
|
||||
!outage_target_manifest_required
|
||||
|| target_set_peer_drives
|
||||
@@ -2056,7 +2079,12 @@ mod tests {
|
||||
} else {
|
||||
cluster_heal_is_idle(&recovered)
|
||||
};
|
||||
if ready {
|
||||
let pool_ready = if ready && background_enabled && !outage_write_deferred_until_rejoin {
|
||||
all_nodes_pool_metadata_readiness(&cluster, recovery_deadline).await.0
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if ready && pool_ready {
|
||||
break;
|
||||
}
|
||||
if Instant::now() >= recovery_deadline {
|
||||
@@ -2553,6 +2581,10 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(path) = &mrf_fallback_scope {
|
||||
std::fs::remove_file(path)?;
|
||||
}
|
||||
|
||||
if let Some(cycle_end) = scanner_cycle_floor {
|
||||
wait_for_scanner_cycle_after(&cluster, cycle_end).await?;
|
||||
}
|
||||
|
||||
@@ -5120,6 +5120,12 @@ impl SetDisks {
|
||||
if request.expected_bucket_incarnation_id.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
#[cfg(feature = "e2e-test-hooks")]
|
||||
if let Some(object) = request.object_prefix.as_deref()
|
||||
&& skip_e2e_mrf_fallback(&request.bucket, object).await
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
request.source = rustfs_heal_contracts::heal_channel::HealRequestSource::Mrf;
|
||||
#[cfg(test)]
|
||||
{
|
||||
@@ -5822,6 +5828,25 @@ impl SetDisks {
|
||||
// }
|
||||
}
|
||||
|
||||
// The isolated root-heal test suppresses only the direct best-effort fallback.
|
||||
// Persisted MRF responsibilities and their replay keep their normal behavior.
|
||||
#[cfg(feature = "e2e-test-hooks")]
|
||||
pub(in crate::set_disk) async fn skip_e2e_mrf_fallback(bucket: &str, object: &str) -> bool {
|
||||
let Some(path) = std::env::var_os("RUSTFS_E2E_SKIP_MRF_FALLBACK_PATH") else {
|
||||
return false;
|
||||
};
|
||||
let path = std::path::PathBuf::from(path);
|
||||
let Ok(prefix) = tokio::fs::read_to_string(&path).await else {
|
||||
return false;
|
||||
};
|
||||
let key = format!("{bucket}/{object}");
|
||||
if prefix.is_empty() || !key.starts_with(&prefix) {
|
||||
return false;
|
||||
}
|
||||
let _ = tokio::fs::write(path.with_extension("observed"), key).await;
|
||||
true
|
||||
}
|
||||
|
||||
fn is_explicit_null_version(version_id: Option<Uuid>) -> bool {
|
||||
version_id == Some(Uuid::nil())
|
||||
}
|
||||
|
||||
@@ -9150,6 +9150,10 @@ impl SetDisks {
|
||||
// cannot safely target the object name after bucket recreation.
|
||||
return Ok(());
|
||||
};
|
||||
#[cfg(feature = "e2e-test-hooks")]
|
||||
if crate::set_disk::skip_e2e_mrf_fallback(bucket, object).await {
|
||||
return Ok(());
|
||||
}
|
||||
let mut request = rustfs_heal_contracts::heal_channel::create_heal_request_with_options(
|
||||
bucket.to_string(),
|
||||
Some(object.to_string()),
|
||||
|
||||
@@ -506,6 +506,7 @@ struct LockAcquireQuorumResult {
|
||||
individual_locks: Vec<HeldLockEntry>,
|
||||
failure_kind: Option<LockAcquireFailureKind>,
|
||||
quorum_impossible: bool,
|
||||
attempt_timed_out: bool,
|
||||
}
|
||||
|
||||
impl DistributedLock {
|
||||
@@ -886,9 +887,10 @@ impl DistributedLock {
|
||||
}
|
||||
|
||||
async fn acquire_lock_quorum_with_retry(&self, request: &LockRequest) -> Result<LockAcquireQuorumResult> {
|
||||
let start = std::time::Instant::now();
|
||||
let start = tokio::time::Instant::now();
|
||||
let mut attempt = 1;
|
||||
let mut last_result = None;
|
||||
let mut last_result: Option<LockAcquireQuorumResult> = None;
|
||||
let mut preserve_quorum_on_attempt_timeout = false;
|
||||
|
||||
loop {
|
||||
let elapsed = start.elapsed();
|
||||
@@ -906,13 +908,23 @@ impl DistributedLock {
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
last_result = Some(result);
|
||||
let backoff = Self::lock_acquire_retry_backoff(attempt, &mut rand::rng());
|
||||
if start.elapsed().saturating_add(backoff) >= request.acquire_timeout {
|
||||
// A shortened final retry may expire without establishing whether
|
||||
// the previously observed quorum failure has recovered.
|
||||
if !preserve_quorum_on_attempt_timeout || !result.attempt_timed_out {
|
||||
last_result = Some(result);
|
||||
preserve_quorum_on_attempt_timeout = false;
|
||||
}
|
||||
let remaining = request.acquire_timeout.saturating_sub(start.elapsed());
|
||||
if remaining.is_zero() {
|
||||
break;
|
||||
}
|
||||
|
||||
tokio::time::sleep(backoff).await;
|
||||
let backoff = Self::lock_acquire_retry_backoff(attempt, &mut rand::rng());
|
||||
if backoff >= remaining && last_result.as_ref().is_some_and(|result| result.quorum_impossible) {
|
||||
preserve_quorum_on_attempt_timeout = true;
|
||||
}
|
||||
// Keep time for another acquire attempt instead of abandoning the
|
||||
// caller's remaining budget when the jittered backoff grows large.
|
||||
tokio::time::sleep(backoff.min(remaining / 2)).await;
|
||||
attempt += 1;
|
||||
}
|
||||
|
||||
@@ -927,6 +939,7 @@ impl DistributedLock {
|
||||
individual_locks: Vec::new(),
|
||||
failure_kind: Some(LockAcquireFailureKind::RetryableContention),
|
||||
quorum_impossible: false,
|
||||
attempt_timed_out: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -937,6 +950,7 @@ impl DistributedLock {
|
||||
individual_locks: Vec::new(),
|
||||
failure_kind: Some(LockAcquireFailureKind::RetryableContention),
|
||||
quorum_impossible: false,
|
||||
attempt_timed_out: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -966,6 +980,7 @@ impl DistributedLock {
|
||||
individual_locks,
|
||||
failure_kind: Some(failure_kind),
|
||||
quorum_impossible: matches!(failure_kind, LockAcquireFailureKind::UnrecoverableQuorum),
|
||||
attempt_timed_out: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1134,6 +1149,7 @@ impl DistributedLock {
|
||||
individual_locks,
|
||||
failure_kind: Some(failure_kind),
|
||||
quorum_impossible: true,
|
||||
attempt_timed_out: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1176,6 +1192,7 @@ impl DistributedLock {
|
||||
individual_locks,
|
||||
failure_kind: None,
|
||||
quorum_impossible: false,
|
||||
attempt_timed_out: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1221,6 +1238,7 @@ impl DistributedLock {
|
||||
individual_locks,
|
||||
failure_kind: Some(failure_kind),
|
||||
quorum_impossible,
|
||||
attempt_timed_out: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1245,6 +1263,7 @@ impl DistributedLock {
|
||||
last_failure_kind.unwrap_or(LockAcquireFailureKind::RetryableContention)
|
||||
}),
|
||||
quorum_impossible: hard_failures > 0,
|
||||
attempt_timed_out: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2246,6 +2265,71 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
fn clients_with_initial_quorum_loss(retries: &[AcquirePlan]) -> Vec<Arc<dyn LockClient>> {
|
||||
(0..4)
|
||||
.map(|index| {
|
||||
let first = if index < 2 {
|
||||
AcquirePlan::Success { delay: Duration::ZERO }
|
||||
} else {
|
||||
AcquirePlan::Failure {
|
||||
error: "Remote lock RPC failed: node unavailable",
|
||||
delay: Duration::ZERO,
|
||||
}
|
||||
};
|
||||
let mut plans = vec![first];
|
||||
plans.extend_from_slice(retries);
|
||||
Arc::new(SequencedClient::new(plans, Arc::new(Mutex::new(Vec::new())))) as Arc<dyn LockClient>
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn acquire_guard_preserves_quorum_failure_when_last_retry_times_out() {
|
||||
let clients = clients_with_initial_quorum_loss(&[AcquirePlan::Success {
|
||||
delay: Duration::from_secs(1),
|
||||
}]);
|
||||
let lock = DistributedLock::new("test".to_string(), clients, 3);
|
||||
let request = LockRequest::new(ObjectKey::new("bucket", "object"), LockType::Exclusive, "owner")
|
||||
.with_acquire_timeout(Duration::from_millis(180));
|
||||
|
||||
let result = lock.acquire_guard(&request).await;
|
||||
assert!(
|
||||
matches!(result, Err(LockError::QuorumNotReached { required: 3, .. })),
|
||||
"a late inconclusive retry must not hide an observed quorum failure: {result:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn acquire_guard_recovers_quorum_with_shortened_retry() {
|
||||
let clients = clients_with_initial_quorum_loss(&[AcquirePlan::Success { delay: Duration::ZERO }]);
|
||||
let lock = DistributedLock::new("test".to_string(), clients, 3);
|
||||
let request = LockRequest::new(ObjectKey::new("bucket", "object"), LockType::Exclusive, "owner")
|
||||
.with_acquire_timeout(Duration::from_millis(180));
|
||||
|
||||
let guard = lock
|
||||
.acquire_guard(&request)
|
||||
.await
|
||||
.expect("a retry should recover from quorum loss")
|
||||
.expect("a recovered quorum should acquire the lock");
|
||||
assert_eq!(guard.entries.len(), 3);
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn acquire_guard_replaces_quorum_failure_with_later_contention() {
|
||||
let clients = clients_with_initial_quorum_loss(
|
||||
&[AcquirePlan::Failure {
|
||||
error: "Lock acquisition timeout",
|
||||
delay: Duration::ZERO,
|
||||
}; 64],
|
||||
);
|
||||
let lock = DistributedLock::new("test".to_string(), clients, 3);
|
||||
let request = LockRequest::new(ObjectKey::new("bucket", "object"), LockType::Exclusive, "owner")
|
||||
.with_acquire_timeout(Duration::from_millis(180));
|
||||
|
||||
let result = lock.acquire_guard(&request).await;
|
||||
assert!(matches!(result, Ok(None)), "later contention should replace the earlier quorum failure");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn acquire_guard_retries_rpc_timeouts_until_caller_timeout() {
|
||||
let clients: Vec<Arc<dyn LockClient>> = vec![
|
||||
|
||||
@@ -979,6 +979,30 @@ async fn test_namespace_lock_distributed_retries_transient_acquire_timeout() {
|
||||
drop(guard);
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn test_namespace_lock_retries_when_backoff_exceeds_remaining_budget() {
|
||||
let managers = (0..3).map(|_| Arc::new(GlobalLockManager::new())).collect::<Vec<_>>();
|
||||
let flaky_clients = managers
|
||||
.iter()
|
||||
.map(|manager| Arc::new(FlakyAcquireClient::new(manager.clone(), 1)))
|
||||
.collect::<Vec<_>>();
|
||||
let clients = flaky_clients
|
||||
.iter()
|
||||
.map(|client| client.clone() as Arc<dyn LockClient>)
|
||||
.collect::<Vec<_>>();
|
||||
let lock = NamespaceLock::with_clients("short-retry-budget".to_string(), clients);
|
||||
let resource = create_test_object_key("bucket", "short-retry-budget");
|
||||
|
||||
// The first jittered backoff is at least 187 ms, but a second attempt can
|
||||
// still succeed within this budget once the transient failure has cleared.
|
||||
let guard = lock
|
||||
.get_write_lock(resource, "owner", Duration::from_millis(180))
|
||||
.await
|
||||
.expect("a backoff longer than the remaining budget must not discard the remaining attempt");
|
||||
assert!(flaky_clients.iter().any(|client| client.acquire_attempts() >= 2));
|
||||
drop(guard);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_namespace_lock_distributed_waits_full_timeout_for_late_release() {
|
||||
let managers = (0..3).map(|_| Arc::new(GlobalLockManager::new())).collect::<Vec<_>>();
|
||||
@@ -1136,10 +1160,16 @@ async fn test_namespace_lock_distributed_contention_quorum_miss_times_out() {
|
||||
let lock = NamespaceLock::with_clients("contention-timeout".to_string(), clients);
|
||||
let resource = create_test_object_key("bucket", "object-contention-timeout");
|
||||
|
||||
let err = lock
|
||||
.get_write_lock(resource, "owner-a", Duration::from_millis(40))
|
||||
let timeout = Duration::from_millis(40);
|
||||
let started = std::time::Instant::now();
|
||||
let err = tokio::time::timeout(Duration::from_secs(2), lock.get_write_lock(resource, "owner-a", timeout))
|
||||
.await
|
||||
.expect("contended acquisition must remain bounded")
|
||||
.expect_err("ordinary contention should exhaust acquire timeout");
|
||||
assert!(
|
||||
started.elapsed() >= timeout,
|
||||
"a contended acquisition must not return before its configured deadline"
|
||||
);
|
||||
|
||||
let err_str = err.to_string().to_lowercase();
|
||||
assert!(err_str.contains("timeout"), "expected timeout after contention retries, got: {err}");
|
||||
|
||||
Reference in New Issue
Block a user