mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-22 20:36:38 +00:00
Merge remote-tracking branch 'origin/main' into codex/resolve-pr-6352
# Conflicts: # crates/scanner/src/scanner/tests.rs
This commit is contained in:
@@ -50,10 +50,10 @@ use rustfs_protos::evict_failed_connection;
|
|||||||
use rustfs_protos::proto_gen::node_service::RenamePartRequest;
|
use rustfs_protos::proto_gen::node_service::RenamePartRequest;
|
||||||
use rustfs_protos::proto_gen::node_service::{
|
use rustfs_protos::proto_gen::node_service::{
|
||||||
BatchReadVersionRequest, BatchReadVersionResponse, CheckPartsRequest, DeletePathsRequest, DeleteRequest,
|
BatchReadVersionRequest, BatchReadVersionResponse, CheckPartsRequest, DeletePathsRequest, DeleteRequest,
|
||||||
DeleteVersionRequest, DeleteVersionsRequest, DeleteVolumeRequest, DiskInfoRequest, ListDirRequest, ListVolumesRequest,
|
DeleteVersionRequest, DeleteVersionsRequest, DeleteVersionsResponse, DeleteVolumeRequest, DiskInfoRequest, ListDirRequest,
|
||||||
MakeVolumeRequest, MakeVolumesRequest, PreparePartTransactionRequest, ReadAllRequest, ReadMetadataRequest,
|
ListVolumesRequest, MakeVolumeRequest, MakeVolumesRequest, PreparePartTransactionRequest, ReadAllRequest,
|
||||||
ReadMultipleRequest, ReadMultipleResponse, ReadPartsRequest, ReadVersionRequest, ReadXlRequest, RenameDataRequest,
|
ReadMetadataRequest, ReadMultipleRequest, ReadMultipleResponse, ReadPartsRequest, ReadVersionRequest, ReadXlRequest,
|
||||||
RenameFileRequest, SettlePartTransactionRequest, SnapshotLeaseReleaseRequest, SnapshotLeaseRenewRequest,
|
RenameDataRequest, RenameFileRequest, SettlePartTransactionRequest, SnapshotLeaseReleaseRequest, SnapshotLeaseRenewRequest,
|
||||||
SnapshotLeaseRequest, SnapshotLeaseResponse, StatVolumeRequest, UpdateMetadataRequest, VerifyFileRequest, WriteAllRequest,
|
SnapshotLeaseRequest, SnapshotLeaseResponse, StatVolumeRequest, UpdateMetadataRequest, VerifyFileRequest, WriteAllRequest,
|
||||||
WriteMetadataRequest, node_service_client::NodeServiceClient,
|
WriteMetadataRequest, node_service_client::NodeServiceClient,
|
||||||
};
|
};
|
||||||
@@ -112,6 +112,28 @@ const EVENT_REMOTE_DISK_RPC: &str = "remote_disk_rpc";
|
|||||||
const SNAPSHOT_LEASE_PROTOCOL_VERSION: u32 = 1;
|
const SNAPSHOT_LEASE_PROTOCOL_VERSION: u32 = 1;
|
||||||
pub const REMOTE_SNAPSHOT_LEASE_TTL: Duration = Duration::from_secs(60);
|
pub const REMOTE_SNAPSHOT_LEASE_TTL: Duration = Duration::from_secs(60);
|
||||||
|
|
||||||
|
fn decode_delete_versions_errors(response: DeleteVersionsResponse, expected_len: usize) -> Vec<Option<Error>> {
|
||||||
|
if !response.item_errors.is_empty() {
|
||||||
|
if response.item_errors.len() != expected_len {
|
||||||
|
return vec![Some(Error::other("malformed delete_versions item errors")); expected_len];
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
.item_errors
|
||||||
|
.into_iter()
|
||||||
|
.map(|error| (error.code != 0).then(|| error.into()))
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
if response.errors.len() != expected_len {
|
||||||
|
return vec![Some(Error::other("malformed delete_versions errors")); expected_len];
|
||||||
|
}
|
||||||
|
response
|
||||||
|
.errors
|
||||||
|
.into_iter()
|
||||||
|
.map(|error| (!error.is_empty()).then(|| Error::other(error)))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn snapshot_lease_token_from_response(response: SnapshotLeaseResponse) -> Result<SnapshotLeaseToken> {
|
fn snapshot_lease_token_from_response(response: SnapshotLeaseResponse) -> Result<SnapshotLeaseToken> {
|
||||||
if !response.success {
|
if !response.success {
|
||||||
return Err(response.error.unwrap_or_default().into());
|
return Err(response.error.unwrap_or_default().into());
|
||||||
@@ -2406,8 +2428,6 @@ impl DiskAPI for RemoteDisk {
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(backlog): replace string errors with typed `StorageError` variants
|
|
||||||
|
|
||||||
let result = self
|
let result = self
|
||||||
.execute_with_timeout(
|
.execute_with_timeout(
|
||||||
|| async {
|
|| async {
|
||||||
@@ -2439,17 +2459,7 @@ impl DiskAPI for RemoteDisk {
|
|||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
response
|
decode_delete_versions_errors(response, versions.len())
|
||||||
.errors
|
|
||||||
.iter()
|
|
||||||
.map(|error| {
|
|
||||||
if error.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(Error::other(error.to_string()))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all)]
|
#[tracing::instrument(level = "trace", skip_all)]
|
||||||
@@ -3760,6 +3770,63 @@ mod tests {
|
|||||||
|
|
||||||
static INIT: Once = Once::new();
|
static INIT: Once = Once::new();
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_versions_response_preserves_typed_item_errors() {
|
||||||
|
let errors = decode_delete_versions_errors(
|
||||||
|
DeleteVersionsResponse {
|
||||||
|
success: true,
|
||||||
|
errors: vec!["file not found".to_string(), String::new()],
|
||||||
|
error: None,
|
||||||
|
item_errors: vec![
|
||||||
|
rustfs_protos::proto_gen::node_service::Error {
|
||||||
|
code: DiskError::FileNotFound.to_u32(),
|
||||||
|
error_info: "file not found".to_string(),
|
||||||
|
},
|
||||||
|
rustfs_protos::proto_gen::node_service::Error::default(),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(matches!(errors.as_slice(), [Some(DiskError::FileNotFound), None]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_versions_response_accepts_legacy_string_errors() {
|
||||||
|
let errors = decode_delete_versions_errors(
|
||||||
|
DeleteVersionsResponse {
|
||||||
|
success: true,
|
||||||
|
errors: vec!["legacy error".to_string(), String::new()],
|
||||||
|
error: None,
|
||||||
|
item_errors: Vec::new(),
|
||||||
|
},
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(errors.len(), 2);
|
||||||
|
assert_eq!(errors[0].as_ref().map(ToString::to_string).as_deref(), Some("io error legacy error"));
|
||||||
|
assert!(errors[1].is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_versions_response_rejects_misaligned_item_errors() {
|
||||||
|
let errors = decode_delete_versions_errors(
|
||||||
|
DeleteVersionsResponse {
|
||||||
|
success: true,
|
||||||
|
errors: vec!["file not found".to_string()],
|
||||||
|
error: None,
|
||||||
|
item_errors: vec![rustfs_protos::proto_gen::node_service::Error {
|
||||||
|
code: DiskError::FileNotFound.to_u32(),
|
||||||
|
error_info: "file not found".to_string(),
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(errors.len(), 2);
|
||||||
|
assert!(errors.iter().all(Option::is_some));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn disk_mutation_digest_marks_rolling_compatibility() {
|
fn disk_mutation_digest_marks_rolling_compatibility() {
|
||||||
let mut request = Request::new(());
|
let mut request = Request::new(());
|
||||||
|
|||||||
@@ -1640,6 +1640,60 @@ mod tests {
|
|||||||
assert_eq!(payload["items"].as_array().expect("items should be an array").len(), 0);
|
assert_eq!(payload["items"].as_array().expect("items should be an array").len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_process_query_request_reports_displaced_terminal_detail() {
|
||||||
|
let heal_manager = Arc::new(HealManager::new(
|
||||||
|
Arc::new(MockStorage),
|
||||||
|
Some(HealConfig {
|
||||||
|
queue_size: 1,
|
||||||
|
..HealConfig::default()
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
let mut displaced = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "displaced-channel".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
displaced.id = "displaced-channel-task".to_string();
|
||||||
|
let displaced_id = displaced.id.clone();
|
||||||
|
heal_manager
|
||||||
|
.submit_heal_request(displaced)
|
||||||
|
.await
|
||||||
|
.expect("initial channel task should queue");
|
||||||
|
heal_manager
|
||||||
|
.submit_heal_request(HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "successor-channel".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::High,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.expect("successor channel task should displace the initial task");
|
||||||
|
|
||||||
|
let processor = HealChannelProcessor::new(heal_manager);
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
processor
|
||||||
|
.process_query_request("displaced-channel".to_string(), displaced_id, None, tx)
|
||||||
|
.await
|
||||||
|
.expect("displaced query should process");
|
||||||
|
let response = rx
|
||||||
|
.await
|
||||||
|
.expect("query response should be returned")
|
||||||
|
.expect("displaced query should remain successful");
|
||||||
|
let payload: serde_json::Value = serde_json::from_slice(response.data.as_deref().expect("status payload should exist"))
|
||||||
|
.expect("status payload should be json");
|
||||||
|
assert_eq!(payload["summary"], "stopped");
|
||||||
|
assert!(
|
||||||
|
response
|
||||||
|
.error
|
||||||
|
.as_deref()
|
||||||
|
.is_some_and(|detail| detail.contains("reason=displaced"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_process_query_request_reports_running_for_queued_task() {
|
async fn test_process_query_request_reports_running_for_queued_task() {
|
||||||
let heal_manager = create_test_heal_manager();
|
let heal_manager = create_test_heal_manager();
|
||||||
|
|||||||
+105
-10
@@ -40,6 +40,7 @@ use tracing::{debug, error, info, warn};
|
|||||||
use super::{DiskError, Endpoint, HealDiskExt as _, local_disk_map_read};
|
use super::{DiskError, Endpoint, HealDiskExt as _, local_disk_map_read};
|
||||||
|
|
||||||
const KEEP_HEAL_TASK_STATUS_DURATION: Duration = Duration::from_secs(10 * 60);
|
const KEEP_HEAL_TASK_STATUS_DURATION: Duration = Duration::from_secs(10 * 60);
|
||||||
|
const DISPLACED_HEAL_REASON: &str = "reason=displaced; retry_hint=submit_again";
|
||||||
const LOG_COMPONENT_HEAL: &str = "heal";
|
const LOG_COMPONENT_HEAL: &str = "heal";
|
||||||
const LOG_SUBSYSTEM_DISK_SCANNER: &str = "disk_scanner";
|
const LOG_SUBSYSTEM_DISK_SCANNER: &str = "disk_scanner";
|
||||||
const LOG_SUBSYSTEM_MANAGER: &str = "manager";
|
const LOG_SUBSYSTEM_MANAGER: &str = "manager";
|
||||||
@@ -120,26 +121,30 @@ struct MrfRepairNoticeTarget {
|
|||||||
version_id: Option<[u8; 16]>,
|
version_id: Option<[u8; 16]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone)]
|
||||||
struct HealAdmissionDecision {
|
struct HealAdmissionDecision {
|
||||||
result: HealAdmissionResult,
|
result: HealAdmissionResult,
|
||||||
displaced_task_id: Option<String>,
|
displaced_request: Option<HealRequest>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HealAdmissionDecision {
|
impl HealAdmissionDecision {
|
||||||
const fn new(result: HealAdmissionResult) -> Self {
|
const fn new(result: HealAdmissionResult) -> Self {
|
||||||
Self {
|
Self {
|
||||||
result,
|
result,
|
||||||
displaced_task_id: None,
|
displaced_request: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn accepted_with_displacement(displaced_task_id: String) -> Self {
|
fn accepted_with_displacement(displaced_request: HealRequest) -> Self {
|
||||||
Self {
|
Self {
|
||||||
result: HealAdmissionResult::Accepted,
|
result: HealAdmissionResult::Accepted,
|
||||||
displaced_task_id: Some(displaced_task_id),
|
displaced_request: Some(displaced_request),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn displaced_task_id(&self) -> Option<&str> {
|
||||||
|
self.displaced_request.as_ref().map(|request| request.id.as_str())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lock_mrf_repair_notice_targets(
|
fn lock_mrf_repair_notice_targets(
|
||||||
@@ -151,6 +156,55 @@ fn lock_mrf_repair_notice_targets(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lock_displaced_terminals(
|
||||||
|
registry: &StdMutex<HashMap<String, Arc<CompletedHealStatus>>>,
|
||||||
|
) -> StdMutexGuard<'_, HashMap<String, Arc<CompletedHealStatus>>> {
|
||||||
|
match registry.lock() {
|
||||||
|
Ok(guard) => guard,
|
||||||
|
Err(poisoned) => poisoned.into_inner(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn record_displaced_terminal(
|
||||||
|
registry: &StdMutex<HashMap<String, Arc<CompletedHealStatus>>>,
|
||||||
|
request: &HealRequest,
|
||||||
|
) -> Arc<CompletedHealStatus> {
|
||||||
|
let terminal = Arc::new(CompletedHealStatus {
|
||||||
|
heal_type: request.heal_type.clone(),
|
||||||
|
status: HealTaskStatus::Failed {
|
||||||
|
error: format!("heal task displaced by a higher-priority request ({DISPLACED_HEAL_REASON})"),
|
||||||
|
},
|
||||||
|
result_items_truncated: false,
|
||||||
|
completed_at: SystemTime::now(),
|
||||||
|
seqed_items: Vec::new(),
|
||||||
|
next_seq: 0,
|
||||||
|
min_seq: 0,
|
||||||
|
});
|
||||||
|
let mut terminals = lock_displaced_terminals(registry);
|
||||||
|
prune_completed_heal_statuses(&mut terminals);
|
||||||
|
terminals.insert(request.id.clone(), Arc::clone(&terminal));
|
||||||
|
terminal
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn remove_displaced_task_aliases(
|
||||||
|
aliases: &Arc<Mutex<HashMap<String, HealTaskAlias>>>,
|
||||||
|
terminals: &StdMutex<HashMap<String, Arc<CompletedHealStatus>>>,
|
||||||
|
task_id: &str,
|
||||||
|
terminal: &Arc<CompletedHealStatus>,
|
||||||
|
) {
|
||||||
|
let mut aliases = aliases.lock().await;
|
||||||
|
let alias_ids = aliases
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(alias_id, alias)| (alias.task_id == task_id).then_some(alias_id.clone()))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let mut displaced_terminals = lock_displaced_terminals(terminals);
|
||||||
|
prune_completed_heal_statuses(&mut displaced_terminals);
|
||||||
|
for alias_id in alias_ids {
|
||||||
|
displaced_terminals.insert(alias_id, Arc::clone(terminal));
|
||||||
|
}
|
||||||
|
aliases.retain(|alias_id, alias| alias_id != task_id && alias.task_id != task_id);
|
||||||
|
}
|
||||||
|
|
||||||
async fn remove_task_aliases_for_task(registry: &Arc<Mutex<HashMap<String, HealTaskAlias>>>, task_id: &str) {
|
async fn remove_task_aliases_for_task(registry: &Arc<Mutex<HashMap<String, HealTaskAlias>>>, task_id: &str) {
|
||||||
registry
|
registry
|
||||||
.lock()
|
.lock()
|
||||||
@@ -618,6 +672,14 @@ pub struct HealManager {
|
|||||||
/// are shared so the lookup helper can hand a completed entry to a
|
/// are shared so the lookup helper can hand a completed entry to a
|
||||||
/// caller without cloning the retained result window.
|
/// caller without cloning the retained result window.
|
||||||
completed_heals: Arc<Mutex<HashMap<String, Arc<CompletedHealStatus>>>>,
|
completed_heals: Arc<Mutex<HashMap<String, Arc<CompletedHealStatus>>>>,
|
||||||
|
/// Terminals for requests removed by priority displacement. An Accepted
|
||||||
|
/// task ID remains queryable for the same process lifetime and the normal
|
||||||
|
/// ten-minute status TTL; clients should treat `reason=displaced` as a
|
||||||
|
/// terminal result and submit a fresh request. This sidecar is synchronous
|
||||||
|
/// so admission can publish the terminal while the queue transition is
|
||||||
|
/// still under its lock, without awaiting another tokio lock. Queue state
|
||||||
|
/// is process-local, so this guarantee does not extend across restart.
|
||||||
|
displaced_terminals: Arc<StdMutex<HashMap<String, Arc<CompletedHealStatus>>>>,
|
||||||
/// Client tokens merged into an existing task id.
|
/// Client tokens merged into an existing task id.
|
||||||
task_aliases: Arc<Mutex<HashMap<String, HealTaskAlias>>>,
|
task_aliases: Arc<Mutex<HashMap<String, HealTaskAlias>>>,
|
||||||
/// Heal tasks waiting for a retry backoff to expire.
|
/// Heal tasks waiting for a retry backoff to expire.
|
||||||
@@ -659,6 +721,7 @@ struct HealQueueContext<'a> {
|
|||||||
heal_queue: &'a Arc<Mutex<PriorityHealQueue>>,
|
heal_queue: &'a Arc<Mutex<PriorityHealQueue>>,
|
||||||
active_heals: &'a Arc<Mutex<HashMap<String, Arc<HealTask>>>>,
|
active_heals: &'a Arc<Mutex<HashMap<String, Arc<HealTask>>>>,
|
||||||
completed_heals: &'a Arc<Mutex<HashMap<String, Arc<CompletedHealStatus>>>>,
|
completed_heals: &'a Arc<Mutex<HashMap<String, Arc<CompletedHealStatus>>>>,
|
||||||
|
displaced_terminals: &'a Arc<StdMutex<HashMap<String, Arc<CompletedHealStatus>>>>,
|
||||||
task_aliases: &'a Arc<Mutex<HashMap<String, HealTaskAlias>>>,
|
task_aliases: &'a Arc<Mutex<HashMap<String, HealTaskAlias>>>,
|
||||||
retrying_heals: &'a Arc<Mutex<HashMap<String, RetryingHeal>>>,
|
retrying_heals: &'a Arc<Mutex<HashMap<String, RetryingHeal>>>,
|
||||||
mrf_repair_notice_targets: &'a Arc<StdMutex<HashMap<String, Vec<MrfRepairNoticeTarget>>>>,
|
mrf_repair_notice_targets: &'a Arc<StdMutex<HashMap<String, Vec<MrfRepairNoticeTarget>>>>,
|
||||||
@@ -874,7 +937,7 @@ impl HealManager {
|
|||||||
result = "accepted_by_displacement",
|
result = "accepted_by_displacement",
|
||||||
"Heal queue request accepted by displacement"
|
"Heal queue request accepted by displacement"
|
||||||
});
|
});
|
||||||
return HealAdmissionDecision::accepted_with_displacement(displaced.id);
|
return HealAdmissionDecision::accepted_with_displacement(displaced);
|
||||||
}
|
}
|
||||||
|
|
||||||
demote_to_debug_when!(per_object_request, warn, target: "rustfs::heal::manager", {
|
demote_to_debug_when!(per_object_request, warn, target: "rustfs::heal::manager", {
|
||||||
@@ -1105,6 +1168,7 @@ impl HealManager {
|
|||||||
active_heals: Arc::new(Mutex::new(HashMap::new())),
|
active_heals: Arc::new(Mutex::new(HashMap::new())),
|
||||||
heal_queue: Arc::new(Mutex::new(PriorityHealQueue::new())),
|
heal_queue: Arc::new(Mutex::new(PriorityHealQueue::new())),
|
||||||
completed_heals: Arc::new(Mutex::new(HashMap::new())),
|
completed_heals: Arc::new(Mutex::new(HashMap::new())),
|
||||||
|
displaced_terminals: Arc::new(StdMutex::new(HashMap::new())),
|
||||||
task_aliases: Arc::new(Mutex::new(HashMap::new())),
|
task_aliases: Arc::new(Mutex::new(HashMap::new())),
|
||||||
retrying_heals: Arc::new(Mutex::new(HashMap::new())),
|
retrying_heals: Arc::new(Mutex::new(HashMap::new())),
|
||||||
mrf_repair_notice_targets: Arc::new(StdMutex::new(HashMap::new())),
|
mrf_repair_notice_targets: Arc::new(StdMutex::new(HashMap::new())),
|
||||||
@@ -1209,6 +1273,10 @@ impl HealManager {
|
|||||||
active_heals.clear();
|
active_heals.clear();
|
||||||
publish_active_heal_count(&active_heals);
|
publish_active_heal_count(&active_heals);
|
||||||
self.completed_heals.lock().await.clear();
|
self.completed_heals.lock().await.clear();
|
||||||
|
// Do not let the synchronous guard live across the following async lock.
|
||||||
|
{
|
||||||
|
lock_displaced_terminals(&self.displaced_terminals).clear();
|
||||||
|
}
|
||||||
self.task_aliases.lock().await.clear();
|
self.task_aliases.lock().await.clear();
|
||||||
self.retrying_heals.lock().await.clear();
|
self.retrying_heals.lock().await.clear();
|
||||||
lock_mrf_repair_notice_targets(&self.mrf_repair_notice_targets).clear();
|
lock_mrf_repair_notice_targets(&self.mrf_repair_notice_targets).clear();
|
||||||
@@ -1459,7 +1527,11 @@ impl HealManager {
|
|||||||
task_id = queued_id.to_owned();
|
task_id = queued_id.to_owned();
|
||||||
}
|
}
|
||||||
let should_notify = matches!(admission, HealAdmissionResult::Accepted) && config.event_driven_scheduler_enable;
|
let should_notify = matches!(admission, HealAdmissionResult::Accepted) && config.event_driven_scheduler_enable;
|
||||||
let displaced_task_id = admission_decision.displaced_task_id;
|
let displaced_task_id = admission_decision.displaced_task_id().map(ToOwned::to_owned);
|
||||||
|
let displaced_terminal = admission_decision
|
||||||
|
.displaced_request
|
||||||
|
.as_ref()
|
||||||
|
.map(|request| record_displaced_terminal(&self.displaced_terminals, request));
|
||||||
if matches!(admission, HealAdmissionResult::Accepted | HealAdmissionResult::Merged)
|
if matches!(admission, HealAdmissionResult::Accepted | HealAdmissionResult::Merged)
|
||||||
&& let Some(target) = mrf_notice_target
|
&& let Some(target) = mrf_notice_target
|
||||||
{
|
{
|
||||||
@@ -1473,8 +1545,12 @@ impl HealManager {
|
|||||||
drop(queue);
|
drop(queue);
|
||||||
drop(active_heals);
|
drop(active_heals);
|
||||||
|
|
||||||
if let Some(displaced_task_id) = displaced_task_id {
|
if let (Some(displaced_task_id), Some(displaced_terminal)) = (displaced_task_id, displaced_terminal) {
|
||||||
self.remove_aliases_for_task(&displaced_task_id).await;
|
// The queue has already removed the displaced request, so the
|
||||||
|
// synchronous terminal sidecar was published before aliases and
|
||||||
|
// MRF ownership are cleaned up.
|
||||||
|
remove_displaced_task_aliases(&self.task_aliases, &self.displaced_terminals, &displaced_task_id, &displaced_terminal)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
if should_notify {
|
if should_notify {
|
||||||
@@ -1549,6 +1625,15 @@ impl HealManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if terminal_completed.is_none() {
|
||||||
|
let mut displaced_terminals = lock_displaced_terminals(&self.displaced_terminals);
|
||||||
|
prune_completed_heal_statuses(&mut displaced_terminals);
|
||||||
|
terminal_completed = displaced_terminals
|
||||||
|
.get(canonical_task_id)
|
||||||
|
.filter(|terminal| matches_path(&terminal.heal_type))
|
||||||
|
.cloned();
|
||||||
|
}
|
||||||
|
|
||||||
match terminal_completed {
|
match terminal_completed {
|
||||||
Some(completed) => TaskStateLookup::Completed(completed),
|
Some(completed) => TaskStateLookup::Completed(completed),
|
||||||
None => TaskStateLookup::NotFound,
|
None => TaskStateLookup::NotFound,
|
||||||
@@ -1669,9 +1754,19 @@ impl HealManager {
|
|||||||
|
|
||||||
let mut completed_heals = self.completed_heals.lock().await;
|
let mut completed_heals = self.completed_heals.lock().await;
|
||||||
prune_completed_heal_statuses(&mut completed_heals);
|
prune_completed_heal_statuses(&mut completed_heals);
|
||||||
completed_heals
|
if completed_heals
|
||||||
.values()
|
.values()
|
||||||
.any(|completed| heal_type_matches_path(&completed.heal_type, heal_path))
|
.any(|completed| heal_type_matches_path(&completed.heal_type, heal_path))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
drop(completed_heals);
|
||||||
|
|
||||||
|
let mut displaced_terminals = lock_displaced_terminals(&self.displaced_terminals);
|
||||||
|
prune_completed_heal_statuses(&mut displaced_terminals);
|
||||||
|
displaced_terminals
|
||||||
|
.values()
|
||||||
|
.any(|terminal| heal_type_matches_path(&terminal.heal_type, heal_path))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get task progress
|
/// Get task progress
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ impl HealManager {
|
|||||||
let heal_queue = self.heal_queue.clone();
|
let heal_queue = self.heal_queue.clone();
|
||||||
let active_heals = self.active_heals.clone();
|
let active_heals = self.active_heals.clone();
|
||||||
let task_aliases = self.task_aliases.clone();
|
let task_aliases = self.task_aliases.clone();
|
||||||
|
let displaced_terminals = self.displaced_terminals.clone();
|
||||||
let mrf_repair_notice_targets = self.mrf_repair_notice_targets.clone();
|
let mrf_repair_notice_targets = self.mrf_repair_notice_targets.clone();
|
||||||
let storage = self.storage.clone();
|
let storage = self.storage.clone();
|
||||||
let replacement_recovery_anchors = self.replacement_recovery_anchors.clone();
|
let replacement_recovery_anchors = self.replacement_recovery_anchors.clone();
|
||||||
@@ -481,6 +482,10 @@ impl HealManager {
|
|||||||
let admission = admission_decision.result;
|
let admission = admission_decision.result;
|
||||||
let should_notify =
|
let should_notify =
|
||||||
matches!(admission, HealAdmissionResult::Accepted) && config.event_driven_scheduler_enable;
|
matches!(admission, HealAdmissionResult::Accepted) && config.event_driven_scheduler_enable;
|
||||||
|
let displaced_terminal = admission_decision
|
||||||
|
.displaced_request
|
||||||
|
.as_ref()
|
||||||
|
.map(|request| record_displaced_terminal(&displaced_terminals, request));
|
||||||
if matches!(admission, HealAdmissionResult::Accepted)
|
if matches!(admission, HealAdmissionResult::Accepted)
|
||||||
&& let Some(anchor) = recovery_anchor
|
&& let Some(anchor) = recovery_anchor
|
||||||
{
|
{
|
||||||
@@ -491,8 +496,16 @@ impl HealManager {
|
|||||||
}
|
}
|
||||||
drop(queue);
|
drop(queue);
|
||||||
drop(config);
|
drop(config);
|
||||||
if let Some(displaced_task_id) = admission_decision.displaced_task_id {
|
if let (Some(displaced_task_id), Some(displaced_terminal)) =
|
||||||
remove_task_aliases_for_task(&task_aliases, &displaced_task_id).await;
|
(admission_decision.displaced_task_id().map(ToOwned::to_owned), displaced_terminal)
|
||||||
|
{
|
||||||
|
remove_displaced_task_aliases(
|
||||||
|
&task_aliases,
|
||||||
|
&displaced_terminals,
|
||||||
|
&displaced_task_id,
|
||||||
|
&displaced_terminal,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
lock_mrf_repair_notice_targets(&mrf_repair_notice_targets).remove(&displaced_task_id);
|
lock_mrf_repair_notice_targets(&mrf_repair_notice_targets).remove(&displaced_task_id);
|
||||||
}
|
}
|
||||||
if matches!(admission, HealAdmissionResult::Accepted) {
|
if matches!(admission, HealAdmissionResult::Accepted) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ impl HealManager {
|
|||||||
let heal_queue = self.heal_queue.clone();
|
let heal_queue = self.heal_queue.clone();
|
||||||
let active_heals = self.active_heals.clone();
|
let active_heals = self.active_heals.clone();
|
||||||
let completed_heals = self.completed_heals.clone();
|
let completed_heals = self.completed_heals.clone();
|
||||||
|
let displaced_terminals = self.displaced_terminals.clone();
|
||||||
let task_aliases = self.task_aliases.clone();
|
let task_aliases = self.task_aliases.clone();
|
||||||
let retrying_heals = self.retrying_heals.clone();
|
let retrying_heals = self.retrying_heals.clone();
|
||||||
let mrf_repair_notice_targets = self.mrf_repair_notice_targets.clone();
|
let mrf_repair_notice_targets = self.mrf_repair_notice_targets.clone();
|
||||||
@@ -53,6 +54,7 @@ impl HealManager {
|
|||||||
heal_queue: &heal_queue,
|
heal_queue: &heal_queue,
|
||||||
active_heals: &active_heals,
|
active_heals: &active_heals,
|
||||||
completed_heals: &completed_heals,
|
completed_heals: &completed_heals,
|
||||||
|
displaced_terminals: &displaced_terminals,
|
||||||
task_aliases: &task_aliases,
|
task_aliases: &task_aliases,
|
||||||
retrying_heals: &retrying_heals,
|
retrying_heals: &retrying_heals,
|
||||||
mrf_repair_notice_targets: &mrf_repair_notice_targets,
|
mrf_repair_notice_targets: &mrf_repair_notice_targets,
|
||||||
@@ -71,6 +73,7 @@ impl HealManager {
|
|||||||
heal_queue: &heal_queue,
|
heal_queue: &heal_queue,
|
||||||
active_heals: &active_heals,
|
active_heals: &active_heals,
|
||||||
completed_heals: &completed_heals,
|
completed_heals: &completed_heals,
|
||||||
|
displaced_terminals: &displaced_terminals,
|
||||||
task_aliases: &task_aliases,
|
task_aliases: &task_aliases,
|
||||||
retrying_heals: &retrying_heals,
|
retrying_heals: &retrying_heals,
|
||||||
mrf_repair_notice_targets: &mrf_repair_notice_targets,
|
mrf_repair_notice_targets: &mrf_repair_notice_targets,
|
||||||
@@ -98,6 +101,7 @@ impl HealManager {
|
|||||||
heal_queue,
|
heal_queue,
|
||||||
active_heals,
|
active_heals,
|
||||||
completed_heals,
|
completed_heals,
|
||||||
|
displaced_terminals,
|
||||||
task_aliases,
|
task_aliases,
|
||||||
retrying_heals,
|
retrying_heals,
|
||||||
mrf_repair_notice_targets,
|
mrf_repair_notice_targets,
|
||||||
@@ -183,6 +187,7 @@ impl HealManager {
|
|||||||
let active_heals_clone = active_heals.clone();
|
let active_heals_clone = active_heals.clone();
|
||||||
let heal_queue_clone = heal_queue.clone();
|
let heal_queue_clone = heal_queue.clone();
|
||||||
let completed_heals_clone = completed_heals.clone();
|
let completed_heals_clone = completed_heals.clone();
|
||||||
|
let displaced_terminals_clone = displaced_terminals.clone();
|
||||||
let task_aliases_clone = task_aliases.clone();
|
let task_aliases_clone = task_aliases.clone();
|
||||||
let retrying_heals_clone = retrying_heals.clone();
|
let retrying_heals_clone = retrying_heals.clone();
|
||||||
let mrf_repair_notice_targets_clone = mrf_repair_notice_targets.clone();
|
let mrf_repair_notice_targets_clone = mrf_repair_notice_targets.clone();
|
||||||
@@ -363,6 +368,7 @@ impl HealManager {
|
|||||||
let retry_heal_queue = heal_queue_clone.clone();
|
let retry_heal_queue = heal_queue_clone.clone();
|
||||||
let retrying_heals_for_spawn = retrying_heals_clone.clone();
|
let retrying_heals_for_spawn = retrying_heals_clone.clone();
|
||||||
let retry_task_aliases = task_aliases_clone.clone();
|
let retry_task_aliases = task_aliases_clone.clone();
|
||||||
|
let retry_displaced_terminals = displaced_terminals_clone.clone();
|
||||||
let retry_mrf_repair_notice_targets = mrf_repair_notice_targets_clone.clone();
|
let retry_mrf_repair_notice_targets = mrf_repair_notice_targets_clone.clone();
|
||||||
let retry_completed_heals = completed_heals_clone.clone();
|
let retry_completed_heals = completed_heals_clone.clone();
|
||||||
let retry_notify = notify_clone.clone();
|
let retry_notify = notify_clone.clone();
|
||||||
@@ -430,6 +436,14 @@ impl HealManager {
|
|||||||
let admission = admission_decision.result;
|
let admission = admission_decision.result;
|
||||||
let should_notify = matches!(admission, HealAdmissionResult::Accepted)
|
let should_notify = matches!(admission, HealAdmissionResult::Accepted)
|
||||||
&& retry_config.event_driven_scheduler_enable;
|
&& retry_config.event_driven_scheduler_enable;
|
||||||
|
// Publish the terminal synchronously while the
|
||||||
|
// queue transition is protected. The subsequent
|
||||||
|
// queue -> retrying handoff retains the lock order
|
||||||
|
// used by operations_snapshot.
|
||||||
|
let displaced_terminal = admission_decision
|
||||||
|
.displaced_request
|
||||||
|
.as_ref()
|
||||||
|
.map(|request| record_displaced_terminal(&retry_displaced_terminals, request));
|
||||||
match admission {
|
match admission {
|
||||||
HealAdmissionResult::Accepted => {
|
HealAdmissionResult::Accepted => {
|
||||||
// Transfer ownership while holding queue -> retrying,
|
// Transfer ownership while holding queue -> retrying,
|
||||||
@@ -437,10 +451,18 @@ impl HealManager {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pause_retry_ownership_transition(&retry_request_id, true).await;
|
pause_retry_ownership_transition(&retry_request_id, true).await;
|
||||||
retrying_heals_for_spawn.lock().await.remove(&retry_request_id);
|
retrying_heals_for_spawn.lock().await.remove(&retry_request_id);
|
||||||
let displaced_task_id = admission_decision.displaced_task_id;
|
let displaced_task_id = admission_decision.displaced_task_id().map(ToOwned::to_owned);
|
||||||
drop(queue);
|
drop(queue);
|
||||||
if let Some(displaced_task_id) = displaced_task_id {
|
if let (Some(displaced_task_id), Some(displaced_terminal)) =
|
||||||
remove_task_aliases_for_task(&retry_task_aliases, &displaced_task_id).await;
|
(displaced_task_id, displaced_terminal)
|
||||||
|
{
|
||||||
|
remove_displaced_task_aliases(
|
||||||
|
&retry_task_aliases,
|
||||||
|
&retry_displaced_terminals,
|
||||||
|
&displaced_task_id,
|
||||||
|
&displaced_terminal,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
remove_mrf_repair_notice_targets(
|
remove_mrf_repair_notice_targets(
|
||||||
&retry_mrf_repair_notice_targets,
|
&retry_mrf_repair_notice_targets,
|
||||||
&displaced_task_id,
|
&displaced_task_id,
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ async fn process_manager_queue_once(manager: &HealManager) {
|
|||||||
heal_queue: &manager.heal_queue,
|
heal_queue: &manager.heal_queue,
|
||||||
active_heals: &manager.active_heals,
|
active_heals: &manager.active_heals,
|
||||||
completed_heals: &manager.completed_heals,
|
completed_heals: &manager.completed_heals,
|
||||||
|
displaced_terminals: &manager.displaced_terminals,
|
||||||
task_aliases: &manager.task_aliases,
|
task_aliases: &manager.task_aliases,
|
||||||
retrying_heals: &manager.retrying_heals,
|
retrying_heals: &manager.retrying_heals,
|
||||||
mrf_repair_notice_targets: &manager.mrf_repair_notice_targets,
|
mrf_repair_notice_targets: &manager.mrf_repair_notice_targets,
|
||||||
@@ -2778,7 +2779,10 @@ async fn test_high_priority_request_displaces_lower_priority_when_queue_full() {
|
|||||||
HealAdmissionResult::Accepted
|
HealAdmissionResult::Accepted
|
||||||
);
|
);
|
||||||
assert_eq!(manager.get_queue_length().await, 1);
|
assert_eq!(manager.get_queue_length().await, 1);
|
||||||
assert!(matches!(manager.get_task_status(&low_id).await, Err(Error::TaskNotFound { .. })));
|
assert!(matches!(
|
||||||
|
manager.get_task_status(&low_id).await,
|
||||||
|
Ok(HealTaskStatus::Failed { error }) if error.contains("reason=displaced")
|
||||||
|
));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
manager
|
manager
|
||||||
.get_task_status(&high_id)
|
.get_task_status(&high_id)
|
||||||
@@ -2788,6 +2792,263 @@ async fn test_high_priority_request_displaces_lower_priority_when_queue_full() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn displaced_task_remains_queryable() {
|
||||||
|
let manager = HealManager::new(
|
||||||
|
Arc::new(MockStorage),
|
||||||
|
Some(HealConfig {
|
||||||
|
queue_size: 1,
|
||||||
|
..HealConfig::default()
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
let mut displaced = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "displaced-bucket".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
displaced.id = "displaced-task".to_string();
|
||||||
|
let displaced_id = displaced.id.clone();
|
||||||
|
manager
|
||||||
|
.submit_heal_request(displaced)
|
||||||
|
.await
|
||||||
|
.expect("displaced request should queue");
|
||||||
|
|
||||||
|
let successor = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "successor-bucket".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::High,
|
||||||
|
);
|
||||||
|
manager
|
||||||
|
.submit_heal_request(successor)
|
||||||
|
.await
|
||||||
|
.expect("successor should displace low work");
|
||||||
|
|
||||||
|
let report = manager
|
||||||
|
.get_task_report(&displaced_id)
|
||||||
|
.await
|
||||||
|
.expect("displaced report should remain queryable");
|
||||||
|
assert!(matches!(report.status, HealTaskStatus::Failed { ref error } if error.contains("reason=displaced")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn displaced_archive_failure_keeps_queryable_terminal() {
|
||||||
|
let manager = HealManager::new(Arc::new(MockStorage), None);
|
||||||
|
let mut request = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "archive-failure".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
request.id = "archive-failure-task".to_string();
|
||||||
|
let request_id = request.id.clone();
|
||||||
|
// The synchronous sidecar is the authoritative fallback when the normal
|
||||||
|
// completed-task archive has no entry (the failure window that must not
|
||||||
|
// turn an Accepted ID into NotFound).
|
||||||
|
record_displaced_terminal(&manager.displaced_terminals, &request);
|
||||||
|
assert!(manager.completed_heals.lock().await.is_empty());
|
||||||
|
assert!(matches!(
|
||||||
|
manager.get_task_status(&request_id).await,
|
||||||
|
Ok(HealTaskStatus::Failed { error }) if error.contains("reason=displaced")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn scheduler_retry_displacement_keeps_evicted_task_queryable() {
|
||||||
|
let manager = Arc::new(HealManager::new(
|
||||||
|
Arc::new(MockStorage),
|
||||||
|
Some(HealConfig {
|
||||||
|
queue_size: 1,
|
||||||
|
event_driven_scheduler_enable: false,
|
||||||
|
..HealConfig::default()
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
let mut retry_request = HealRequest::object("retry-transition".to_string(), "object".to_string(), None);
|
||||||
|
retry_request.priority = HealPriority::High;
|
||||||
|
let retry_id = retry_request.id.clone();
|
||||||
|
manager
|
||||||
|
.submit_heal_request(retry_request)
|
||||||
|
.await
|
||||||
|
.expect("retry request should queue");
|
||||||
|
|
||||||
|
// Process exactly one queue cycle so the retry task is spawned without a
|
||||||
|
// background scheduler consuming the filler request before the retry wakes.
|
||||||
|
process_manager_queue_once(&manager).await;
|
||||||
|
tokio::time::timeout(Duration::from_secs(1), async {
|
||||||
|
loop {
|
||||||
|
if manager.retrying_heals.lock().await.contains_key(&retry_id) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tokio::task::yield_now().await;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("retry request should enter backoff");
|
||||||
|
|
||||||
|
let filler = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "retry-displaced-filler".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
let filler_id = filler.id.clone();
|
||||||
|
manager
|
||||||
|
.submit_heal_request(filler)
|
||||||
|
.await
|
||||||
|
.expect("filler request should occupy the queue");
|
||||||
|
|
||||||
|
tokio::time::timeout(Duration::from_secs(5), async {
|
||||||
|
loop {
|
||||||
|
if matches!(
|
||||||
|
manager.get_task_status(&filler_id).await,
|
||||||
|
Ok(HealTaskStatus::Failed { ref error }) if error.contains("reason=displaced")
|
||||||
|
) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("retry admission should displace the filler request");
|
||||||
|
assert_eq!(manager.get_queue_length().await, 1);
|
||||||
|
assert_eq!(
|
||||||
|
manager.get_task_status(&retry_id).await.expect("retry should be queued"),
|
||||||
|
HealTaskStatus::Pending
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn concurrent_displacers_produce_one_terminal_generation() {
|
||||||
|
let manager = Arc::new(HealManager::new(
|
||||||
|
Arc::new(MockStorage),
|
||||||
|
Some(HealConfig {
|
||||||
|
queue_size: 1,
|
||||||
|
..HealConfig::default()
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
let mut displaced = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "concurrent-displaced".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
displaced.id = "concurrent-displaced-task".to_string();
|
||||||
|
let displaced_id = displaced.id.clone();
|
||||||
|
manager
|
||||||
|
.submit_heal_request(displaced)
|
||||||
|
.await
|
||||||
|
.expect("initial request should queue");
|
||||||
|
|
||||||
|
let first = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "concurrent-successor-a".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::High,
|
||||||
|
);
|
||||||
|
let second = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "concurrent-successor-b".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::High,
|
||||||
|
);
|
||||||
|
let (first_result, second_result) = tokio::join!(manager.submit_heal_request(first), manager.submit_heal_request(second));
|
||||||
|
let accepted = [&first_result, &second_result]
|
||||||
|
.into_iter()
|
||||||
|
.filter(|result| matches!(result, Ok(HealAdmissionResult::Accepted)))
|
||||||
|
.count();
|
||||||
|
assert_eq!(accepted, 1, "exactly one concurrent displacer should win the full queue");
|
||||||
|
assert!(
|
||||||
|
first_result.is_ok() && second_result.is_ok(),
|
||||||
|
"the losing request should receive a typed Full result"
|
||||||
|
);
|
||||||
|
let terminals = lock_displaced_terminals(&manager.displaced_terminals);
|
||||||
|
assert_eq!(terminals.len(), 1);
|
||||||
|
assert!(terminals.contains_key(&displaced_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn successor_chain_is_bounded_and_authorized() {
|
||||||
|
let manager = HealManager::new(
|
||||||
|
Arc::new(MockStorage),
|
||||||
|
Some(HealConfig {
|
||||||
|
queue_size: 1,
|
||||||
|
..HealConfig::default()
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
let mut original = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "authorized-original".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
original.id = "authorized-original-task".to_string();
|
||||||
|
let original_id = original.id.clone();
|
||||||
|
manager.submit_heal_request(original).await.expect("original should queue");
|
||||||
|
let mut duplicate = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "authorized-original".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
duplicate.id = "authorized-duplicate-task".to_string();
|
||||||
|
let duplicate_id = duplicate.id.clone();
|
||||||
|
manager
|
||||||
|
.submit_heal_request(duplicate)
|
||||||
|
.await
|
||||||
|
.expect("same-target duplicate should merge");
|
||||||
|
let successor = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "authorized-successor".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::High,
|
||||||
|
);
|
||||||
|
let successor_id = successor.id.clone();
|
||||||
|
manager.submit_heal_request(successor).await.expect("successor should queue");
|
||||||
|
assert!(manager.task_aliases.lock().await.is_empty());
|
||||||
|
assert!(matches!(manager.get_task_status(&original_id).await, Ok(HealTaskStatus::Failed { .. })));
|
||||||
|
assert!(matches!(manager.get_task_status(&duplicate_id).await, Ok(HealTaskStatus::Failed { .. })));
|
||||||
|
assert_eq!(
|
||||||
|
manager
|
||||||
|
.get_task_status(&successor_id)
|
||||||
|
.await
|
||||||
|
.expect("successor should remain queued"),
|
||||||
|
HealTaskStatus::Pending
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn displaced_terminal_expires_after_bounded_ttl() {
|
||||||
|
let manager = HealManager::new(Arc::new(MockStorage), None);
|
||||||
|
let mut request = HealRequest::new(
|
||||||
|
HealType::Bucket {
|
||||||
|
bucket: "expires".to_string(),
|
||||||
|
},
|
||||||
|
HealOptions::default(),
|
||||||
|
HealPriority::Low,
|
||||||
|
);
|
||||||
|
request.id = "expires-task".to_string();
|
||||||
|
let request_id = request.id.clone();
|
||||||
|
record_displaced_terminal(&manager.displaced_terminals, &request);
|
||||||
|
{
|
||||||
|
let mut terminals = lock_displaced_terminals(&manager.displaced_terminals);
|
||||||
|
let entry =
|
||||||
|
Arc::get_mut(terminals.get_mut(&request_id).expect("terminal should be retained")).expect("test owns terminal entry");
|
||||||
|
entry.completed_at = SystemTime::now() - KEEP_HEAL_TASK_STATUS_DURATION - Duration::from_secs(1);
|
||||||
|
}
|
||||||
|
assert!(matches!(manager.get_task_status(&request_id).await, Err(Error::TaskNotFound { .. })));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_displacing_registered_mrf_task_drops_notice_ownership() {
|
async fn test_displacing_registered_mrf_task_drops_notice_ownership() {
|
||||||
let storage: Arc<dyn HealStorageAPI> = Arc::new(MockStorage);
|
let storage: Arc<dyn HealStorageAPI> = Arc::new(MockStorage);
|
||||||
|
|||||||
@@ -722,6 +722,10 @@ pub struct DeleteVersionsResponse {
|
|||||||
pub errors: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
pub errors: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
||||||
#[prost(message, optional, tag = "3")]
|
#[prost(message, optional, tag = "3")]
|
||||||
pub error: ::core::option::Option<Error>,
|
pub error: ::core::option::Option<Error>,
|
||||||
|
/// Senders dual-write the legacy strings and typed entries. Receivers prefer typed entries
|
||||||
|
/// when present and fall back to strings for peers that predate this field. Code zero means success.
|
||||||
|
#[prost(message, repeated, tag = "4")]
|
||||||
|
pub item_errors: ::prost::alloc::vec::Vec<Error>,
|
||||||
}
|
}
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
||||||
pub struct ReadMultipleRequest {
|
pub struct ReadMultipleRequest {
|
||||||
|
|||||||
@@ -493,6 +493,9 @@ message DeleteVersionsResponse {
|
|||||||
bool success = 1;
|
bool success = 1;
|
||||||
repeated string errors = 2;
|
repeated string errors = 2;
|
||||||
optional Error error = 3;
|
optional Error error = 3;
|
||||||
|
// Senders dual-write the legacy strings and typed entries. Receivers prefer typed entries
|
||||||
|
// when present and fall back to strings for peers that predate this field. Code zero means success.
|
||||||
|
repeated Error item_errors = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ReadMultipleRequest {
|
message ReadMultipleRequest {
|
||||||
|
|||||||
@@ -125,6 +125,34 @@ pub(crate) async fn read_config_with_revision<S: ScannerObjectIO>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read only the object revision without materializing its body.
|
||||||
|
pub(crate) async fn read_config_revision<S: ScannerObjectIO>(store: Arc<S>, path: &str) -> StorageResult<DataUsageCacheRevision> {
|
||||||
|
match store
|
||||||
|
.get_object_reader(
|
||||||
|
RUSTFS_META_BUCKET,
|
||||||
|
path,
|
||||||
|
None,
|
||||||
|
HeaderMap::new(),
|
||||||
|
&ObjectOptions {
|
||||||
|
no_lock: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(reader) => reader
|
||||||
|
.object_info
|
||||||
|
.etag
|
||||||
|
.filter(|etag| !etag.is_empty())
|
||||||
|
.map(DataUsageCacheRevision::Etag)
|
||||||
|
.ok_or_else(|| StorageError::other(format!("scanner config object {path} has no ETag"))),
|
||||||
|
Err(Error::FileNotFound | Error::VolumeNotFound | Error::ObjectNotFound(_, _) | Error::BucketNotFound(_)) => {
|
||||||
|
Ok(DataUsageCacheRevision::Missing)
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct DataUsageCacheRevisions {
|
pub(crate) struct DataUsageCacheRevisions {
|
||||||
main: DataUsageCacheRevision,
|
main: DataUsageCacheRevision,
|
||||||
@@ -146,6 +174,11 @@ pub static LEGACY_DATA_USAGE_OBJ_NAME_PATH: LazyLock<String> =
|
|||||||
pub static DATA_USAGE_BLOOM_NAME_PATH: LazyLock<String> =
|
pub static DATA_USAGE_BLOOM_NAME_PATH: LazyLock<String> =
|
||||||
LazyLock::new(|| format!("{BUCKET_META_PREFIX}{SLASH_SEPARATOR}{DATA_USAGE_BLOOM_NAME}"));
|
LazyLock::new(|| format!("{BUCKET_META_PREFIX}{SLASH_SEPARATOR}{DATA_USAGE_BLOOM_NAME}"));
|
||||||
|
|
||||||
|
/// Durable companion object for a cycle-state object which cannot be decoded.
|
||||||
|
/// The primary object is deliberately never replaced or deleted by recovery.
|
||||||
|
pub static DATA_USAGE_BLOOM_RECOVERY_PATH: LazyLock<String> =
|
||||||
|
LazyLock::new(|| format!("{}.recovery-required.json", DATA_USAGE_BLOOM_NAME_PATH.as_str()));
|
||||||
|
|
||||||
pub static BACKGROUND_HEAL_INFO_PATH: LazyLock<String> =
|
pub static BACKGROUND_HEAL_INFO_PATH: LazyLock<String> =
|
||||||
LazyLock::new(|| format!("{BUCKET_META_PREFIX}{SLASH_SEPARATOR}.background-heal.json"));
|
LazyLock::new(|| format!("{BUCKET_META_PREFIX}{SLASH_SEPARATOR}.background-heal.json"));
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ impl DataUsageCache {
|
|||||||
let loaded = Self::load_cache(store.clone(), name).await?;
|
let loaded = Self::load_cache(store.clone(), name).await?;
|
||||||
let backup = match loaded.backup_revision {
|
let backup = match loaded.backup_revision {
|
||||||
Some(revision) => Some(revision),
|
Some(revision) => Some(revision),
|
||||||
None => match Self::revision_for_path(store, &backup_path).await {
|
None => match read_config_revision(store, &backup_path).await {
|
||||||
Ok(revision) => Some(revision),
|
Ok(revision) => Some(revision),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
counter!(METRIC_CACHE_BACKUP_REVISION_FAILURE_TOTAL).increment(1);
|
counter!(METRIC_CACHE_BACKUP_REVISION_FAILURE_TOTAL).increment(1);
|
||||||
@@ -336,33 +336,6 @@ impl DataUsageCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn revision_for_path<S: ScannerObjectIO>(store: Arc<S>, path: &str) -> StorageResult<DataUsageCacheRevision> {
|
|
||||||
match store
|
|
||||||
.get_object_reader(
|
|
||||||
RUSTFS_META_BUCKET,
|
|
||||||
path,
|
|
||||||
None,
|
|
||||||
HeaderMap::new(),
|
|
||||||
&ObjectOptions {
|
|
||||||
no_lock: true,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(reader) => reader
|
|
||||||
.object_info
|
|
||||||
.etag
|
|
||||||
.filter(|etag| !etag.is_empty())
|
|
||||||
.map(DataUsageCacheRevision::Etag)
|
|
||||||
.ok_or_else(|| StorageError::other(format!("scanner cache object {path} has no ETag"))),
|
|
||||||
Err(Error::FileNotFound | Error::VolumeNotFound | Error::ObjectNotFound(_, _) | Error::BucketNotFound(_)) => {
|
|
||||||
Ok(DataUsageCacheRevision::Missing)
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn cache_save_timeout() -> Duration {
|
pub(super) fn cache_save_timeout() -> Duration {
|
||||||
crate::runtime_config::scanner_cache_save_timeout()
|
crate::runtime_config::scanner_cache_save_timeout()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,10 @@ pub use remote_scanner::{
|
|||||||
};
|
};
|
||||||
pub use runtime_config::{apply_scanner_runtime_config, scanner_runtime_config_status, validate_scanner_runtime_config};
|
pub use runtime_config::{apply_scanner_runtime_config, scanner_runtime_config_status, validate_scanner_runtime_config};
|
||||||
pub use rustfs_common::last_minute;
|
pub use rustfs_common::last_minute;
|
||||||
pub use scanner::{ScannerCycleScheduleStatus, init_data_scanner, scanner_cycle_schedule_status, scanner_topology_digest};
|
pub use scanner::{
|
||||||
|
ScannerCycleRecoveryMarker, ScannerCycleRecoveryStatus, ScannerCycleScheduleStatus, init_data_scanner,
|
||||||
|
reset_scanner_cycle_recovery, scanner_cycle_recovery_status, scanner_cycle_schedule_status, scanner_topology_digest,
|
||||||
|
};
|
||||||
pub use scanner_io::{
|
pub use scanner_io::{
|
||||||
ScannerDirtyUsageAckError, ScannerDirtyUsageState, acknowledge_dirty_usage_generation, clear_dirty_usage_bucket,
|
ScannerDirtyUsageAckError, ScannerDirtyUsageState, acknowledge_dirty_usage_generation, clear_dirty_usage_bucket,
|
||||||
record_dirty_usage_bucket, record_scanner_maintenance_change, scanner_activity_epoch, scanner_dirty_usage_state,
|
record_dirty_usage_bucket, record_scanner_maintenance_change, scanner_activity_epoch, scanner_dirty_usage_state,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use std::sync::{Arc, LazyLock, RwLock};
|
|||||||
|
|
||||||
use crate::data_usage_define::{
|
use crate::data_usage_define::{
|
||||||
BACKGROUND_HEAL_INFO_PATH, DATA_USAGE_BLOOM_NAME_PATH, DATA_USAGE_OBJ_NAME_PATH, DATA_USAGE_OBSERVED_OBJ_NAME_PATH,
|
BACKGROUND_HEAL_INFO_PATH, DATA_USAGE_BLOOM_NAME_PATH, DATA_USAGE_OBJ_NAME_PATH, DATA_USAGE_OBSERVED_OBJ_NAME_PATH,
|
||||||
DataUsageCache, DataUsageCacheRevision, LEGACY_DATA_USAGE_OBJ_NAME_PATH, read_config_with_revision,
|
DataUsageCache, DataUsageCacheRevision, LEGACY_DATA_USAGE_OBJ_NAME_PATH, read_config_revision, read_config_with_revision,
|
||||||
};
|
};
|
||||||
use crate::runtime_config::{
|
use crate::runtime_config::{
|
||||||
ScannerRuntimeConfig, ScannerRuntimeConfigSource, refresh_scanner_runtime_config_from_global, scanner_bitrot_cycle,
|
ScannerRuntimeConfig, ScannerRuntimeConfigSource, refresh_scanner_runtime_config_from_global, scanner_bitrot_cycle,
|
||||||
@@ -55,9 +55,7 @@ use rustfs_data_usage::observed_data_usage_is_newer;
|
|||||||
use rustfs_lock::NamespaceLockGuard;
|
use rustfs_lock::NamespaceLockGuard;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest as _, Sha256};
|
use sha2::{Digest as _, Sha256};
|
||||||
#[cfg(test)]
|
use tokio::sync::{Notify, mpsc};
|
||||||
use tokio::sync::Notify;
|
|
||||||
use tokio::sync::mpsc;
|
|
||||||
use tokio::time::{Duration, Instant};
|
use tokio::time::{Duration, Instant};
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tokio_util::task::AbortOnDropHandle;
|
use tokio_util::task::AbortOnDropHandle;
|
||||||
@@ -105,6 +103,13 @@ const CLEAN_IDLE_BACKOFF_FACTOR: u32 = 2;
|
|||||||
/// unavailable peer cannot drive a tight retry loop.
|
/// unavailable peer cannot drive a tight retry loop.
|
||||||
const SCANNER_RETRY_BASE_INTERVAL: Duration = Duration::from_secs(5);
|
const SCANNER_RETRY_BASE_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
const SCANNER_RETRY_MAX_INTERVAL: Duration = Duration::from_secs(30 * 60);
|
const SCANNER_RETRY_MAX_INTERVAL: Duration = Duration::from_secs(30 * 60);
|
||||||
|
/// A transient backend outage remains self-healing after the short retry
|
||||||
|
/// budget is exhausted, but the probe is intentionally sparse until storage
|
||||||
|
/// recovers or an operator reset wakes the scanner.
|
||||||
|
const SCANNER_CYCLE_RECOVERY_PAUSED_INTERVAL: Duration = Duration::from_secs(5 * 60);
|
||||||
|
/// Permanent recovery states still get a sparse status probe so a reset that
|
||||||
|
/// races the wait registration cannot leave the scanner asleep forever.
|
||||||
|
const SCANNER_CYCLE_RECOVERY_BLOCKED_PROBE_INTERVAL: Duration = Duration::from_secs(5 * 60);
|
||||||
const SCANNER_LEADER_LOCK_POLL_INTERVAL: Duration = Duration::from_secs(1);
|
const SCANNER_LEADER_LOCK_POLL_INTERVAL: Duration = Duration::from_secs(1);
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
const SCANNER_LOCK_LOSS_SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(30);
|
const SCANNER_LOCK_LOSS_SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
@@ -126,6 +131,12 @@ type ScannerCycleStatePersistTestHook = (u64, Arc<Notify>);
|
|||||||
static SCANNER_CYCLE_STATE_PERSIST_TEST_HOOK: LazyLock<StdMutex<Option<ScannerCycleStatePersistTestHook>>> =
|
static SCANNER_CYCLE_STATE_PERSIST_TEST_HOOK: LazyLock<StdMutex<Option<ScannerCycleStatePersistTestHook>>> =
|
||||||
LazyLock::new(|| StdMutex::new(None));
|
LazyLock::new(|| StdMutex::new(None));
|
||||||
|
|
||||||
|
static SCANNER_CYCLE_RECOVERY_WAKE: LazyLock<Notify> = LazyLock::new(Notify::new);
|
||||||
|
|
||||||
|
pub(super) fn notify_scanner_cycle_recovery_wake() {
|
||||||
|
SCANNER_CYCLE_RECOVERY_WAKE.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
struct ScannerCycleStatePersistTestHookGuard;
|
struct ScannerCycleStatePersistTestHookGuard;
|
||||||
|
|
||||||
@@ -577,19 +588,21 @@ pub async fn init_data_scanner(ctx: CancellationToken, storeapi: Arc<ECStore>) {
|
|||||||
tokio::time::sleep(sleep_time).await;
|
tokio::time::sleep(sleep_time).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut transient_backoff = ScannerRetryBackoff::default();
|
||||||
|
let mut recovery_retry_count = 0_u32;
|
||||||
loop {
|
loop {
|
||||||
if ctx_clone.is_cancelled() {
|
if ctx_clone.is_cancelled() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = run_data_scanner_with_maintenance_state(
|
let run_result = run_data_scanner_with_maintenance_state(
|
||||||
ctx_clone.clone(),
|
ctx_clone.clone(),
|
||||||
storeapi_clone.clone(),
|
storeapi_clone.clone(),
|
||||||
startup_features,
|
startup_features,
|
||||||
startup_maintenance_generation,
|
startup_maintenance_generation,
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
{
|
if let Err(e) = &run_result {
|
||||||
error!(
|
error!(
|
||||||
target: "rustfs::scanner",
|
target: "rustfs::scanner",
|
||||||
event = EVENT_SCANNER_CYCLE_STATE,
|
event = EVENT_SCANNER_CYCLE_STATE,
|
||||||
@@ -600,11 +613,52 @@ pub async fn init_data_scanner(ctx: CancellationToken, storeapi: Arc<ECStore>) {
|
|||||||
"Scanner runtime iteration failed"
|
"Scanner runtime iteration failed"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let recovery_status = scanner_cycle_recovery_status();
|
||||||
|
if recovery_status.retryable {
|
||||||
|
recovery_retry_count = recovery_retry_count.saturating_add(1);
|
||||||
|
let _ = record_scanner_cycle_recovery_retry(recovery_retry_count);
|
||||||
|
} else {
|
||||||
|
recovery_retry_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let recovery_status = scanner_cycle_recovery_status();
|
||||||
|
if recovery_status.state == "paused" {
|
||||||
|
transient_backoff.record_retryable_cycle(false);
|
||||||
|
tokio::select! {
|
||||||
|
_ = ctx_clone.cancelled() => break,
|
||||||
|
_ = SCANNER_CYCLE_RECOVERY_WAKE.notified() => {},
|
||||||
|
_ = tokio::time::sleep(SCANNER_CYCLE_RECOVERY_PAUSED_INTERVAL) => {},
|
||||||
|
}
|
||||||
|
recovery_retry_count = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if !recovery_status.retryable
|
||||||
|
&& matches!(recovery_status.state.as_str(), "blocked" | "recovery-required" | "cleanup-pending")
|
||||||
|
{
|
||||||
|
transient_backoff.record_retryable_cycle(false);
|
||||||
|
tokio::select! {
|
||||||
|
_ = ctx_clone.cancelled() => break,
|
||||||
|
_ = SCANNER_CYCLE_RECOVERY_WAKE.notified() => {},
|
||||||
|
_ = tokio::time::sleep(SCANNER_CYCLE_RECOVERY_BLOCKED_PROBE_INTERVAL) => {},
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let retry_delay = if recovery_status.retryable || run_result.is_err() {
|
||||||
|
transient_backoff.record_retryable_cycle(true);
|
||||||
|
transient_backoff
|
||||||
|
.retry_interval(scanner_cycle_interval())
|
||||||
|
.unwrap_or(SCANNER_RETRY_BASE_INTERVAL)
|
||||||
|
} else {
|
||||||
|
transient_backoff.record_retryable_cycle(false);
|
||||||
|
randomized_cycle_delay()
|
||||||
|
};
|
||||||
// Backoff before retrying after lock contention or scanner-level failures.
|
// Backoff before retrying after lock contention or scanner-level failures.
|
||||||
// Keep this cancellation-aware so shutdown is not delayed by backoff sleep.
|
// Keep this cancellation-aware so shutdown is not delayed by backoff sleep.
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = ctx_clone.cancelled() => break,
|
_ = ctx_clone.cancelled() => break,
|
||||||
_ = tokio::time::sleep(randomized_cycle_delay()) => {}
|
_ = SCANNER_CYCLE_RECOVERY_WAKE.notified() => {},
|
||||||
|
_ = tokio::time::sleep(retry_delay) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1711,40 +1765,22 @@ async fn run_data_scanner_with_maintenance_state(
|
|||||||
observe_scanner_activity(&storeapi, distributed, &mut scanner_activity_seen).await;
|
observe_scanner_activity(&storeapi, distributed, &mut scanner_activity_seen).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (buf, mut cycle_revision) = match read_config_with_revision(storeapi.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str()).await {
|
let (mut cycle_info, mut leader_epoch, mut cycle_revision) =
|
||||||
Ok((buf, revision)) => (buf.unwrap_or_default(), revision),
|
match load_scanner_cycle_state_for_startup(storeapi.clone()).await {
|
||||||
Err(err) => {
|
ScannerCycleStateStartup::Ready {
|
||||||
error!(
|
cycle,
|
||||||
target: "rustfs::scanner",
|
leader_epoch,
|
||||||
event = EVENT_SCANNER_PERSIST_STATE,
|
revision,
|
||||||
component = LOG_COMPONENT_SCANNER,
|
} => (cycle, leader_epoch, revision),
|
||||||
subsystem = LOG_SUBSYSTEM_RUNTIME,
|
ScannerCycleStateStartup::Blocked => {
|
||||||
path = %&*DATA_USAGE_BLOOM_NAME_PATH,
|
global_metrics().set_cycle(None).await;
|
||||||
state = "revision_load_failed",
|
return Ok(());
|
||||||
error = %err,
|
}
|
||||||
"Scanner cycle state revision load failed"
|
ScannerCycleStateStartup::Transient(err) => {
|
||||||
);
|
global_metrics().set_cycle(None).await;
|
||||||
global_metrics().set_cycle(None).await;
|
return Err(err);
|
||||||
return Ok(());
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
let (mut cycle_info, mut leader_epoch) = match decode_scanner_cycle_state_for_startup(&buf) {
|
|
||||||
Ok(state) => state,
|
|
||||||
Err(err) => {
|
|
||||||
error!(
|
|
||||||
target: "rustfs::scanner",
|
|
||||||
event = EVENT_SCANNER_PERSIST_STATE,
|
|
||||||
component = LOG_COMPONENT_SCANNER,
|
|
||||||
subsystem = LOG_SUBSYSTEM_RUNTIME,
|
|
||||||
path = %&*DATA_USAGE_BLOOM_NAME_PATH,
|
|
||||||
state = "cycle_decode_failed",
|
|
||||||
error = %err,
|
|
||||||
"Scanner stopped because persisted cycle state is invalid"
|
|
||||||
);
|
|
||||||
global_metrics().set_cycle(None).await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let usage_floor = match persisted_usage_floor(storeapi.clone()).await {
|
let usage_floor = match persisted_usage_floor(storeapi.clone()).await {
|
||||||
Ok(floor) => floor,
|
Ok(floor) => floor,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -2396,7 +2432,12 @@ pub(crate) use activity::{
|
|||||||
pub(crate) use activity::{ScannerCycleOutcome, scanner_cycle_outcome_with_pending_maintenance};
|
pub(crate) use activity::{ScannerCycleOutcome, scanner_cycle_outcome_with_pending_maintenance};
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) use cycle_state::encode_scanner_cycle_fence_for_test;
|
pub(crate) use cycle_state::encode_scanner_cycle_fence_for_test;
|
||||||
pub(crate) use cycle_state::{current_scanner_leader_epoch, decode_persisted_scanner_cycle_fence};
|
pub use cycle_state::{
|
||||||
|
ScannerCycleRecoveryMarker, ScannerCycleRecoveryStatus, reset_scanner_cycle_recovery, scanner_cycle_recovery_status,
|
||||||
|
};
|
||||||
|
pub(crate) use cycle_state::{
|
||||||
|
current_scanner_leader_epoch, decode_persisted_scanner_cycle_fence, load_scanner_cycle_state_for_startup,
|
||||||
|
};
|
||||||
pub use heal_info::{BackgroundHealInfo, read_background_heal_info, save_background_heal_info};
|
pub use heal_info::{BackgroundHealInfo, read_background_heal_info, save_background_heal_info};
|
||||||
pub use usage_store::store_data_usage_in_backend;
|
pub use usage_store::store_data_usage_in_backend;
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -15,11 +15,12 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::EcstoreResult;
|
use crate::EcstoreResult;
|
||||||
use crate::{
|
use crate::{
|
||||||
Endpoint, EndpointServerPools, Endpoints, InstanceContext, PoolEndpoints, ScannerGetObjectReader as GetObjectReader,
|
DATA_USAGE_BLOOM_RECOVERY_PATH, Endpoint, EndpointServerPools, Endpoints, InstanceContext, PoolEndpoints,
|
||||||
ScannerObjectInfo as ObjectInfo, ScannerObjectOptions as ObjectOptions, ScannerPutObjReader as PutObjReader,
|
ScannerGetObjectReader as GetObjectReader, ScannerObjectInfo as ObjectInfo, ScannerObjectOptions as ObjectOptions,
|
||||||
init_bucket_metadata_sys_for_scanner_tests, init_ecstore_config_for_scanner_tests, init_local_disks_with_instance_ctx,
|
ScannerPutObjReader as PutObjReader, init_bucket_metadata_sys_for_scanner_tests, init_ecstore_config_for_scanner_tests,
|
||||||
|
init_local_disks_with_instance_ctx,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
use temp_env::{with_var, with_var_unset};
|
use temp_env::{with_var, with_var_unset};
|
||||||
@@ -290,6 +291,15 @@ async fn cycle_budget_deadline_handler_fences_and_releases_guard() {
|
|||||||
global_metrics().set_cycle(None).await;
|
global_metrics().set_cycle(None).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn scanner_cycle_recovery_wake_survives_wait_registration_race() {
|
||||||
|
notify_scanner_cycle_recovery_wake();
|
||||||
|
|
||||||
|
tokio::time::timeout(Duration::from_secs(1), SCANNER_CYCLE_RECOVERY_WAKE.notified())
|
||||||
|
.await
|
||||||
|
.expect("recovery wake should retain a permit until the waiter registers");
|
||||||
|
}
|
||||||
|
|
||||||
struct ScannerDefaultSpeedGuard;
|
struct ScannerDefaultSpeedGuard;
|
||||||
|
|
||||||
impl ScannerDefaultSpeedGuard {
|
impl ScannerDefaultSpeedGuard {
|
||||||
@@ -324,6 +334,7 @@ impl Drop for ScannerDefaultCycleGuard {
|
|||||||
struct MemoryConfigStore {
|
struct MemoryConfigStore {
|
||||||
objects: Mutex<HashMap<String, Vec<u8>>>,
|
objects: Mutex<HashMap<String, Vec<u8>>>,
|
||||||
revisions: Mutex<HashMap<String, u64>>,
|
revisions: Mutex<HashMap<String, u64>>,
|
||||||
|
non_regular_objects: Mutex<HashSet<String>>,
|
||||||
fail_put_number: Mutex<HashMap<String, usize>>,
|
fail_put_number: Mutex<HashMap<String, usize>>,
|
||||||
object_not_found_put_number: Mutex<HashMap<String, usize>>,
|
object_not_found_put_number: Mutex<HashMap<String, usize>>,
|
||||||
error_after_commit_put_number: Mutex<HashMap<String, usize>>,
|
error_after_commit_put_number: Mutex<HashMap<String, usize>>,
|
||||||
@@ -364,12 +375,16 @@ impl crate::storage_api::scanner_io::ObjectIO for MemoryConfigStore {
|
|||||||
.get(&key)
|
.get(&key)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(EcstoreError::FileNotFound)?;
|
.ok_or(EcstoreError::FileNotFound)?;
|
||||||
let revision = *self.revisions.lock().await.entry(key).or_insert(1);
|
let data_len = i64::try_from(data.len()).expect("memory test object length should fit in i64");
|
||||||
|
let revision = *self.revisions.lock().await.entry(key.clone()).or_insert(1);
|
||||||
|
let is_dir = self.non_regular_objects.lock().await.contains(&key);
|
||||||
|
|
||||||
Ok(GetObjectReader {
|
Ok(GetObjectReader {
|
||||||
stream: Box::new(Cursor::new(data)),
|
stream: Box::new(Cursor::new(data)),
|
||||||
object_info: ObjectInfo {
|
object_info: ObjectInfo {
|
||||||
etag: Some(format!("memory-{revision}")),
|
etag: Some(format!("memory-{revision}")),
|
||||||
|
size: data_len,
|
||||||
|
is_dir,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
buffered_body: None,
|
buffered_body: None,
|
||||||
@@ -993,6 +1008,840 @@ fn scanner_startup_fails_closed_on_nonempty_corrupt_cycle_state() {
|
|||||||
assert!(encode_scanner_cycle_state(&exhausted, 7).is_err());
|
assert!(encode_scanner_cycle_state(&exhausted, 7).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn corrupt_cycle_state_is_quarantined_once() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let state_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
store.objects.lock().await.insert(state_key.clone(), vec![1]);
|
||||||
|
store.revisions.lock().await.insert(state_key.clone(), 7);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store.clone()).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
let marker_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str());
|
||||||
|
let marker_data = store
|
||||||
|
.objects
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.get(&marker_key)
|
||||||
|
.cloned()
|
||||||
|
.expect("corrupt state must leave a durable recovery marker");
|
||||||
|
let marker: ScannerCycleRecoveryMarker = serde_json::from_slice(&marker_data).expect("marker should be valid JSON");
|
||||||
|
assert_eq!(marker.primary_revision, "memory-7");
|
||||||
|
assert_eq!(marker.path, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
assert_eq!(marker.quarantine_path, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str());
|
||||||
|
assert_eq!(marker.classification, "corrupt");
|
||||||
|
|
||||||
|
// A second startup sees the matching marker before consuming the poison body.
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store.clone()).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
|
||||||
|
// Replacing the primary object advances its revision; the stale marker must
|
||||||
|
// not quarantine the newer, valid state.
|
||||||
|
let cycle = CurrentCycle {
|
||||||
|
next: 9,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let encoded = encode_scanner_cycle_state(&cycle, 3).expect("valid state should encode");
|
||||||
|
store.objects.lock().await.insert(state_key.clone(), encoded);
|
||||||
|
store.revisions.lock().await.insert(state_key, 8);
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store).await,
|
||||||
|
ScannerCycleStateStartup::Ready {
|
||||||
|
cycle: CurrentCycle { next: 9, .. },
|
||||||
|
leader_epoch: 3,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn empty_cycle_state_object_is_quarantined_as_corrupt() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let state_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
store.objects.lock().await.insert(state_key.clone(), Vec::new());
|
||||||
|
store.revisions.lock().await.insert(state_key, 6);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
assert_eq!(scanner_cycle_recovery_status().classification.as_deref(), Some("corrupt"));
|
||||||
|
assert!(
|
||||||
|
scanner_cycle_recovery_status()
|
||||||
|
.reason
|
||||||
|
.as_deref()
|
||||||
|
.is_some_and(|reason| reason.contains("empty"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn future_cycle_state_schema_is_recovery_required() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let state_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
let mut future = 17_u64.to_le_bytes().to_vec();
|
||||||
|
future.extend_from_slice(b"RSCYC999");
|
||||||
|
future.extend_from_slice(&4_u64.to_le_bytes());
|
||||||
|
future.extend_from_slice(&[0x90]);
|
||||||
|
store.objects.lock().await.insert(state_key.clone(), future);
|
||||||
|
store.revisions.lock().await.insert(state_key, 13);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
assert_eq!(scanner_cycle_recovery_status().classification.as_deref(), Some("future_schema"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn concurrent_leaders_cannot_quarantine_newer_cycle_state() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let state_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
store.objects.lock().await.insert(state_key.clone(), vec![1]);
|
||||||
|
store.revisions.lock().await.insert(state_key, 4);
|
||||||
|
|
||||||
|
let (first, second) = tokio::join!(
|
||||||
|
load_scanner_cycle_state_for_startup(store.clone()),
|
||||||
|
load_scanner_cycle_state_for_startup(store.clone()),
|
||||||
|
);
|
||||||
|
assert!(matches!(first, ScannerCycleStateStartup::Blocked));
|
||||||
|
assert!(matches!(second, ScannerCycleStateStartup::Blocked));
|
||||||
|
|
||||||
|
let marker_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str());
|
||||||
|
let marker_data = store
|
||||||
|
.objects
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.get(&marker_key)
|
||||||
|
.cloned()
|
||||||
|
.expect("one contender must publish the recovery marker");
|
||||||
|
let marker: ScannerCycleRecoveryMarker = serde_json::from_slice(&marker_data).expect("marker should decode");
|
||||||
|
assert_eq!(marker.primary_revision, "memory-4");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn cleanup_pending_marker_blocks_a_rewritten_primary_after_restart() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let state_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
let marker_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str());
|
||||||
|
let encoded = encode_scanner_cycle_state(
|
||||||
|
&CurrentCycle {
|
||||||
|
next: 12,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
8,
|
||||||
|
)
|
||||||
|
.expect("valid state should encode");
|
||||||
|
store.objects.lock().await.insert(state_key.clone(), encoded);
|
||||||
|
store.revisions.lock().await.insert(state_key, 22);
|
||||||
|
let marker = ScannerCycleRecoveryMarker {
|
||||||
|
schema_version: 1,
|
||||||
|
primary_revision: "memory-21".to_string(),
|
||||||
|
generation: 11,
|
||||||
|
leader_epoch: 7,
|
||||||
|
classification: "corrupt".to_string(),
|
||||||
|
first_detected_at_unix_secs: 1,
|
||||||
|
last_attempt_at_unix_secs: 2,
|
||||||
|
retry_count: 1,
|
||||||
|
reason: "reset in progress".to_string(),
|
||||||
|
path: DATA_USAGE_BLOOM_NAME_PATH.clone(),
|
||||||
|
quarantine_path: DATA_USAGE_BLOOM_RECOVERY_PATH.clone(),
|
||||||
|
state: "cleanup-pending".to_string(),
|
||||||
|
};
|
||||||
|
store
|
||||||
|
.objects
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(marker_key.clone(), serde_json::to_vec(&marker).expect("marker should encode"));
|
||||||
|
store.revisions.lock().await.insert(marker_key, 3);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
assert_eq!(scanner_cycle_recovery_status().state, "cleanup-pending");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn full_rescan_reset_accepts_unknown_marker_fields_without_trusting_cursor() {
|
||||||
|
let marker = br#"{
|
||||||
|
"schema_version": 99,
|
||||||
|
"primary_revision": "memory-7",
|
||||||
|
"generation": 9000,
|
||||||
|
"leader_epoch": 9000,
|
||||||
|
"classification": "new-future-classification",
|
||||||
|
"first_detected_at_unix_secs": 1,
|
||||||
|
"last_attempt_at_unix_secs": 2,
|
||||||
|
"retry_count": 9,
|
||||||
|
"reason": "future marker",
|
||||||
|
"path": "buckets/.bloomcycle.bin",
|
||||||
|
"quarantine_path": "buckets/.bloomcycle.bin.recovery-required.json",
|
||||||
|
"future_field": {"cursor": "untrusted"}
|
||||||
|
}"#;
|
||||||
|
let decoded =
|
||||||
|
super::cycle_state::decode_recovery_marker_for_reset(marker, &DataUsageCacheRevision::Etag("memory-3".to_string()))
|
||||||
|
.expect("full-rescan compatibility decoder should accept additive fields");
|
||||||
|
assert_eq!(decoded.primary_revision, "memory-7");
|
||||||
|
assert_eq!(decoded.classification, "future_schema");
|
||||||
|
assert_eq!(decoded.generation, 0);
|
||||||
|
assert_eq!(decoded.leader_epoch, 0);
|
||||||
|
assert_eq!(decoded.state, "blocked");
|
||||||
|
|
||||||
|
let malformed =
|
||||||
|
super::cycle_state::decode_recovery_marker_for_reset(b"{not-json", &DataUsageCacheRevision::Etag("memory-4".to_string()))
|
||||||
|
.expect("a full-rescan reset must recover even when the marker is malformed");
|
||||||
|
assert!(malformed.primary_revision.is_empty());
|
||||||
|
assert_eq!(malformed.classification, "future_schema");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rebuilds_after_malformed_marker_without_trusting_cursor() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), vec![0xff, 0x00, 0x01])
|
||||||
|
.await
|
||||||
|
.expect("corrupt cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), br#"{not-json"#.to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("full-rescan reset should recover malformed marker");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("rebuilt cycle state should remain durable");
|
||||||
|
let (cycle, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(cycle.next, 0, "reset must use the verified usage floor, not marker cursor");
|
||||||
|
assert_eq!(leader_epoch, 1);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_ignores_epoch_from_malformed_future_primary() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
let mut future_primary = vec![0; 24];
|
||||||
|
future_primary[8..16].copy_from_slice(b"RSCY9999");
|
||||||
|
future_primary[16..24].copy_from_slice(&u64::MAX.to_le_bytes());
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), future_primary)
|
||||||
|
.await
|
||||||
|
.expect("future cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), br#"{not-json"#.to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("full-rescan reset should recover malformed future state");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("rebuilt cycle state should remain durable");
|
||||||
|
let (_, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(leader_epoch, 1, "invalid persisted bytes must not raise the recovery epoch");
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn ecstore_exact_recovery_marker_delete_honors_etag() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"marker-v1".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("initial recovery marker should be persisted");
|
||||||
|
let (_, stale_revision) = read_config_with_revision(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("initial marker revision should load");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"marker-v2".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("replacement recovery marker should be persisted");
|
||||||
|
|
||||||
|
let delete_result = store
|
||||||
|
.delete_config_object(
|
||||||
|
RUSTFS_META_BUCKET,
|
||||||
|
DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(),
|
||||||
|
ObjectOptions {
|
||||||
|
http_preconditions: Some(stale_revision.preconditions()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert!(matches!(delete_result, Err(EcstoreError::PreconditionFailed)));
|
||||||
|
assert_eq!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("replacement marker should remain durable"),
|
||||||
|
b"marker-v2"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rejects_corrupt_primary_under_stale_blocked_marker() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
let corrupt_primary = vec![0xff, 0x00, 0x01];
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), corrupt_primary.clone())
|
||||||
|
.await
|
||||||
|
.expect("corrupt cycle state should be persisted");
|
||||||
|
let (_, primary_revision) = read_config_with_revision(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("primary revision should load");
|
||||||
|
let marker = ScannerCycleRecoveryMarker {
|
||||||
|
schema_version: 1,
|
||||||
|
primary_revision: "memory-stale".to_string(),
|
||||||
|
generation: 1,
|
||||||
|
leader_epoch: 1,
|
||||||
|
classification: "corrupt".to_string(),
|
||||||
|
first_detected_at_unix_secs: 1,
|
||||||
|
last_attempt_at_unix_secs: 2,
|
||||||
|
retry_count: 1,
|
||||||
|
reason: "blocked primary changed".to_string(),
|
||||||
|
path: DATA_USAGE_BLOOM_NAME_PATH.clone(),
|
||||||
|
quarantine_path: DATA_USAGE_BLOOM_RECOVERY_PATH.clone(),
|
||||||
|
state: "blocked".to_string(),
|
||||||
|
};
|
||||||
|
let marker_data = serde_json::to_vec(&marker).expect("blocked marker should encode");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), marker_data.clone())
|
||||||
|
.await
|
||||||
|
.expect("blocked marker should be persisted");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.is_err(),
|
||||||
|
"a strict marker must fail closed when its primary revision changed"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("primary should remain readable"),
|
||||||
|
corrupt_primary
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("blocked marker should remain durable"),
|
||||||
|
marker_data
|
||||||
|
);
|
||||||
|
assert!(!matches!(primary_revision, DataUsageCacheRevision::Missing));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_preserves_valid_primary_when_marker_is_malformed() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
let primary = CurrentCycle {
|
||||||
|
next: 42,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let old_primary_data = encode_scanner_cycle_state(&primary, 7).expect("valid cycle state should encode");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), old_primary_data.clone())
|
||||||
|
.await
|
||||||
|
.expect("valid cycle state should be persisted");
|
||||||
|
let (_, old_primary_revision) = read_config_with_revision(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("primary state revision should load");
|
||||||
|
let old_usage = DataUsageInfo {
|
||||||
|
scanner_epoch: Some(7),
|
||||||
|
scanner_cycle: Some(41),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let old_usage_data = serde_json::to_vec(&old_usage).expect("usage snapshot should encode");
|
||||||
|
save_config(store.clone(), DATA_USAGE_OBJ_NAME_PATH.as_str(), old_usage_data.clone())
|
||||||
|
.await
|
||||||
|
.expect("usage snapshot should be persisted");
|
||||||
|
let (_, old_usage_revision) = read_config_with_revision(store.clone(), DATA_USAGE_OBJ_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("usage snapshot revision should load");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"{not-json".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("reset should clear a stale malformed marker");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("valid primary should remain durable");
|
||||||
|
let (cycle, leader_epoch) = decode_scanner_cycle_state(&state).expect("primary cycle state should decode");
|
||||||
|
assert_eq!(cycle.next, 42, "reset must not regress an independently fenced primary");
|
||||||
|
assert_eq!(leader_epoch, 8, "reset must advance the preserved primary epoch");
|
||||||
|
let stale_primary_save = save_config_with_preconditions(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_BLOOM_NAME_PATH.as_str(),
|
||||||
|
old_primary_data,
|
||||||
|
old_primary_revision.preconditions(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert!(matches!(stale_primary_save, Err(EcstoreError::PreconditionFailed)));
|
||||||
|
let usage = read_config(store.clone(), DATA_USAGE_OBJ_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("usage epoch fence should remain durable");
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::from_slice::<DataUsageInfo>(&usage)
|
||||||
|
.expect("fenced usage should decode")
|
||||||
|
.scanner_epoch,
|
||||||
|
Some(8)
|
||||||
|
);
|
||||||
|
let stale_save = save_config_with_preconditions(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_OBJ_NAME_PATH.as_str(),
|
||||||
|
old_usage_data,
|
||||||
|
old_usage_revision.preconditions(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert!(matches!(stale_save, Err(EcstoreError::PreconditionFailed)));
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_resumes_cleanup_pending_preserved_primary() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
let completed_at = Utc::now();
|
||||||
|
let primary = CurrentCycle {
|
||||||
|
current: 3,
|
||||||
|
next: 42,
|
||||||
|
cycle_completed: vec![completed_at],
|
||||||
|
started: completed_at,
|
||||||
|
};
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_BLOOM_NAME_PATH.as_str(),
|
||||||
|
encode_scanner_cycle_state(&primary, 7).expect("valid cycle state should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("valid cycle state should be persisted");
|
||||||
|
let usage = DataUsageInfo {
|
||||||
|
scanner_epoch: Some(7),
|
||||||
|
scanner_cycle: Some(41),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_OBJ_NAME_PATH.as_str(),
|
||||||
|
serde_json::to_vec(&usage).expect("usage snapshot should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("usage snapshot should be persisted");
|
||||||
|
let marker = ScannerCycleRecoveryMarker {
|
||||||
|
schema_version: 1,
|
||||||
|
primary_revision: "memory-old".to_string(),
|
||||||
|
generation: 41,
|
||||||
|
leader_epoch: 7,
|
||||||
|
classification: "corrupt".to_string(),
|
||||||
|
first_detected_at_unix_secs: 1,
|
||||||
|
last_attempt_at_unix_secs: 2,
|
||||||
|
retry_count: 1,
|
||||||
|
reason: "reset in progress".to_string(),
|
||||||
|
path: DATA_USAGE_BLOOM_NAME_PATH.clone(),
|
||||||
|
quarantine_path: DATA_USAGE_BLOOM_RECOVERY_PATH.clone(),
|
||||||
|
state: "cleanup-pending".to_string(),
|
||||||
|
};
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(),
|
||||||
|
serde_json::to_vec(&marker).expect("marker should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("cleanup marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("reset should resume a cleanup-pending preserved primary");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("preserved cycle state should remain durable");
|
||||||
|
let (cycle, leader_epoch) = decode_scanner_cycle_state(&state).expect("cycle state should decode");
|
||||||
|
assert_eq!(cycle.current, 3, "cleanup retry must preserve the in-progress cursor");
|
||||||
|
assert_eq!(cycle.next, 42);
|
||||||
|
assert_eq!(cycle.cycle_completed, vec![completed_at]);
|
||||||
|
assert_eq!(cycle.started, completed_at);
|
||||||
|
assert_eq!(leader_epoch, 8);
|
||||||
|
let usage = read_config(store.clone(), DATA_USAGE_OBJ_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("usage epoch fence should remain durable");
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::from_slice::<DataUsageInfo>(&usage)
|
||||||
|
.expect("usage should decode")
|
||||||
|
.scanner_epoch,
|
||||||
|
Some(8)
|
||||||
|
);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rebuilds_oversized_regular_primary_with_malformed_marker() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), vec![0; 1024 * 1024 + 1])
|
||||||
|
.await
|
||||||
|
.expect("oversized cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"{not-json".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("explicit full-rescan reset should replace an oversized regular primary");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("rebuilt cycle state should remain durable");
|
||||||
|
let (cycle, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(cycle.next, 0);
|
||||||
|
assert_eq!(leader_epoch, 1);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rebuilds_oversized_primary_after_cleanup_marker() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), vec![0; 1024 * 1024 + 1])
|
||||||
|
.await
|
||||||
|
.expect("oversized cycle state should be persisted");
|
||||||
|
let (_, primary_revision) = read_config_with_revision(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("primary revision should load");
|
||||||
|
let marker = ScannerCycleRecoveryMarker {
|
||||||
|
schema_version: 1,
|
||||||
|
primary_revision: match primary_revision {
|
||||||
|
DataUsageCacheRevision::Etag(etag) => etag,
|
||||||
|
DataUsageCacheRevision::Missing => panic!("primary revision should be present"),
|
||||||
|
},
|
||||||
|
generation: 1,
|
||||||
|
leader_epoch: 1,
|
||||||
|
classification: "corrupt".to_string(),
|
||||||
|
first_detected_at_unix_secs: 1,
|
||||||
|
last_attempt_at_unix_secs: 2,
|
||||||
|
retry_count: 1,
|
||||||
|
reason: "reset in progress".to_string(),
|
||||||
|
path: DATA_USAGE_BLOOM_NAME_PATH.clone(),
|
||||||
|
quarantine_path: DATA_USAGE_BLOOM_RECOVERY_PATH.clone(),
|
||||||
|
state: "cleanup-pending".to_string(),
|
||||||
|
};
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(),
|
||||||
|
serde_json::to_vec(&marker).expect("cleanup marker should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("cleanup marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("cleanup retry should rebuild an oversized primary");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("rebuilt cycle state should remain durable");
|
||||||
|
let (cycle, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(cycle.next, 0);
|
||||||
|
assert_eq!(leader_epoch, 1);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rebuilds_with_oversized_marker() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), vec![0xff, 0x00, 0x01])
|
||||||
|
.await
|
||||||
|
.expect("corrupt cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), vec![b'x'; 64 * 1024 + 1])
|
||||||
|
.await
|
||||||
|
.expect("oversized recovery marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("full-rescan reset should recover an oversized marker");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("rebuilt cycle state should remain durable");
|
||||||
|
let (_, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(leader_epoch, 1);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rebuilds_with_empty_marker() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), vec![0xff, 0x00, 0x01])
|
||||||
|
.await
|
||||||
|
.expect("corrupt cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), Vec::new())
|
||||||
|
.await
|
||||||
|
.expect("empty recovery marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("full-rescan reset should recover an empty marker");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("rebuilt cycle state should remain durable");
|
||||||
|
let (_, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(leader_epoch, 1);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_keeps_cleanup_marker_when_preserved_epoch_is_exhausted() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
let primary = CurrentCycle {
|
||||||
|
next: 42,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_BLOOM_NAME_PATH.as_str(),
|
||||||
|
encode_scanner_cycle_state(&primary, u64::MAX).expect("valid cycle state should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("valid cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"{not-json".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
|
||||||
|
let marker = read_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("cleanup marker should remain durable");
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::from_slice::<ScannerCycleRecoveryMarker>(&marker)
|
||||||
|
.expect("cleanup marker should decode")
|
||||||
|
.state,
|
||||||
|
"cleanup-pending"
|
||||||
|
);
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rejects_preserved_epoch_that_would_be_terminal() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
let primary = CurrentCycle {
|
||||||
|
next: 42,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_BLOOM_NAME_PATH.as_str(),
|
||||||
|
encode_scanner_cycle_state(&primary, u64::MAX - 1).expect("valid cycle state should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("valid cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"{not-json".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.is_err(),
|
||||||
|
"reset must not persist the terminal leader epoch"
|
||||||
|
);
|
||||||
|
|
||||||
|
let marker = read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("cleanup marker should remain durable");
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::from_slice::<ScannerCycleRecoveryMarker>(&marker)
|
||||||
|
.expect("cleanup marker should decode")
|
||||||
|
.state,
|
||||||
|
"cleanup-pending"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rejects_usage_floor_that_would_be_terminal() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), vec![0xff, 0x00, 0x01])
|
||||||
|
.await
|
||||||
|
.expect("corrupt cycle state should be persisted");
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_OBJ_NAME_PATH.as_str(),
|
||||||
|
serde_json::to_vec(&DataUsageInfo {
|
||||||
|
scanner_epoch: Some(u64::MAX - 1),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.expect("usage floor should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("usage floor should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"{not-json".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.is_err(),
|
||||||
|
"reset must not persist the terminal leader epoch"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("recovery marker should remain durable"),
|
||||||
|
b"{not-json"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rebuilds_empty_primary_with_malformed_marker() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str(), Vec::new())
|
||||||
|
.await
|
||||||
|
.expect("empty cycle state should be persisted");
|
||||||
|
save_config(store.clone(), DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(), b"{not-json".to_vec())
|
||||||
|
.await
|
||||||
|
.expect("malformed marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("explicit full-rescan reset should replace an empty primary");
|
||||||
|
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("rebuilt cycle state should remain durable");
|
||||||
|
let (cycle, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(cycle.next, 0);
|
||||||
|
assert_eq!(leader_epoch, 1);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn full_rescan_reset_rebuilds_when_primary_cycle_state_is_missing() {
|
||||||
|
let (_temp_dir, store) = setup_scanner_cycle_store().await;
|
||||||
|
let marker = ScannerCycleRecoveryMarker {
|
||||||
|
schema_version: 1,
|
||||||
|
primary_revision: "memory-missing".to_string(),
|
||||||
|
generation: u64::MAX,
|
||||||
|
leader_epoch: u64::MAX,
|
||||||
|
classification: "corrupt".to_string(),
|
||||||
|
first_detected_at_unix_secs: 1,
|
||||||
|
last_attempt_at_unix_secs: 2,
|
||||||
|
retry_count: 0,
|
||||||
|
reason: "missing primary".to_string(),
|
||||||
|
path: DATA_USAGE_BLOOM_NAME_PATH.clone(),
|
||||||
|
quarantine_path: DATA_USAGE_BLOOM_RECOVERY_PATH.clone(),
|
||||||
|
state: "blocked".to_string(),
|
||||||
|
};
|
||||||
|
save_config(
|
||||||
|
store.clone(),
|
||||||
|
DATA_USAGE_BLOOM_RECOVERY_PATH.as_str(),
|
||||||
|
serde_json::to_vec(&marker).expect("marker should encode"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("marker should be persisted");
|
||||||
|
|
||||||
|
reset_scanner_cycle_recovery(CancellationToken::new(), store.clone())
|
||||||
|
.await
|
||||||
|
.expect("full-rescan reset should recreate missing primary");
|
||||||
|
let state = read_config(store.clone(), DATA_USAGE_BLOOM_NAME_PATH.as_str())
|
||||||
|
.await
|
||||||
|
.expect("missing primary should be rebuilt");
|
||||||
|
let (cycle, leader_epoch) = decode_scanner_cycle_state(&state).expect("rebuilt cycle state should decode");
|
||||||
|
assert_eq!(cycle.next, 0);
|
||||||
|
assert_eq!(leader_epoch, 1);
|
||||||
|
assert!(matches!(
|
||||||
|
read_config(store, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()).await,
|
||||||
|
Err(EcstoreError::ConfigNotFound)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn corrupt_cycle_state_rename_or_marker_failure_stays_recovery_required() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let state_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
let marker_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str());
|
||||||
|
store.objects.lock().await.insert(state_key.clone(), vec![1]);
|
||||||
|
store.revisions.lock().await.insert(state_key, 9);
|
||||||
|
store.fail_put_number.lock().await.insert(marker_key, 1);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store.clone()).await,
|
||||||
|
ScannerCycleStateStartup::Transient(_)
|
||||||
|
));
|
||||||
|
let status = scanner_cycle_recovery_status();
|
||||||
|
assert_eq!(status.state, "recovery-required");
|
||||||
|
assert!(status.retryable);
|
||||||
|
assert!(
|
||||||
|
store
|
||||||
|
.objects
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.contains_key(&memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn oversized_or_symlinked_cycle_state_is_rejected() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_NAME_PATH.as_str());
|
||||||
|
store.objects.lock().await.insert(key.clone(), vec![0; 1024 * 1024 + 1]);
|
||||||
|
store.revisions.lock().await.insert(key.clone(), 11);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store.clone()).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
assert_eq!(scanner_cycle_recovery_status().classification.as_deref(), Some("corrupt"));
|
||||||
|
assert!(
|
||||||
|
scanner_cycle_recovery_status()
|
||||||
|
.reason
|
||||||
|
.as_deref()
|
||||||
|
.is_some_and(|reason| reason.contains("oversized"))
|
||||||
|
);
|
||||||
|
|
||||||
|
let marker_key = memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_BLOOM_RECOVERY_PATH.as_str());
|
||||||
|
store.objects.lock().await.remove(&marker_key);
|
||||||
|
store.objects.lock().await.insert(key.clone(), vec![1]);
|
||||||
|
store.revisions.lock().await.insert(key.clone(), 12);
|
||||||
|
store.non_regular_objects.lock().await.insert(key);
|
||||||
|
// The object contract exposes a non-regular object as `is_dir`; local
|
||||||
|
// backends reject symlink/reparse entries before they become an object.
|
||||||
|
assert!(matches!(
|
||||||
|
load_scanner_cycle_state_for_startup(store).await,
|
||||||
|
ScannerCycleStateStartup::Blocked
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn scanner_startup_uses_primary_and_backup_usage_floor() {
|
async fn scanner_startup_uses_primary_and_backup_usage_floor() {
|
||||||
let store = Arc::new(MemoryConfigStore::default());
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
@@ -1025,6 +1874,31 @@ async fn scanner_startup_uses_primary_and_backup_usage_floor() {
|
|||||||
assert_eq!(epoch, 11);
|
assert_eq!(epoch, 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn scanner_usage_floor_ignores_older_backup_after_primary_epoch_fence() {
|
||||||
|
let store = Arc::new(MemoryConfigStore::default());
|
||||||
|
let backup_path = format!("{}.bkp", DATA_USAGE_OBJ_NAME_PATH.as_str());
|
||||||
|
for (path, epoch, cycle) in [(DATA_USAGE_OBJ_NAME_PATH.as_str(), 8, 100), (backup_path.as_str(), 7, 10_000)] {
|
||||||
|
store.objects.lock().await.insert(
|
||||||
|
memory_config_key(RUSTFS_META_BUCKET, path),
|
||||||
|
serde_json::to_vec(&DataUsageInfo {
|
||||||
|
scanner_epoch: Some(epoch),
|
||||||
|
scanner_cycle: Some(cycle),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.expect("usage snapshot should encode"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
persisted_usage_floor(store).await.expect("usage floor should load"),
|
||||||
|
PersistedUsageFloor {
|
||||||
|
next_cycle: 101,
|
||||||
|
leader_epoch: 8,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn scanner_startup_treats_incomplete_usage_snapshot_as_cold() {
|
fn scanner_startup_treats_incomplete_usage_snapshot_as_cold() {
|
||||||
let mut legacy = complete_usage_with_bucket_count(Some(std::time::SystemTime::now()), 1);
|
let mut legacy = complete_usage_with_bucket_count(Some(std::time::SystemTime::now()), 1);
|
||||||
@@ -1157,6 +2031,15 @@ async fn scanner_usage_floor_fails_closed_on_corrupt_or_exhausted_usage_state()
|
|||||||
|
|
||||||
assert!(persisted_usage_floor(store.clone()).await.is_err());
|
assert!(persisted_usage_floor(store.clone()).await.is_err());
|
||||||
|
|
||||||
|
store.objects.lock().await.insert(
|
||||||
|
memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_OBJ_NAME_PATH.as_str()),
|
||||||
|
br#"{}"#.to_vec(),
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
persisted_usage_floor(store.clone()).await.is_err(),
|
||||||
|
"a structurally incomplete usage snapshot must not be treated as an empty floor"
|
||||||
|
);
|
||||||
|
|
||||||
store.objects.lock().await.insert(
|
store.objects.lock().await.insert(
|
||||||
memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_OBJ_NAME_PATH.as_str()),
|
memory_config_key(RUSTFS_META_BUCKET, DATA_USAGE_OBJ_NAME_PATH.as_str()),
|
||||||
serde_json::to_vec(&DataUsageInfo {
|
serde_json::to_vec(&DataUsageInfo {
|
||||||
@@ -3166,6 +4049,24 @@ fn superseded_retry_backoff_grows_from_the_default_cycle() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(start_paused = true)]
|
||||||
|
async fn corrupt_cycle_state_backoff_uses_virtual_clock() {
|
||||||
|
let mut backoff = ScannerRetryBackoff::default();
|
||||||
|
backoff.record_retryable_cycle(true);
|
||||||
|
let first_delay = backoff
|
||||||
|
.retry_interval(Duration::from_secs(60))
|
||||||
|
.expect("the first recovery retry should be scheduled");
|
||||||
|
assert_eq!(first_delay, Duration::from_secs(5));
|
||||||
|
|
||||||
|
let deadline = Instant::now() + first_delay;
|
||||||
|
assert!(Instant::now() < deadline);
|
||||||
|
tokio::time::advance(first_delay).await;
|
||||||
|
assert!(Instant::now() >= deadline);
|
||||||
|
|
||||||
|
backoff.record_retryable_cycle(true);
|
||||||
|
assert_eq!(backoff.retry_interval(Duration::from_secs(60)), Some(Duration::from_secs(10)));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn scanner_cycle_wait_plan_drives_growth_resets_and_bitrot_cap() {
|
fn scanner_cycle_wait_plan_drives_growth_resets_and_bitrot_cap() {
|
||||||
let runtime_config = ScannerRuntimeConfig {
|
let runtime_config = ScannerRuntimeConfig {
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ mod tests {
|
|||||||
let _list_remote_target_handler = replication::ListRemoteTargetHandler {};
|
let _list_remote_target_handler = replication::ListRemoteTargetHandler {};
|
||||||
let _remove_remote_target_handler = replication::RemoveRemoteTargetHandler {};
|
let _remove_remote_target_handler = replication::RemoveRemoteTargetHandler {};
|
||||||
let _scanner_status_handler = scanner::ScannerStatusHandler {};
|
let _scanner_status_handler = scanner::ScannerStatusHandler {};
|
||||||
|
let _scanner_cycle_state_reset_handler = scanner::ScannerCycleStateResetHandler {};
|
||||||
let _ilm_expiry_status_handler = scanner::IlmExpiryStatusHandler {};
|
let _ilm_expiry_status_handler = scanner::IlmExpiryStatusHandler {};
|
||||||
let _manual_transition_handler = ilm_transition::ManualTransitionRunHandler {};
|
let _manual_transition_handler = ilm_transition::ManualTransitionRunHandler {};
|
||||||
let _manual_transition_status_handler = ilm_transition::ManualTransitionJobStatusHandler {};
|
let _manual_transition_status_handler = ilm_transition::ManualTransitionJobStatusHandler {};
|
||||||
|
|||||||
@@ -13,8 +13,11 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use crate::admin::auth::authorize_admin_request;
|
use crate::admin::auth::authorize_admin_request;
|
||||||
|
use crate::admin::handlers::supervise_admin_mutation;
|
||||||
use crate::admin::router::{AdminOperation, Operation, S3Router};
|
use crate::admin::router::{AdminOperation, Operation, S3Router};
|
||||||
use crate::admin::runtime_sources::current_scanner_metrics_report;
|
use crate::admin::runtime_sources::{
|
||||||
|
app_context_from_req, current_object_store_handle_for_context, current_scanner_metrics_report,
|
||||||
|
};
|
||||||
use crate::module_switches::{ENV_SCANNER_ENABLED, scanner_enabled_from_env};
|
use crate::module_switches::{ENV_SCANNER_ENABLED, scanner_enabled_from_env};
|
||||||
use crate::server::ADMIN_PREFIX;
|
use crate::server::ADMIN_PREFIX;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
@@ -22,11 +25,13 @@ use http::{HeaderMap, HeaderValue};
|
|||||||
use hyper::{Method, StatusCode};
|
use hyper::{Method, StatusCode};
|
||||||
use matchit::Params;
|
use matchit::Params;
|
||||||
use rustfs_common::metrics::{ScannerLifecycleExpirySnapshot, ScannerMaintenanceControlSnapshot, ScannerMetricsReport};
|
use rustfs_common::metrics::{ScannerLifecycleExpirySnapshot, ScannerMaintenanceControlSnapshot, ScannerMetricsReport};
|
||||||
|
use rustfs_config::MAX_ADMIN_REQUEST_BODY_SIZE;
|
||||||
use rustfs_credentials::Credentials;
|
use rustfs_credentials::Credentials;
|
||||||
use rustfs_policy::policy::action::{Action, AdminAction};
|
use rustfs_policy::policy::action::{Action, AdminAction};
|
||||||
use s3s::header::CONTENT_TYPE;
|
use s3s::header::CONTENT_TYPE;
|
||||||
use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, s3_error};
|
use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, s3_error};
|
||||||
use serde::Serialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
const JSON_CONTENT_TYPE: &str = "application/json";
|
const JSON_CONTENT_TYPE: &str = "application/json";
|
||||||
|
|
||||||
@@ -38,6 +43,13 @@ struct ScannerStatusResponse {
|
|||||||
metrics: ScannerMetricsReport,
|
metrics: ScannerMetricsReport,
|
||||||
cycle_schedule: rustfs_scanner::ScannerCycleScheduleStatus,
|
cycle_schedule: rustfs_scanner::ScannerCycleScheduleStatus,
|
||||||
runtime_config: rustfs_scanner::runtime_config::ScannerRuntimeConfigStatus,
|
runtime_config: rustfs_scanner::runtime_config::ScannerRuntimeConfigStatus,
|
||||||
|
cycle_recovery: rustfs_scanner::ScannerCycleRecoveryStatus,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
struct ScannerCycleResetRequest {
|
||||||
|
mode: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -117,6 +129,7 @@ fn scanner_status_response(
|
|||||||
metrics,
|
metrics,
|
||||||
cycle_schedule,
|
cycle_schedule,
|
||||||
runtime_config,
|
runtime_config,
|
||||||
|
cycle_recovery: rustfs_scanner::scanner::scanner_cycle_recovery_status(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +157,11 @@ pub fn register_scanner_route(r: &mut S3Router<AdminOperation>) -> std::io::Resu
|
|||||||
format!("{ADMIN_PREFIX}/v3/scanner/status").as_str(),
|
format!("{ADMIN_PREFIX}/v3/scanner/status").as_str(),
|
||||||
AdminOperation(&ScannerStatusHandler {}),
|
AdminOperation(&ScannerStatusHandler {}),
|
||||||
)?;
|
)?;
|
||||||
|
r.insert(
|
||||||
|
Method::POST,
|
||||||
|
format!("{ADMIN_PREFIX}/v3/scanner/cycle-state/reset").as_str(),
|
||||||
|
AdminOperation(&ScannerCycleStateResetHandler {}),
|
||||||
|
)?;
|
||||||
r.insert(
|
r.insert(
|
||||||
Method::GET,
|
Method::GET,
|
||||||
format!("{ADMIN_PREFIX}/v3/ilm/expiry/status").as_str(),
|
format!("{ADMIN_PREFIX}/v3/ilm/expiry/status").as_str(),
|
||||||
@@ -163,6 +181,13 @@ async fn validate_scanner_status_request(req: &S3Request<Body>) -> S3Result<Cred
|
|||||||
authorize_admin_request(req, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)]).await
|
authorize_admin_request(req, vec![Action::AdminAction(AdminAction::ServerInfoAdminAction)]).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn validate_scanner_reset_request(req: &S3Request<Body>) -> S3Result<Credentials> {
|
||||||
|
if req.credentials.is_none() {
|
||||||
|
return Err(s3_error!(InvalidRequest, "missing credentials"));
|
||||||
|
}
|
||||||
|
authorize_admin_request(req, vec![Action::AdminAction(AdminAction::ConfigUpdateAdminAction)]).await
|
||||||
|
}
|
||||||
|
|
||||||
fn json_response(body: Vec<u8>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
fn json_response(body: Vec<u8>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
let content_type = HeaderValue::from_str(JSON_CONTENT_TYPE)
|
let content_type = HeaderValue::from_str(JSON_CONTENT_TYPE)
|
||||||
@@ -192,6 +217,37 @@ impl Operation for ScannerStatusHandler {
|
|||||||
|
|
||||||
pub struct IlmExpiryStatusHandler {}
|
pub struct IlmExpiryStatusHandler {}
|
||||||
|
|
||||||
|
pub struct ScannerCycleStateResetHandler {}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl Operation for ScannerCycleStateResetHandler {
|
||||||
|
async fn call(&self, mut req: S3Request<Body>, _params: Params<'_, '_>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
||||||
|
let _cred = validate_scanner_reset_request(&req).await?;
|
||||||
|
let body = req
|
||||||
|
.input
|
||||||
|
.store_all_limited(MAX_ADMIN_REQUEST_BODY_SIZE)
|
||||||
|
.await
|
||||||
|
.map_err(|err| S3Error::with_message(S3ErrorCode::InvalidRequest, format!("invalid reset request body: {err}")))?;
|
||||||
|
let reset = serde_json::from_slice::<ScannerCycleResetRequest>(&body)
|
||||||
|
.map_err(|err| S3Error::with_message(S3ErrorCode::InvalidRequest, format!("invalid reset request body: {err}")))?;
|
||||||
|
if reset.mode != "full-rescan" {
|
||||||
|
return Err(S3Error::with_message(S3ErrorCode::InvalidRequest, "reset mode must be full-rescan"));
|
||||||
|
}
|
||||||
|
let context = app_context_from_req(&req)
|
||||||
|
.ok_or_else(|| S3Error::with_message(S3ErrorCode::InternalError, "storage layer not initialized"))?;
|
||||||
|
let store = current_object_store_handle_for_context(Some(context.as_ref()))
|
||||||
|
.ok_or_else(|| S3Error::with_message(S3ErrorCode::InternalError, "storage layer not initialized"))?;
|
||||||
|
supervise_admin_mutation("scanner cycle state reset", async move {
|
||||||
|
rustfs_scanner::scanner::reset_scanner_cycle_recovery(CancellationToken::new(), store)
|
||||||
|
.await
|
||||||
|
.map_err(|err| S3Error::with_message(S3ErrorCode::InternalError, err.to_string()))?;
|
||||||
|
Ok::<_, S3Error>(())
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
json_response(br#"{"status":"reset","mode":"full-rescan"}"#.to_vec())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl Operation for IlmExpiryStatusHandler {
|
impl Operation for IlmExpiryStatusHandler {
|
||||||
async fn call(&self, req: S3Request<Body>, _params: Params<'_, '_>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
async fn call(&self, req: S3Request<Body>, _params: Params<'_, '_>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
||||||
@@ -237,6 +293,38 @@ mod tests {
|
|||||||
assert_eq!(err.message(), Some("missing credentials"));
|
assert_eq!(err.message(), Some("missing credentials"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn scanner_reset_gate_rejects_missing_credentials() {
|
||||||
|
let req = S3Request {
|
||||||
|
input: Body::from(String::new()),
|
||||||
|
method: Method::POST,
|
||||||
|
uri: http::Uri::from_static("/rustfs/admin/v3/scanner/cycle-state/reset"),
|
||||||
|
headers: HeaderMap::new(),
|
||||||
|
extensions: http::Extensions::new(),
|
||||||
|
credentials: None,
|
||||||
|
region: None,
|
||||||
|
service: None,
|
||||||
|
trailing_headers: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let err = validate_scanner_reset_request(&req)
|
||||||
|
.await
|
||||||
|
.expect_err("a reset request without credentials must be rejected");
|
||||||
|
assert_eq!(err.code(), &S3ErrorCode::InvalidRequest);
|
||||||
|
assert_eq!(err.message(), Some("missing credentials"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn admin_reset_requires_full_rescan_or_verified_cursor() {
|
||||||
|
let full_rescan: ScannerCycleResetRequest =
|
||||||
|
serde_json::from_str(r#"{"mode":"full-rescan"}"#).expect("full rescan must be accepted");
|
||||||
|
assert_eq!(full_rescan.mode, "full-rescan");
|
||||||
|
let cursor: ScannerCycleResetRequest =
|
||||||
|
serde_json::from_str(r#"{"mode":"cursor"}"#).expect("mode validation belongs to the handler");
|
||||||
|
assert_ne!(cursor.mode, "full-rescan");
|
||||||
|
assert!(serde_json::from_str::<ScannerCycleResetRequest>(r#"{"mode":"full-rescan","cursor":"untrusted"}"#).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn scanner_disabled_reason_reports_startup_env_key() {
|
fn scanner_disabled_reason_reports_startup_env_key() {
|
||||||
assert_eq!(scanner_disabled_reason(true), None);
|
assert_eq!(scanner_disabled_reason(true), None);
|
||||||
@@ -304,6 +392,11 @@ mod tests {
|
|||||||
assert_eq!(encoded["cycle_schedule"]["effective_interval_seconds"], 0);
|
assert_eq!(encoded["cycle_schedule"]["effective_interval_seconds"], 0);
|
||||||
assert_eq!(encoded["cycle_schedule"]["clean_idle_backoff_enabled"], false);
|
assert_eq!(encoded["cycle_schedule"]["clean_idle_backoff_enabled"], false);
|
||||||
assert_eq!(encoded["cycle_schedule"]["clean_idle_backoff_multiplier"], 1);
|
assert_eq!(encoded["cycle_schedule"]["clean_idle_backoff_multiplier"], 1);
|
||||||
|
assert_eq!(encoded["cycle_recovery"]["state"], "healthy");
|
||||||
|
assert_eq!(
|
||||||
|
encoded["cycle_recovery"]["quarantine_path"],
|
||||||
|
rustfs_scanner::DATA_USAGE_BLOOM_RECOVERY_PATH.as_str()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -428,6 +428,12 @@ pub const ADMIN_ROUTE_POLICY_SPECS: &[AdminRouteSpec] = &[
|
|||||||
admin(HttpMethod::Get, "/rustfs/admin/v3/config", CONFIG_UPDATE, RouteRiskLevel::High),
|
admin(HttpMethod::Get, "/rustfs/admin/v3/config", CONFIG_UPDATE, RouteRiskLevel::High),
|
||||||
admin(HttpMethod::Put, "/rustfs/admin/v3/config", CONFIG_UPDATE, RouteRiskLevel::High),
|
admin(HttpMethod::Put, "/rustfs/admin/v3/config", CONFIG_UPDATE, RouteRiskLevel::High),
|
||||||
admin(HttpMethod::Get, "/rustfs/admin/v3/scanner/status", SERVER_INFO, RouteRiskLevel::Sensitive),
|
admin(HttpMethod::Get, "/rustfs/admin/v3/scanner/status", SERVER_INFO, RouteRiskLevel::Sensitive),
|
||||||
|
admin(
|
||||||
|
HttpMethod::Post,
|
||||||
|
"/rustfs/admin/v3/scanner/cycle-state/reset",
|
||||||
|
CONFIG_UPDATE,
|
||||||
|
RouteRiskLevel::High,
|
||||||
|
),
|
||||||
admin(
|
admin(
|
||||||
HttpMethod::Get,
|
HttpMethod::Get,
|
||||||
"/rustfs/admin/v3/ilm/expiry/status",
|
"/rustfs/admin/v3/ilm/expiry/status",
|
||||||
@@ -2020,6 +2026,12 @@ mod tests {
|
|||||||
assert_not_action(HttpMethod::Get, "/rustfs/admin/v3/ilm/expiry/status", SET_TIER);
|
assert_not_action(HttpMethod::Get, "/rustfs/admin/v3/ilm/expiry/status", SET_TIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn route_policy_requires_config_update_for_scanner_cycle_reset() {
|
||||||
|
assert_action(HttpMethod::Post, "/rustfs/admin/v3/scanner/cycle-state/reset", CONFIG_UPDATE);
|
||||||
|
assert_not_action(HttpMethod::Post, "/rustfs/admin/v3/scanner/cycle-state/reset", SERVER_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn route_policy_uses_tier_actions_for_transition_routes() {
|
fn route_policy_uses_tier_actions_for_transition_routes() {
|
||||||
assert_action(HttpMethod::Post, "/rustfs/admin/v3/ilm/transition/run", SET_TIER);
|
assert_action(HttpMethod::Post, "/rustfs/admin/v3/ilm/transition/run", SET_TIER);
|
||||||
|
|||||||
@@ -243,6 +243,7 @@ fn expected_admin_route_matrix() -> Vec<RouteMatrixEntry> {
|
|||||||
admin_route(Method::GET, "/v3/config"),
|
admin_route(Method::GET, "/v3/config"),
|
||||||
admin_route(Method::PUT, "/v3/config"),
|
admin_route(Method::PUT, "/v3/config"),
|
||||||
admin_route(Method::GET, "/v3/scanner/status"),
|
admin_route(Method::GET, "/v3/scanner/status"),
|
||||||
|
admin_route(Method::POST, "/v3/scanner/cycle-state/reset"),
|
||||||
admin_route(Method::GET, "/v3/audit/target/list"),
|
admin_route(Method::GET, "/v3/audit/target/list"),
|
||||||
admin_route_sample(
|
admin_route_sample(
|
||||||
Method::PUT,
|
Method::PUT,
|
||||||
@@ -879,6 +880,7 @@ fn test_register_routes_cover_representative_admin_paths() {
|
|||||||
assert_route(&router, Method::GET, &admin_path("/v3/config"));
|
assert_route(&router, Method::GET, &admin_path("/v3/config"));
|
||||||
assert_route(&router, Method::PUT, &admin_path("/v3/config"));
|
assert_route(&router, Method::PUT, &admin_path("/v3/config"));
|
||||||
assert_route(&router, Method::GET, &admin_path("/v3/scanner/status"));
|
assert_route(&router, Method::GET, &admin_path("/v3/scanner/status"));
|
||||||
|
assert_route(&router, Method::POST, &admin_path("/v3/scanner/cycle-state/reset"));
|
||||||
assert_route(&router, Method::GET, &admin_path("/v3/ilm/expiry/status"));
|
assert_route(&router, Method::GET, &admin_path("/v3/ilm/expiry/status"));
|
||||||
assert_route(&router, Method::POST, &admin_path("/v3/ilm/transition/run"));
|
assert_route(&router, Method::POST, &admin_path("/v3/ilm/transition/run"));
|
||||||
assert_route(
|
assert_route(
|
||||||
@@ -1367,6 +1369,7 @@ fn test_admin_alias_paths_match_existing_admin_routes() {
|
|||||||
(Method::GET, compat_admin_alias_path("/v3/config")),
|
(Method::GET, compat_admin_alias_path("/v3/config")),
|
||||||
(Method::PUT, compat_admin_alias_path("/v3/config")),
|
(Method::PUT, compat_admin_alias_path("/v3/config")),
|
||||||
(Method::GET, compat_admin_alias_path("/v3/scanner/status")),
|
(Method::GET, compat_admin_alias_path("/v3/scanner/status")),
|
||||||
|
(Method::POST, compat_admin_alias_path("/v3/scanner/cycle-state/reset")),
|
||||||
(Method::GET, compat_admin_alias_path("/v3/ilm/expiry/status")),
|
(Method::GET, compat_admin_alias_path("/v3/ilm/expiry/status")),
|
||||||
] {
|
] {
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -146,6 +146,29 @@ fn encode_file_info_msgpack(value: &FileInfo) -> std::result::Result<Vec<u8>, Di
|
|||||||
encode_msgpack_with_capacity(value, "FileInfo", FILE_INFO_MSGPACK_ENCODE_CAPACITY_HINT)
|
encode_msgpack_with_capacity(value, "FileInfo", FILE_INFO_MSGPACK_ENCODE_CAPACITY_HINT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn encode_delete_versions_errors(disk_errors: Vec<Option<DiskError>>) -> (Vec<String>, Vec<Error>) {
|
||||||
|
let mut errors = Vec::with_capacity(disk_errors.len());
|
||||||
|
let mut item_errors = Vec::with_capacity(disk_errors.len());
|
||||||
|
for error in disk_errors {
|
||||||
|
match error {
|
||||||
|
Some(error) => {
|
||||||
|
let code = match &error {
|
||||||
|
DiskError::Io(source) if source.kind() == std::io::ErrorKind::NotFound => DiskError::FileNotFound.to_u32(),
|
||||||
|
_ => error.to_u32(),
|
||||||
|
};
|
||||||
|
let error_info = error.to_string();
|
||||||
|
errors.push(error_info.clone());
|
||||||
|
item_errors.push(Error { code, error_info });
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
errors.push(String::new());
|
||||||
|
item_errors.push(Error::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(errors, item_errors)
|
||||||
|
}
|
||||||
|
|
||||||
fn encode_msgpack_named<T: serde::Serialize>(value: &T, value_name: &str) -> std::result::Result<Vec<u8>, DiskError> {
|
fn encode_msgpack_named<T: serde::Serialize>(value: &T, value_name: &str) -> std::result::Result<Vec<u8>, DiskError> {
|
||||||
let mut serializer = rmp_serde::Serializer::new(Vec::with_capacity(MSGPACK_ENCODE_CAPACITY_HINT)).with_struct_map();
|
let mut serializer = rmp_serde::Serializer::new(Vec::with_capacity(MSGPACK_ENCODE_CAPACITY_HINT)).with_struct_map();
|
||||||
value
|
value
|
||||||
@@ -552,6 +575,7 @@ impl NodeService {
|
|||||||
success: false,
|
success: false,
|
||||||
errors: Vec::new(),
|
errors: Vec::new(),
|
||||||
error: Some(DiskError::other(format!("decode FileInfoVersions failed: {err}")).into()),
|
error: Some(DiskError::other(format!("decode FileInfoVersions failed: {err}")).into()),
|
||||||
|
item_errors: Vec::new(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -563,30 +587,26 @@ impl NodeService {
|
|||||||
success: false,
|
success: false,
|
||||||
errors: Vec::new(),
|
errors: Vec::new(),
|
||||||
error: Some(DiskError::other(format!("decode DeleteOptions failed: {err}")).into()),
|
error: Some(DiskError::other(format!("decode DeleteOptions failed: {err}")).into()),
|
||||||
|
item_errors: Vec::new(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let errors = disk
|
let (errors, item_errors) =
|
||||||
.delete_versions(&request.volume, versions, opts)
|
encode_delete_versions_errors(disk.delete_versions(&request.volume, versions, opts).await);
|
||||||
.await
|
|
||||||
.into_iter()
|
|
||||||
.map(|error| match error {
|
|
||||||
Some(e) => e.to_string(),
|
|
||||||
None => "".to_string(),
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(Response::new(DeleteVersionsResponse {
|
Ok(Response::new(DeleteVersionsResponse {
|
||||||
success: true,
|
success: true,
|
||||||
errors,
|
errors,
|
||||||
error: None,
|
error: None,
|
||||||
|
item_errors,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(Response::new(DeleteVersionsResponse {
|
Ok(Response::new(DeleteVersionsResponse {
|
||||||
success: false,
|
success: false,
|
||||||
errors: Vec::new(),
|
errors: Vec::new(),
|
||||||
error: Some(DiskError::other("cannot find disk".to_string()).into()),
|
error: Some(DiskError::other("cannot find disk".to_string()).into()),
|
||||||
|
item_errors: Vec::new(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1612,8 +1632,8 @@ impl NodeService {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
compat_response_json, decode_msgpack_or_json, decode_rename_data_request_file_info,
|
compat_response_json, decode_msgpack_or_json, decode_rename_data_request_file_info,
|
||||||
encode_batch_read_version_response_payloads, encode_file_info_msgpack, encode_msgpack, encode_msgpack_named,
|
encode_batch_read_version_response_payloads, encode_delete_versions_errors, encode_file_info_msgpack, encode_msgpack,
|
||||||
encode_read_multiple_response_payloads, encode_rename_data_response_payloads,
|
encode_msgpack_named, encode_read_multiple_response_payloads, encode_rename_data_response_payloads,
|
||||||
};
|
};
|
||||||
use crate::storage::rpc::node_service::make_server;
|
use crate::storage::rpc::node_service::make_server;
|
||||||
use crate::storage::storage_api::ReadMultipleResp;
|
use crate::storage::storage_api::ReadMultipleResp;
|
||||||
@@ -1632,6 +1652,18 @@ mod tests {
|
|||||||
count: u32,
|
count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_versions_response_dual_writes_typed_item_errors() {
|
||||||
|
let raw_not_found = super::DiskError::Io(std::io::Error::from(std::io::ErrorKind::NotFound));
|
||||||
|
let (errors, item_errors) = encode_delete_versions_errors(vec![Some(raw_not_found), None]);
|
||||||
|
|
||||||
|
assert!(errors[0].starts_with("io error "));
|
||||||
|
assert!(errors[1].is_empty());
|
||||||
|
assert_eq!(item_errors[0].code, super::DiskError::FileNotFound.to_u32());
|
||||||
|
assert_eq!(item_errors[0].error_info, errors[0]);
|
||||||
|
assert_eq!(item_errors[1].code, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn handle_read_version_records_attribution_for_missing_disk() {
|
async fn handle_read_version_records_attribution_for_missing_disk() {
|
||||||
|
|||||||
Reference in New Issue
Block a user