mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-22 12:26:37 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 16c56fe0bd | |||
| 2c3e68ad89 |
@@ -400,7 +400,7 @@ jobs:
|
||||
if: github.event_name != 'pull_request' || github.event.action != 'closed'
|
||||
needs: [ quick-checks ]
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 45
|
||||
timeout-minutes: 90
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
steps:
|
||||
@@ -440,7 +440,7 @@ jobs:
|
||||
if: github.event_name != 'pull_request' || github.event.action != 'closed'
|
||||
needs: [ quick-checks ]
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 60
|
||||
timeout-minutes: 90
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
steps:
|
||||
@@ -470,7 +470,7 @@ jobs:
|
||||
if: github.event_name != 'pull_request' || github.event.action != 'closed'
|
||||
needs: [ quick-checks ]
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 60
|
||||
timeout-minutes: 90
|
||||
strategy:
|
||||
# On a PR, one failing protocol leg is enough to know the PR is not ready,
|
||||
# so stop the sibling leg instead of paying another ~40 minutes for it.
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::heal::{
|
||||
progress::HealProgress,
|
||||
progress::{HealProgress, add_bytes, increment_counter},
|
||||
resume::{
|
||||
CheckpointManager, ReplacementTargetIdentity, ResumeManager, ResumeUtils, compose_key,
|
||||
replacement_target_identities_match,
|
||||
@@ -410,6 +410,9 @@ impl ErasureSetHealer {
|
||||
&& state.successful_objects == 0
|
||||
&& state.failed_objects == 0
|
||||
&& state.skipped_objects == 0
|
||||
&& state.skipped_new_versions == 0
|
||||
&& state.skipped_ilm_expired == 0
|
||||
&& state.processed_bytes == 0
|
||||
{
|
||||
// schedule_retry persists the authoritative resume reset before
|
||||
// resetting the checkpoint. Reapply the checkpoint reset after
|
||||
@@ -474,6 +477,23 @@ impl ErasureSetHealer {
|
||||
|
||||
// 2. initialize progress
|
||||
self.initialize_progress(buckets, &state).await;
|
||||
let (baseline_known, baseline_count, baseline_size, baseline_generation) = {
|
||||
let baseline = self.progress.read().await;
|
||||
(
|
||||
baseline.baseline_known,
|
||||
baseline.objects_total_count,
|
||||
baseline.objects_total_size,
|
||||
baseline.baseline_generation,
|
||||
)
|
||||
};
|
||||
if baseline_known {
|
||||
resume_manager
|
||||
.set_progress_baseline(baseline_count, baseline_size, baseline_generation)
|
||||
.await?;
|
||||
checkpoint_manager
|
||||
.set_progress_baseline(baseline_count, baseline_size, baseline_generation)
|
||||
.await?;
|
||||
}
|
||||
|
||||
// 3. continue from checkpoint
|
||||
let current_bucket_index = checkpoint.current_bucket_index;
|
||||
@@ -483,6 +503,58 @@ impl ErasureSetHealer {
|
||||
let mut successful_objects = state.successful_objects;
|
||||
let mut failed_objects = state.failed_objects;
|
||||
let mut skipped_objects = state.skipped_objects;
|
||||
let checkpoint_has_progress = checkpoint.baseline_known
|
||||
|| checkpoint.successful_objects > 0
|
||||
|| checkpoint.failed_object_count > 0
|
||||
|| checkpoint.skipped_object_count > 0
|
||||
|| checkpoint.skipped_new_versions > 0
|
||||
|| checkpoint.skipped_ilm_expired > 0
|
||||
|| checkpoint.processed_bytes > 0
|
||||
|| checkpoint.total_objects > 0
|
||||
|| checkpoint.total_bytes > 0
|
||||
|| checkpoint.baseline_generation.is_some()
|
||||
|| checkpoint.counter_unknown;
|
||||
let checkpoint_generation_mismatch = checkpoint.baseline_known && checkpoint.baseline_generation != baseline_generation;
|
||||
let mut restored_counter_unknown = state.counter_unknown || checkpoint.counter_unknown;
|
||||
if checkpoint_has_progress {
|
||||
successful_objects = checkpoint.successful_objects;
|
||||
failed_objects = checkpoint.failed_object_count;
|
||||
skipped_objects = checkpoint.skipped_object_count;
|
||||
let restored_processed_objects = successful_objects
|
||||
.checked_add(failed_objects)
|
||||
.and_then(|value| value.checked_add(skipped_objects))
|
||||
.and_then(|value| value.checked_add(checkpoint.skipped_new_versions))
|
||||
.and_then(|value| value.checked_add(checkpoint.skipped_ilm_expired));
|
||||
let checkpoint_counter_overflow = restored_processed_objects.is_none();
|
||||
restored_counter_unknown |= checkpoint_counter_overflow;
|
||||
processed_objects = restored_processed_objects.unwrap_or(u64::MAX);
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.objects_scanned = processed_objects;
|
||||
progress.objects_healed = successful_objects;
|
||||
progress.objects_failed = failed_objects;
|
||||
progress.skipped_objects = skipped_objects;
|
||||
progress.skipped_new_versions = checkpoint.skipped_new_versions;
|
||||
progress.skipped_ilm_expired = checkpoint.skipped_ilm_expired;
|
||||
if checkpoint.baseline_known && !checkpoint_generation_mismatch {
|
||||
progress.objects_total_count = checkpoint.total_objects;
|
||||
progress.objects_total_size = checkpoint.total_bytes;
|
||||
progress.baseline_generation = checkpoint.baseline_generation;
|
||||
progress.baseline_known = true;
|
||||
}
|
||||
progress.bytes_processed = checkpoint.processed_bytes;
|
||||
progress.counter_unknown = state.counter_unknown || checkpoint.counter_unknown;
|
||||
progress.refresh_progress_percentage();
|
||||
if checkpoint_generation_mismatch || checkpoint_counter_overflow || progress.counter_unknown {
|
||||
progress.mark_unknown();
|
||||
}
|
||||
}
|
||||
if checkpoint_generation_mismatch {
|
||||
restored_counter_unknown = true;
|
||||
}
|
||||
if restored_counter_unknown {
|
||||
checkpoint_manager.mark_counter_unknown().await?;
|
||||
resume_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
let mut failed_buckets = 0u64;
|
||||
|
||||
// 4. process remaining buckets
|
||||
@@ -516,13 +588,42 @@ impl ErasureSetHealer {
|
||||
return bucket_result;
|
||||
}
|
||||
|
||||
// update checkpoint position
|
||||
checkpoint_manager.update_position(bucket_idx, current_object_index).await?;
|
||||
|
||||
// update progress
|
||||
resume_manager
|
||||
.update_progress(processed_objects, successful_objects, failed_objects, skipped_objects)
|
||||
let progress_snapshot = self.progress.read().await;
|
||||
let bytes_processed = progress_snapshot.bytes_processed;
|
||||
let skipped_new_versions = progress_snapshot.skipped_new_versions;
|
||||
let skipped_ilm_expired = progress_snapshot.skipped_ilm_expired;
|
||||
let counter_unknown = progress_snapshot.counter_unknown;
|
||||
drop(progress_snapshot);
|
||||
// The checkpoint is the recovery authority for object progress.
|
||||
// Publish its counters and fence before the resume summary so a
|
||||
// crash between the two stores cannot make recovery select newer
|
||||
// summary bytes with an older checkpoint ledger.
|
||||
if counter_unknown {
|
||||
checkpoint_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
checkpoint_manager
|
||||
.update_progress(successful_objects, failed_objects, skipped_objects, bytes_processed)
|
||||
.await?;
|
||||
checkpoint_manager
|
||||
.set_skipped_version_counts(skipped_new_versions, skipped_ilm_expired)
|
||||
.await?;
|
||||
checkpoint_manager.update_position(bucket_idx, current_object_index).await?;
|
||||
resume_manager
|
||||
.update_progress_with_bytes(
|
||||
processed_objects,
|
||||
successful_objects,
|
||||
failed_objects,
|
||||
skipped_objects,
|
||||
bytes_processed,
|
||||
)
|
||||
.await?;
|
||||
resume_manager
|
||||
.set_skipped_version_counts(skipped_new_versions, skipped_ilm_expired)
|
||||
.await?;
|
||||
if counter_unknown {
|
||||
resume_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
|
||||
// check cancel status
|
||||
if self.cancel_token.is_cancelled() {
|
||||
@@ -781,14 +882,36 @@ impl ErasureSetHealer {
|
||||
|
||||
if should_skip_new_version(item.mod_time_unix_nanos, started_at_secs) {
|
||||
checkpoint_manager.add_processed_object(key).await?;
|
||||
*processed_objects = processed_objects.saturating_add(1);
|
||||
let counter_ok = increment_counter(processed_objects);
|
||||
completed_in_page = completed_in_page.saturating_add(1);
|
||||
counter!("rustfs_heal_skipped_new_versions_total").increment(1);
|
||||
{
|
||||
let (skipped_new, skipped_ilm, counter_unknown) = {
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.record_skipped_new_version();
|
||||
progress.set_current_object(Some(format!("skipped_new: {bucket}/{}", item.name)));
|
||||
progress.update_progress(*processed_objects, *successful_objects, *failed_objects, bytes_processed);
|
||||
progress.update_object_progress(
|
||||
*processed_objects,
|
||||
*successful_objects,
|
||||
*failed_objects,
|
||||
*skipped_objects,
|
||||
bytes_processed,
|
||||
);
|
||||
if !counter_ok {
|
||||
progress.mark_unknown();
|
||||
}
|
||||
(progress.skipped_new_versions, progress.skipped_ilm_expired, progress.counter_unknown)
|
||||
};
|
||||
if !counter_ok || counter_unknown {
|
||||
checkpoint_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
checkpoint_manager
|
||||
.set_skipped_version_counts(skipped_new, skipped_ilm)
|
||||
.await?;
|
||||
checkpoint_manager
|
||||
.update_progress(*successful_objects, *failed_objects, *skipped_objects, bytes_processed)
|
||||
.await?;
|
||||
if !counter_ok || counter_unknown {
|
||||
resume_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
debug!(
|
||||
target: "rustfs::heal::erasure_healer",
|
||||
@@ -821,14 +944,36 @@ impl ErasureSetHealer {
|
||||
.await?
|
||||
{
|
||||
checkpoint_manager.add_processed_object(key).await?;
|
||||
*processed_objects = processed_objects.saturating_add(1);
|
||||
let counter_ok = increment_counter(processed_objects);
|
||||
completed_in_page = completed_in_page.saturating_add(1);
|
||||
counter!("rustfs_heal_skipped_ilm_expired_total").increment(1);
|
||||
{
|
||||
let (skipped_new, skipped_ilm, counter_unknown) = {
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.record_skipped_ilm_expired();
|
||||
progress.set_current_object(Some(format!("skipped_ilm: {bucket}/{}", item.name)));
|
||||
progress.update_progress(*processed_objects, *successful_objects, *failed_objects, bytes_processed);
|
||||
progress.update_object_progress(
|
||||
*processed_objects,
|
||||
*successful_objects,
|
||||
*failed_objects,
|
||||
*skipped_objects,
|
||||
bytes_processed,
|
||||
);
|
||||
if !counter_ok {
|
||||
progress.mark_unknown();
|
||||
}
|
||||
(progress.skipped_new_versions, progress.skipped_ilm_expired, progress.counter_unknown)
|
||||
};
|
||||
if !counter_ok || counter_unknown {
|
||||
checkpoint_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
checkpoint_manager
|
||||
.set_skipped_version_counts(skipped_new, skipped_ilm)
|
||||
.await?;
|
||||
checkpoint_manager
|
||||
.update_progress(*successful_objects, *failed_objects, *skipped_objects, bytes_processed)
|
||||
.await?;
|
||||
if !counter_ok || counter_unknown {
|
||||
resume_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
debug!(
|
||||
target: "rustfs::heal::erasure_healer",
|
||||
@@ -954,10 +1099,11 @@ impl ErasureSetHealer {
|
||||
|
||||
while let Some((key, object, version_id, result)) = page_tasks.next().await {
|
||||
let (object_size, result) = result;
|
||||
let mut telemetry_unknown = false;
|
||||
match result {
|
||||
Ok(true) => {
|
||||
*successful_objects += 1;
|
||||
bytes_processed = bytes_processed.saturating_add(object_size);
|
||||
telemetry_unknown |= !increment_counter(successful_objects);
|
||||
telemetry_unknown |= !add_bytes(&mut bytes_processed, object_size);
|
||||
checkpoint_manager.add_processed_object(key).await?;
|
||||
debug!(
|
||||
target: "rustfs::heal::erasure_healer",
|
||||
@@ -974,8 +1120,8 @@ impl ErasureSetHealer {
|
||||
}
|
||||
Ok(false) => {
|
||||
checkpoint_manager.add_processed_object(key).await?;
|
||||
*successful_objects += 1;
|
||||
bytes_processed = bytes_processed.saturating_add(object_size);
|
||||
telemetry_unknown |= !increment_counter(successful_objects);
|
||||
telemetry_unknown |= !add_bytes(&mut bytes_processed, object_size);
|
||||
debug!(
|
||||
target: "rustfs::heal::erasure_healer",
|
||||
event = EVENT_HEAL_ERASURE_OBJECT_STATE,
|
||||
@@ -991,8 +1137,8 @@ impl ErasureSetHealer {
|
||||
}
|
||||
Err(err @ Error::TaskCancelled) | Err(err @ Error::TaskTimeout) => return Err(err),
|
||||
Err(Error::TransientSkip { message }) => {
|
||||
*skipped_objects += 1;
|
||||
bytes_processed = bytes_processed.saturating_add(object_size);
|
||||
telemetry_unknown |= !increment_counter(skipped_objects);
|
||||
telemetry_unknown |= !add_bytes(&mut bytes_processed, object_size);
|
||||
checkpoint_manager.add_skipped_object(key).await?;
|
||||
demote_to_debug_when!(!take_failure_log_sample(&mut transient_skip_samples_logged), warn, target: "rustfs::heal::erasure_healer", {
|
||||
event = EVENT_HEAL_ERASURE_OBJECT_STATE,
|
||||
@@ -1008,8 +1154,8 @@ impl ErasureSetHealer {
|
||||
});
|
||||
}
|
||||
Err(err) => {
|
||||
*failed_objects += 1;
|
||||
bytes_processed = bytes_processed.saturating_add(object_size);
|
||||
telemetry_unknown |= !increment_counter(failed_objects);
|
||||
telemetry_unknown |= !add_bytes(&mut bytes_processed, object_size);
|
||||
checkpoint_manager.add_failed_object(key).await?;
|
||||
demote_to_debug_when!(!take_failure_log_sample(&mut failure_samples_logged), warn, target: "rustfs::heal::erasure_healer", {
|
||||
event = EVENT_HEAL_ERASURE_OBJECT_STATE,
|
||||
@@ -1026,12 +1172,31 @@ impl ErasureSetHealer {
|
||||
}
|
||||
}
|
||||
|
||||
*processed_objects += 1;
|
||||
telemetry_unknown |= !increment_counter(processed_objects);
|
||||
completed_in_page += 1;
|
||||
{
|
||||
let progress_unknown = {
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("{bucket}/{object}")));
|
||||
progress.update_progress(*processed_objects, *successful_objects, *failed_objects, bytes_processed);
|
||||
progress.update_object_progress(
|
||||
*processed_objects,
|
||||
*successful_objects,
|
||||
*failed_objects,
|
||||
*skipped_objects,
|
||||
bytes_processed,
|
||||
);
|
||||
if telemetry_unknown {
|
||||
progress.mark_unknown();
|
||||
}
|
||||
progress.counter_unknown
|
||||
};
|
||||
if telemetry_unknown || progress_unknown {
|
||||
checkpoint_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
checkpoint_manager
|
||||
.update_progress(*successful_objects, *failed_objects, *skipped_objects, bytes_processed)
|
||||
.await?;
|
||||
if telemetry_unknown || progress_unknown {
|
||||
resume_manager.mark_counter_unknown().await?;
|
||||
}
|
||||
|
||||
if completed_in_page.is_multiple_of(100) {
|
||||
@@ -1083,10 +1248,66 @@ impl ErasureSetHealer {
|
||||
/// initialize progress tracking
|
||||
async fn initialize_progress(&self, _buckets: &[String], state: &crate::heal::resume::ResumeState) {
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.objects_scanned = state.total_objects;
|
||||
let existing_baseline = (
|
||||
progress.objects_total_count,
|
||||
progress.objects_total_size,
|
||||
progress.baseline_generation,
|
||||
progress.progress_state,
|
||||
progress.baseline_known,
|
||||
);
|
||||
let baseline_generation_mismatch =
|
||||
state.baseline_known && existing_baseline.4 && state.baseline_generation != existing_baseline.2;
|
||||
let use_persisted_baseline = state.baseline_known && !baseline_generation_mismatch;
|
||||
progress.objects_scanned = state.processed_objects;
|
||||
progress.objects_healed = state.successful_objects;
|
||||
progress.objects_failed = state.failed_objects;
|
||||
progress.bytes_processed = 0; // Resume state tracks object counts, not byte counters.
|
||||
progress.skipped_objects = state.skipped_objects;
|
||||
progress.skipped_new_versions = state.skipped_new_versions;
|
||||
progress.skipped_ilm_expired = state.skipped_ilm_expired;
|
||||
progress.bytes_processed = state.processed_bytes;
|
||||
progress.counter_unknown = state.counter_unknown;
|
||||
if use_persisted_baseline
|
||||
|| existing_baseline.0 > 0
|
||||
|| existing_baseline.1 > 0
|
||||
|| existing_baseline.2.is_some()
|
||||
|| existing_baseline.4
|
||||
{
|
||||
progress.objects_total_count = if use_persisted_baseline {
|
||||
state.total_objects
|
||||
} else {
|
||||
existing_baseline.0
|
||||
};
|
||||
progress.objects_total_size = if use_persisted_baseline {
|
||||
state.total_bytes
|
||||
} else {
|
||||
existing_baseline.1
|
||||
};
|
||||
progress.baseline_generation = if use_persisted_baseline {
|
||||
state.baseline_generation
|
||||
} else {
|
||||
existing_baseline.2
|
||||
};
|
||||
progress.baseline_known = use_persisted_baseline
|
||||
|| existing_baseline.0 > 0
|
||||
|| existing_baseline.1 > 0
|
||||
|| existing_baseline.2.is_some()
|
||||
|| existing_baseline.4;
|
||||
}
|
||||
progress.progress_state = if use_persisted_baseline
|
||||
|| existing_baseline.0 > 0
|
||||
|| existing_baseline.1 > 0
|
||||
|| existing_baseline.2.is_some()
|
||||
|| existing_baseline.4
|
||||
{
|
||||
crate::heal::progress::HealProgressState::Running
|
||||
} else {
|
||||
crate::heal::progress::HealProgressState::Indeterminate
|
||||
};
|
||||
if baseline_generation_mismatch || state.counter_unknown {
|
||||
progress.mark_unknown();
|
||||
}
|
||||
progress.ledger_complete = false;
|
||||
progress.refresh_progress_percentage();
|
||||
progress.start_time = UNIX_EPOCH.checked_add(Duration::from_secs(state.start_time));
|
||||
progress.last_update_time = UNIX_EPOCH.checked_add(Duration::from_secs(state.last_update));
|
||||
progress.set_current_object(state.current_object.clone());
|
||||
|
||||
@@ -1917,16 +1917,44 @@ impl HealManager {
|
||||
}
|
||||
|
||||
let mut snapshot = HealProgress::default();
|
||||
let mut has_object_sweep = false;
|
||||
let mut all_object_baselines_known = true;
|
||||
let mut counter_overflow = false;
|
||||
let mut stage_current = 0_u64;
|
||||
let mut stage_total = 0_u64;
|
||||
for task in active_tasks {
|
||||
let progress = task.get_progress().await;
|
||||
snapshot.objects_scanned = snapshot.objects_scanned.saturating_add(progress.objects_scanned);
|
||||
snapshot.objects_healed = snapshot.objects_healed.saturating_add(progress.objects_healed);
|
||||
snapshot.objects_failed = snapshot.objects_failed.saturating_add(progress.objects_failed);
|
||||
snapshot.skipped_new_versions = snapshot.skipped_new_versions.saturating_add(progress.skipped_new_versions);
|
||||
snapshot.skipped_ilm_expired = snapshot.skipped_ilm_expired.saturating_add(progress.skipped_ilm_expired);
|
||||
snapshot.objects_total_count = snapshot.objects_total_count.saturating_add(progress.objects_total_count);
|
||||
snapshot.objects_total_size = snapshot.objects_total_size.saturating_add(progress.objects_total_size);
|
||||
snapshot.bytes_processed = snapshot.bytes_processed.saturating_add(progress.bytes_processed);
|
||||
let object_sweep = matches!(progress.kind, crate::heal::progress::HealProgressKind::ObjectSweep);
|
||||
has_object_sweep |= object_sweep;
|
||||
if object_sweep {
|
||||
all_object_baselines_known &= progress.baseline_known;
|
||||
}
|
||||
counter_overflow |=
|
||||
progress.counter_unknown || matches!(progress.progress_state, crate::heal::progress::HealProgressState::Unknown);
|
||||
match stage_current.checked_add(progress.stage_current) {
|
||||
Some(sum) => stage_current = sum,
|
||||
None => counter_overflow = true,
|
||||
}
|
||||
match stage_total.checked_add(progress.stage_total) {
|
||||
Some(sum) => stage_total = sum,
|
||||
None => counter_overflow = true,
|
||||
}
|
||||
for (target, value) in [
|
||||
(&mut snapshot.objects_scanned, progress.objects_scanned),
|
||||
(&mut snapshot.objects_healed, progress.objects_healed),
|
||||
(&mut snapshot.objects_failed, progress.objects_failed),
|
||||
(&mut snapshot.skipped_objects, progress.skipped_objects),
|
||||
(&mut snapshot.skipped_new_versions, progress.skipped_new_versions),
|
||||
(&mut snapshot.skipped_ilm_expired, progress.skipped_ilm_expired),
|
||||
(&mut snapshot.objects_total_count, progress.objects_total_count),
|
||||
(&mut snapshot.objects_total_size, progress.objects_total_size),
|
||||
(&mut snapshot.bytes_processed, progress.bytes_processed),
|
||||
] {
|
||||
match target.checked_add(value) {
|
||||
Some(sum) => *target = sum,
|
||||
None => counter_overflow = true,
|
||||
}
|
||||
}
|
||||
snapshot.start_time = match (snapshot.start_time, progress.start_time) {
|
||||
(Some(current), Some(next)) => Some(current.min(next)),
|
||||
(None, next) => next,
|
||||
@@ -1941,7 +1969,36 @@ impl HealManager {
|
||||
snapshot.current_object = progress.current_object;
|
||||
}
|
||||
}
|
||||
snapshot.refresh_progress_percentage();
|
||||
snapshot.kind = if has_object_sweep {
|
||||
crate::heal::progress::HealProgressKind::ObjectSweep
|
||||
} else {
|
||||
crate::heal::progress::HealProgressKind::Stage
|
||||
};
|
||||
snapshot.stage_current = stage_current;
|
||||
snapshot.stage_total = stage_total;
|
||||
snapshot.baseline_known = has_object_sweep && all_object_baselines_known;
|
||||
snapshot.progress_state = if counter_overflow {
|
||||
crate::heal::progress::HealProgressState::Unknown
|
||||
} else if has_object_sweep && !all_object_baselines_known {
|
||||
crate::heal::progress::HealProgressState::Indeterminate
|
||||
} else if has_object_sweep {
|
||||
crate::heal::progress::HealProgressState::Running
|
||||
} else if stage_total == 0 {
|
||||
crate::heal::progress::HealProgressState::Indeterminate
|
||||
} else {
|
||||
crate::heal::progress::HealProgressState::Running
|
||||
};
|
||||
if counter_overflow {
|
||||
snapshot.progress_percentage = 0.0;
|
||||
} else if !has_object_sweep {
|
||||
snapshot.progress_percentage = if stage_total == 0 {
|
||||
0.0
|
||||
} else {
|
||||
((stage_current as f64 / stage_total as f64) * 100.0).min(99.999)
|
||||
};
|
||||
} else {
|
||||
snapshot.refresh_progress_percentage();
|
||||
}
|
||||
snapshot.refresh_estimated_completion_time();
|
||||
Some(snapshot)
|
||||
}
|
||||
|
||||
@@ -15,15 +15,70 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
pub(crate) fn increment_counter(counter: &mut u64) -> bool {
|
||||
match counter.checked_add(1) {
|
||||
Some(next) => {
|
||||
*counter = next;
|
||||
true
|
||||
}
|
||||
None => {
|
||||
*counter = u64::MAX;
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn add_bytes(total: &mut u64, amount: u64) -> bool {
|
||||
match total.checked_add(amount) {
|
||||
Some(next) => {
|
||||
*total = next;
|
||||
true
|
||||
}
|
||||
None => {
|
||||
*total = u64::MAX;
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum HealProgressKind {
|
||||
#[default]
|
||||
Unknown,
|
||||
Stage,
|
||||
ObjectSweep,
|
||||
}
|
||||
|
||||
/// Whether the object ledger can produce a meaningful percentage.
|
||||
///
|
||||
/// A zero-valued baseline is not a completed scan: it means that no complete
|
||||
/// usage snapshot was available. Keep this state explicit so callers do not
|
||||
/// mistake the legacy `0.0` wire value for a measured zero-percent result.
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum HealProgressState {
|
||||
#[default]
|
||||
Unknown,
|
||||
Indeterminate,
|
||||
Running,
|
||||
Completed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HealProgress {
|
||||
#[serde(default)]
|
||||
pub kind: HealProgressKind,
|
||||
/// Objects scanned
|
||||
pub objects_scanned: u64,
|
||||
/// Objects healed
|
||||
pub objects_healed: u64,
|
||||
/// Objects failed
|
||||
pub objects_failed: u64,
|
||||
/// Versions deferred for a later retry pass.
|
||||
#[serde(default)]
|
||||
pub skipped_objects: u64,
|
||||
/// Versions skipped because they were written after this heal started
|
||||
pub skipped_new_versions: u64,
|
||||
/// Versions skipped because lifecycle already selected them for expiry
|
||||
@@ -44,11 +99,38 @@ pub struct HealProgress {
|
||||
pub last_update_time: Option<SystemTime>,
|
||||
/// Estimated completion time
|
||||
pub estimated_completion_time: Option<SystemTime>,
|
||||
/// Current stage number. Stage updates are intentionally independent from
|
||||
/// the object ledger below.
|
||||
#[serde(default)]
|
||||
pub stage_current: u64,
|
||||
/// Number of stages in the current task.
|
||||
#[serde(default)]
|
||||
pub stage_total: u64,
|
||||
/// Explicitly distinguishes a missing usage baseline from measured 0%.
|
||||
#[serde(default)]
|
||||
pub progress_state: HealProgressState,
|
||||
/// True only after the task's durable completion ledger was committed.
|
||||
#[serde(default)]
|
||||
pub ledger_complete: bool,
|
||||
/// Generation of the usage snapshot used for the baseline, if available.
|
||||
#[serde(default)]
|
||||
pub baseline_generation: Option<u64>,
|
||||
/// Whether the baseline was explicitly observed. This is separate from
|
||||
/// the counters so a known empty scope (0 objects, 0 bytes) is not
|
||||
/// confused with a legacy snapshot that omitted the baseline fields.
|
||||
#[serde(default)]
|
||||
pub baseline_known: bool,
|
||||
/// Internal telemetry fence set when an aggregate counter overflows or
|
||||
/// becomes inconsistent. It prevents a later refresh from fabricating a
|
||||
/// percentage from the poisoned values.
|
||||
#[serde(default)]
|
||||
pub counter_unknown: bool,
|
||||
}
|
||||
|
||||
impl HealProgress {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
kind: HealProgressKind::Unknown,
|
||||
start_time: Some(SystemTime::now()),
|
||||
last_update_time: Some(SystemTime::now()),
|
||||
..Default::default()
|
||||
@@ -56,12 +138,87 @@ impl HealProgress {
|
||||
}
|
||||
|
||||
pub fn update_progress(&mut self, scanned: u64, healed: u64, failed: u64, bytes: u64) {
|
||||
self.update_object_sweep_progress(scanned, healed, failed, bytes);
|
||||
}
|
||||
|
||||
pub fn update_object_sweep_progress(&mut self, scanned: u64, healed: u64, failed: u64, bytes: u64) {
|
||||
self.kind = HealProgressKind::ObjectSweep;
|
||||
self.objects_scanned = scanned;
|
||||
self.objects_healed = healed;
|
||||
self.objects_failed = failed;
|
||||
self.bytes_processed = bytes;
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
|
||||
let explicit_skipped = match self.skipped_new_versions.checked_add(self.skipped_ilm_expired) {
|
||||
Some(value) => value,
|
||||
None => {
|
||||
self.mark_unknown();
|
||||
0
|
||||
}
|
||||
};
|
||||
let skipped = healed
|
||||
.checked_add(failed)
|
||||
.and_then(|value| value.checked_add(explicit_skipped))
|
||||
.and_then(|value| scanned.checked_sub(value))
|
||||
.unwrap_or(0);
|
||||
self.update_object_progress(scanned, healed, failed, skipped, bytes);
|
||||
}
|
||||
|
||||
/// Update task stage progress without modifying object counters.
|
||||
pub fn update_stage(&mut self, current: u64, total: u64) {
|
||||
let object_sweep_active = matches!(self.kind, HealProgressKind::ObjectSweep);
|
||||
if !object_sweep_active {
|
||||
self.kind = HealProgressKind::Stage;
|
||||
}
|
||||
self.ledger_complete = false;
|
||||
self.stage_current = current.min(total);
|
||||
self.stage_total = total;
|
||||
if object_sweep_active {
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
self.refresh_progress_percentage();
|
||||
return;
|
||||
}
|
||||
self.progress_state = if total == 0 {
|
||||
HealProgressState::Indeterminate
|
||||
} else {
|
||||
HealProgressState::Running
|
||||
};
|
||||
self.progress_percentage = if total == 0 {
|
||||
0.0
|
||||
} else {
|
||||
(current as f64 / total as f64 * 100.0).min(100.0)
|
||||
};
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
}
|
||||
|
||||
/// Update the disjoint object ledger. `scanned` is the number of terminal
|
||||
/// object outcomes and must equal healed + failed + deferred skipped plus
|
||||
/// the two terminal skip classes. Overflow is a corrupt/unknown counter
|
||||
/// state, not a reason to abort a completed heal.
|
||||
pub fn update_object_progress(&mut self, scanned: u64, healed: u64, failed: u64, skipped: u64, bytes: u64) {
|
||||
self.kind = HealProgressKind::ObjectSweep;
|
||||
// `skipped` is the transient/deferred class. The two explicit skip
|
||||
// counters are terminal classifications too, so include them in the
|
||||
// same ledger without making callers maintain a second aggregate.
|
||||
let outcomes = healed
|
||||
.checked_add(failed)
|
||||
.and_then(|value| value.checked_add(skipped))
|
||||
.and_then(|value| value.checked_add(self.skipped_new_versions))
|
||||
.and_then(|value| value.checked_add(self.skipped_ilm_expired));
|
||||
self.objects_scanned = scanned;
|
||||
self.objects_healed = healed;
|
||||
self.objects_failed = failed;
|
||||
self.skipped_objects = skipped;
|
||||
self.bytes_processed = bytes;
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
self.ledger_complete = false;
|
||||
if outcomes != Some(scanned) {
|
||||
// Telemetry corruption must not abort a heal. Preserve the
|
||||
// counters for diagnostics, but do not derive a percentage from a
|
||||
// double-counted or overflowing ledger.
|
||||
self.mark_unknown();
|
||||
return;
|
||||
}
|
||||
self.refresh_progress_percentage();
|
||||
self.refresh_estimated_completion_time();
|
||||
}
|
||||
@@ -69,50 +226,88 @@ impl HealProgress {
|
||||
pub fn set_total_baseline(&mut self, objects_total_count: u64, objects_total_size: u64) {
|
||||
self.objects_total_count = objects_total_count;
|
||||
self.objects_total_size = objects_total_size;
|
||||
self.baseline_known = true;
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
self.refresh_progress_percentage();
|
||||
self.refresh_estimated_completion_time();
|
||||
}
|
||||
|
||||
pub fn set_total_baseline_with_generation(&mut self, objects_total_count: u64, objects_total_size: u64, generation: u64) {
|
||||
self.baseline_generation = Some(generation);
|
||||
self.set_total_baseline(objects_total_count, objects_total_size);
|
||||
}
|
||||
|
||||
pub fn record_skipped_new_version(&mut self) {
|
||||
self.skipped_new_versions = self.skipped_new_versions.saturating_add(1);
|
||||
let Some(next) = self.skipped_new_versions.checked_add(1) else {
|
||||
self.mark_unknown();
|
||||
return;
|
||||
};
|
||||
self.skipped_new_versions = next;
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
self.refresh_progress_percentage();
|
||||
self.refresh_estimated_completion_time();
|
||||
}
|
||||
|
||||
pub fn record_skipped_ilm_expired(&mut self) {
|
||||
self.skipped_ilm_expired = self.skipped_ilm_expired.saturating_add(1);
|
||||
let Some(next) = self.skipped_ilm_expired.checked_add(1) else {
|
||||
self.mark_unknown();
|
||||
return;
|
||||
};
|
||||
self.skipped_ilm_expired = next;
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
self.refresh_progress_percentage();
|
||||
self.refresh_estimated_completion_time();
|
||||
}
|
||||
|
||||
fn completed_for_baseline(&self) -> u64 {
|
||||
fn completed_for_baseline(&self) -> Option<u64> {
|
||||
self.objects_healed
|
||||
.saturating_add(self.objects_failed)
|
||||
.saturating_add(self.skipped_new_versions)
|
||||
.saturating_add(self.skipped_ilm_expired)
|
||||
.checked_add(self.objects_failed)?
|
||||
.checked_add(self.skipped_objects)?
|
||||
.checked_add(self.skipped_new_versions)?
|
||||
.checked_add(self.skipped_ilm_expired)
|
||||
}
|
||||
|
||||
pub(crate) fn refresh_progress_percentage(&mut self) {
|
||||
if self.ledger_complete {
|
||||
self.progress_state = HealProgressState::Completed;
|
||||
self.progress_percentage = 100.0;
|
||||
return;
|
||||
}
|
||||
if self.counter_unknown {
|
||||
self.progress_state = HealProgressState::Unknown;
|
||||
self.progress_percentage = 0.0;
|
||||
return;
|
||||
}
|
||||
if !self.baseline_known {
|
||||
self.progress_state = HealProgressState::Indeterminate;
|
||||
self.progress_percentage = 0.0;
|
||||
self.estimated_completion_time = None;
|
||||
return;
|
||||
}
|
||||
if self.objects_total_size > 0 {
|
||||
self.progress_percentage = ((self.bytes_processed as f64 / self.objects_total_size as f64) * 100.0).min(100.0);
|
||||
self.progress_percentage = self.progress_percentage.min(99.999);
|
||||
self.progress_state = HealProgressState::Running;
|
||||
return;
|
||||
}
|
||||
if self.objects_total_count > 0 {
|
||||
let completed = self.completed_for_baseline();
|
||||
let Some(completed) = self.completed_for_baseline() else {
|
||||
self.progress_state = HealProgressState::Unknown;
|
||||
self.progress_percentage = 0.0;
|
||||
return;
|
||||
};
|
||||
self.progress_percentage = ((completed as f64 / self.objects_total_count as f64) * 100.0).min(100.0);
|
||||
self.progress_percentage = self.progress_percentage.min(99.999);
|
||||
self.progress_state = HealProgressState::Running;
|
||||
return;
|
||||
}
|
||||
|
||||
let total = self
|
||||
.objects_scanned
|
||||
.saturating_add(self.objects_healed)
|
||||
.saturating_add(self.objects_failed);
|
||||
if total > 0 {
|
||||
self.progress_percentage = (self.objects_healed as f64 / total as f64) * 100.0;
|
||||
if self.baseline_known {
|
||||
self.progress_state = HealProgressState::Running;
|
||||
self.progress_percentage = 0.0;
|
||||
return;
|
||||
}
|
||||
self.progress_state = HealProgressState::Indeterminate;
|
||||
self.progress_percentage = 0.0;
|
||||
}
|
||||
|
||||
pub fn set_current_object(&mut self, object: Option<String>) {
|
||||
@@ -125,7 +320,11 @@ impl HealProgress {
|
||||
self.estimated_completion_time = None;
|
||||
return;
|
||||
};
|
||||
if self.is_completed() || !(0.0..100.0).contains(&self.progress_percentage) || self.bytes_processed == 0 {
|
||||
if self.is_completed()
|
||||
|| self.progress_percentage <= 0.0
|
||||
|| self.progress_percentage >= 100.0
|
||||
|| self.bytes_processed == 0
|
||||
{
|
||||
self.estimated_completion_time = None;
|
||||
return;
|
||||
}
|
||||
@@ -142,18 +341,39 @@ impl HealProgress {
|
||||
}
|
||||
|
||||
pub fn is_completed(&self) -> bool {
|
||||
if self.progress_percentage >= 100.0 {
|
||||
return true;
|
||||
}
|
||||
if self.objects_total_count > 0 || self.objects_total_size > 0 {
|
||||
return false;
|
||||
}
|
||||
self.ledger_complete
|
||||
}
|
||||
|
||||
self.objects_scanned > 0 && self.objects_healed.saturating_add(self.objects_failed) >= self.objects_scanned
|
||||
/// Mark telemetry unknown while allowing the underlying heal operation to
|
||||
/// continue. This is used for corrupt/overflowing counters at the
|
||||
/// observability boundary; it must never turn a successful heal into an
|
||||
/// execution error.
|
||||
pub fn mark_unknown(&mut self) {
|
||||
self.counter_unknown = true;
|
||||
self.progress_state = HealProgressState::Unknown;
|
||||
self.ledger_complete = false;
|
||||
self.progress_percentage = 0.0;
|
||||
self.estimated_completion_time = None;
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
}
|
||||
|
||||
/// Mark the object ledger terminal only after the enclosing task has
|
||||
/// committed all durable resume state and cleanup fences.
|
||||
pub fn mark_completed(&mut self) {
|
||||
let telemetry_unknown = self.counter_unknown || self.progress_state == HealProgressState::Unknown;
|
||||
self.ledger_complete = true;
|
||||
if !telemetry_unknown {
|
||||
self.progress_state = HealProgressState::Completed;
|
||||
}
|
||||
self.progress_percentage = 100.0;
|
||||
self.last_update_time = Some(SystemTime::now());
|
||||
self.estimated_completion_time = None;
|
||||
}
|
||||
|
||||
pub fn get_success_rate(&self) -> f64 {
|
||||
let total = self.objects_healed + self.objects_failed;
|
||||
let Some(total) = self.objects_healed.checked_add(self.objects_failed) else {
|
||||
return 0.0;
|
||||
};
|
||||
if total > 0 {
|
||||
(self.objects_healed as f64 / total as f64) * 100.0
|
||||
} else {
|
||||
@@ -230,6 +450,7 @@ mod tests {
|
||||
assert_eq!(progress.objects_scanned, 0);
|
||||
assert_eq!(progress.objects_healed, 0);
|
||||
assert_eq!(progress.objects_failed, 0);
|
||||
assert_eq!(progress.skipped_objects, 0);
|
||||
assert_eq!(progress.skipped_new_versions, 0);
|
||||
assert_eq!(progress.skipped_ilm_expired, 0);
|
||||
assert_eq!(progress.objects_total_count, 0);
|
||||
@@ -250,10 +471,8 @@ mod tests {
|
||||
assert_eq!(progress.objects_healed, 8);
|
||||
assert_eq!(progress.objects_failed, 2);
|
||||
assert_eq!(progress.bytes_processed, 1024);
|
||||
// Progress percentage should be calculated based on healed/total
|
||||
// total = scanned + healed + failed = 10 + 8 + 2 = 20
|
||||
// healed/total = 8/20 = 0.4 = 40%
|
||||
assert!((progress.progress_percentage - 40.0).abs() < 0.001);
|
||||
assert_eq!(progress.progress_state, HealProgressState::Indeterminate);
|
||||
assert_eq!(progress.progress_percentage, 0.0);
|
||||
assert!(progress.last_update_time.is_some());
|
||||
}
|
||||
|
||||
@@ -262,7 +481,8 @@ mod tests {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.start_time = Some(SystemTime::now() - Duration::from_secs(10));
|
||||
|
||||
progress.update_progress(100, 25, 0, 4096);
|
||||
progress.set_total_baseline(100, 16384);
|
||||
progress.update_progress(25, 25, 0, 4096);
|
||||
|
||||
let eta = progress
|
||||
.estimated_completion_time
|
||||
@@ -275,7 +495,7 @@ mod tests {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.set_total_baseline(10, 8192);
|
||||
|
||||
progress.update_progress(100, 25, 0, 4096);
|
||||
progress.update_progress(25, 25, 0, 4096);
|
||||
|
||||
assert!((progress.progress_percentage - 50.0).abs() < 0.001);
|
||||
}
|
||||
@@ -285,7 +505,7 @@ mod tests {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.set_total_baseline(10, 0);
|
||||
|
||||
progress.update_progress(100, 3, 2, 0);
|
||||
progress.update_progress(5, 3, 2, 0);
|
||||
|
||||
assert!((progress.progress_percentage - 50.0).abs() < 0.001);
|
||||
}
|
||||
@@ -295,7 +515,7 @@ mod tests {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.set_total_baseline(10, 0);
|
||||
|
||||
progress.update_progress(100, 3, 2, 0);
|
||||
progress.update_progress(5, 3, 2, 0);
|
||||
progress.record_skipped_new_version();
|
||||
|
||||
assert_eq!(progress.skipped_new_versions, 1);
|
||||
@@ -336,7 +556,8 @@ mod tests {
|
||||
fn test_heal_progress_update_progress_all_healed() {
|
||||
let mut progress = HealProgress::new();
|
||||
// When scanned=0, healed=10, failed=0: total=10, progress = 10/10 = 100%
|
||||
progress.update_progress(0, 10, 0, 2048);
|
||||
progress.update_progress(10, 10, 0, 2048);
|
||||
progress.mark_completed();
|
||||
|
||||
// All healed, should be 100%
|
||||
assert!((progress.progress_percentage - 100.0).abs() < 0.001);
|
||||
@@ -394,6 +615,7 @@ mod tests {
|
||||
assert_eq!(json["objectsScanned"], 10);
|
||||
assert_eq!(json["objectsHealed"], 8);
|
||||
assert_eq!(json["objectsFailed"], 2);
|
||||
assert_eq!(json["skippedObjects"], 0);
|
||||
assert_eq!(json["skippedNewVersions"], 0);
|
||||
assert_eq!(json["skippedIlmExpired"], 0);
|
||||
assert_eq!(json["bytesProcessed"], 1024);
|
||||
@@ -405,6 +627,7 @@ mod tests {
|
||||
fn test_heal_progress_is_completed_by_percentage() {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.update_progress(10, 10, 0, 1024);
|
||||
progress.mark_completed();
|
||||
|
||||
assert!(progress.is_completed());
|
||||
}
|
||||
@@ -415,7 +638,7 @@ mod tests {
|
||||
progress.objects_scanned = 10;
|
||||
progress.objects_healed = 8;
|
||||
progress.objects_failed = 2;
|
||||
// healed + failed = 8 + 2 = 10 >= scanned = 10
|
||||
progress.mark_completed();
|
||||
assert!(progress.is_completed());
|
||||
}
|
||||
|
||||
@@ -455,6 +678,66 @@ mod tests {
|
||||
assert!((progress.get_success_rate() - 100.0).abs() < 0.001);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_object_progress_reaches_terminal_100() {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.update_object_progress(1, 1, 0, 0, 128);
|
||||
assert!(!progress.is_completed());
|
||||
progress.mark_completed();
|
||||
assert!(progress.is_completed());
|
||||
assert_eq!(progress.progress_percentage, 100.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_without_baseline_is_indeterminate() {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.update_object_progress(1, 1, 0, 0, 128);
|
||||
assert_eq!(progress.progress_state, HealProgressState::Indeterminate);
|
||||
assert_eq!(progress.progress_percentage, 0.0);
|
||||
assert!(progress.estimated_completion_time.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_retry_is_exactly_once() {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.set_total_baseline(1, 128);
|
||||
progress.update_object_progress(1, 1, 0, 0, 128);
|
||||
progress.update_object_progress(1, 1, 0, 0, 128);
|
||||
assert_eq!(progress.objects_scanned, 1);
|
||||
assert_eq!(progress.objects_healed, 1);
|
||||
assert_eq!(progress.bytes_processed, 128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_never_triggers_cleanup_before_terminal_ledger_empty() {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.progress_percentage = 100.0;
|
||||
assert!(!progress.is_completed());
|
||||
progress.mark_completed();
|
||||
assert!(progress.is_completed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_counter_overflow_is_marked_unknown_without_aborting_completed_heal() {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.update_object_progress(u64::MAX, u64::MAX, 1, 0, 0);
|
||||
assert_eq!(progress.progress_state, HealProgressState::Unknown);
|
||||
progress.mark_completed();
|
||||
assert!(progress.is_completed());
|
||||
assert_eq!(progress.progress_state, HealProgressState::Unknown);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stage_updates_do_not_double_count_object_outcomes() {
|
||||
let mut progress = HealProgress::new();
|
||||
progress.update_object_progress(2, 1, 0, 1, 256);
|
||||
progress.update_stage(3, 4);
|
||||
assert_eq!(progress.kind, HealProgressKind::ObjectSweep);
|
||||
assert_eq!(progress.objects_scanned, 2);
|
||||
assert_eq!(progress.objects_healed, 1);
|
||||
assert_eq!(progress.skipped_objects, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_heal_statistics_new() {
|
||||
let stats = HealStatistics::new();
|
||||
|
||||
@@ -340,6 +340,12 @@ pub struct ResumeState {
|
||||
pub failed_objects: u64,
|
||||
/// skipped objects
|
||||
pub skipped_objects: u64,
|
||||
/// Terminal versions skipped because they were newer than the heal start.
|
||||
#[serde(default)]
|
||||
pub skipped_new_versions: u64,
|
||||
/// Terminal versions handed to lifecycle expiry.
|
||||
#[serde(default)]
|
||||
pub skipped_ilm_expired: u64,
|
||||
/// current bucket
|
||||
pub current_bucket: Option<String>,
|
||||
/// current object
|
||||
@@ -354,6 +360,24 @@ pub struct ResumeState {
|
||||
pub retry_count: u32,
|
||||
/// max retries
|
||||
pub max_retries: u32,
|
||||
/// Bytes accounted by the object ledger; additive for old snapshots.
|
||||
#[serde(default)]
|
||||
pub processed_bytes: u64,
|
||||
/// Total bytes from a complete usage snapshot, when available.
|
||||
#[serde(default)]
|
||||
pub total_bytes: u64,
|
||||
/// Generation of the usage snapshot used for the baseline.
|
||||
#[serde(default)]
|
||||
pub baseline_generation: Option<u64>,
|
||||
/// Whether the usage baseline is known. Missing in old snapshots means
|
||||
/// indeterminate rather than a measured zero baseline.
|
||||
#[serde(default)]
|
||||
pub baseline_known: bool,
|
||||
/// Persistent telemetry fence for counter/byte overflow or corruption.
|
||||
/// It must survive a restart so a saturated snapshot is never presented as
|
||||
/// a measured percentage on the next resume.
|
||||
#[serde(default)]
|
||||
pub counter_unknown: bool,
|
||||
}
|
||||
|
||||
impl ResumeState {
|
||||
@@ -377,6 +401,8 @@ impl ResumeState {
|
||||
successful_objects: 0,
|
||||
failed_objects: 0,
|
||||
skipped_objects: 0,
|
||||
skipped_new_versions: 0,
|
||||
skipped_ilm_expired: 0,
|
||||
current_bucket: None,
|
||||
current_object: None,
|
||||
completed_buckets: Vec::new(),
|
||||
@@ -384,6 +410,11 @@ impl ResumeState {
|
||||
error_message: None,
|
||||
retry_count: 0,
|
||||
max_retries: 3,
|
||||
processed_bytes: 0,
|
||||
total_bytes: 0,
|
||||
baseline_generation: None,
|
||||
baseline_known: false,
|
||||
counter_unknown: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,6 +443,39 @@ impl ResumeState {
|
||||
self.last_update = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
|
||||
}
|
||||
|
||||
pub fn update_progress_with_bytes(
|
||||
&mut self,
|
||||
processed: u64,
|
||||
successful: u64,
|
||||
failed: u64,
|
||||
skipped: u64,
|
||||
processed_bytes: u64,
|
||||
) {
|
||||
self.update_progress(processed, successful, failed, skipped);
|
||||
self.processed_bytes = processed_bytes;
|
||||
}
|
||||
|
||||
pub fn set_skipped_version_counts(&mut self, new_versions: u64, ilm_expired: u64) {
|
||||
self.skipped_new_versions = new_versions;
|
||||
self.skipped_ilm_expired = ilm_expired;
|
||||
self.last_update = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
|
||||
}
|
||||
|
||||
pub fn set_progress_baseline(&mut self, total_objects: u64, total_bytes: u64, generation: Option<u64>) {
|
||||
self.total_objects = total_objects;
|
||||
self.total_bytes = total_bytes;
|
||||
self.baseline_generation = generation;
|
||||
// This method is called only after a complete usage snapshot has been
|
||||
// validated. A complete but empty snapshot is still a known baseline.
|
||||
self.baseline_known = true;
|
||||
self.last_update = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
|
||||
}
|
||||
|
||||
pub fn mark_counter_unknown(&mut self) {
|
||||
self.counter_unknown = true;
|
||||
self.last_update = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
|
||||
}
|
||||
|
||||
pub fn set_current_item(&mut self, bucket: Option<String>, object: Option<String>) {
|
||||
self.current_bucket = bucket;
|
||||
self.current_object = object;
|
||||
@@ -454,6 +518,10 @@ impl ResumeState {
|
||||
self.successful_objects = 0;
|
||||
self.failed_objects = 0;
|
||||
self.skipped_objects = 0;
|
||||
self.skipped_new_versions = 0;
|
||||
self.skipped_ilm_expired = 0;
|
||||
self.processed_bytes = 0;
|
||||
self.counter_unknown = false;
|
||||
self.completed = false;
|
||||
// A retry re-scans every bucket from the beginning, so the version
|
||||
// cursor must be cleared too — otherwise the retry would resume mid-scan.
|
||||
@@ -476,14 +544,28 @@ impl ResumeState {
|
||||
}
|
||||
|
||||
pub fn get_progress_percentage(&self) -> f64 {
|
||||
if self.completed {
|
||||
return 100.0;
|
||||
}
|
||||
if self.counter_unknown {
|
||||
return 0.0;
|
||||
}
|
||||
if !self.baseline_known {
|
||||
return 0.0;
|
||||
}
|
||||
if self.total_bytes > 0 {
|
||||
return ((self.processed_bytes as f64 / self.total_bytes as f64) * 100.0).min(99.999);
|
||||
}
|
||||
if self.total_objects == 0 {
|
||||
return 0.0;
|
||||
}
|
||||
(self.processed_objects as f64 / self.total_objects as f64) * 100.0
|
||||
((self.processed_objects as f64 / self.total_objects as f64) * 100.0).min(99.999)
|
||||
}
|
||||
|
||||
pub fn get_success_rate(&self) -> f64 {
|
||||
let total = self.successful_objects + self.failed_objects;
|
||||
let Some(total) = self.successful_objects.checked_add(self.failed_objects) else {
|
||||
return 0.0;
|
||||
};
|
||||
if total == 0 {
|
||||
return 0.0;
|
||||
}
|
||||
@@ -754,6 +836,14 @@ impl ResumeManager {
|
||||
state.successful_objects = 0;
|
||||
state.failed_objects = 0;
|
||||
state.skipped_objects = 0;
|
||||
state.skipped_new_versions = 0;
|
||||
state.skipped_ilm_expired = 0;
|
||||
state.processed_bytes = 0;
|
||||
state.total_objects = 0;
|
||||
state.total_bytes = 0;
|
||||
state.baseline_generation = None;
|
||||
state.baseline_known = false;
|
||||
state.counter_unknown = false;
|
||||
state.completed = false;
|
||||
state.completed_buckets.clear();
|
||||
state.schema_version = CURRENT_RESUME_SCHEMA;
|
||||
@@ -838,6 +928,41 @@ impl ResumeManager {
|
||||
self.save_state_throttled().await
|
||||
}
|
||||
|
||||
pub async fn update_progress_with_bytes(
|
||||
&self,
|
||||
processed: u64,
|
||||
successful: u64,
|
||||
failed: u64,
|
||||
skipped: u64,
|
||||
processed_bytes: u64,
|
||||
) -> Result<()> {
|
||||
let mut state = self.state.write().await;
|
||||
state.update_progress_with_bytes(processed, successful, failed, skipped, processed_bytes);
|
||||
drop(state);
|
||||
self.save_state_throttled().await
|
||||
}
|
||||
|
||||
pub async fn set_progress_baseline(&self, total_objects: u64, total_bytes: u64, generation: Option<u64>) -> Result<()> {
|
||||
let mut state = self.state.write().await;
|
||||
state.set_progress_baseline(total_objects, total_bytes, generation);
|
||||
drop(state);
|
||||
self.save_state_throttled().await
|
||||
}
|
||||
|
||||
pub async fn mark_counter_unknown(&self) -> Result<()> {
|
||||
let mut state = self.state.write().await;
|
||||
state.mark_counter_unknown();
|
||||
drop(state);
|
||||
self.save_state().await
|
||||
}
|
||||
|
||||
pub async fn set_skipped_version_counts(&self, new_versions: u64, ilm_expired: u64) -> Result<()> {
|
||||
let mut state = self.state.write().await;
|
||||
state.set_skipped_version_counts(new_versions, ilm_expired);
|
||||
drop(state);
|
||||
self.save_state_throttled().await
|
||||
}
|
||||
|
||||
/// Set current item. Called once per healed object, so persistence is
|
||||
/// throttled: the in-memory state always updates, but the snapshot is only
|
||||
/// written every `PERSIST_EVERY_MUTATIONS` calls or `PERSIST_INTERVAL`.
|
||||
|
||||
@@ -57,6 +57,30 @@ pub struct ResumeCheckpoint {
|
||||
pub failed_objects: HashSet<String>,
|
||||
/// skipped objects
|
||||
pub skipped_objects: HashSet<String>,
|
||||
/// Aggregate object ledger counters restored alongside the dedup sets.
|
||||
#[serde(default)]
|
||||
pub successful_objects: u64,
|
||||
#[serde(default)]
|
||||
pub failed_object_count: u64,
|
||||
#[serde(default)]
|
||||
pub skipped_object_count: u64,
|
||||
#[serde(default)]
|
||||
pub skipped_new_versions: u64,
|
||||
#[serde(default)]
|
||||
pub skipped_ilm_expired: u64,
|
||||
#[serde(default)]
|
||||
pub processed_bytes: u64,
|
||||
#[serde(default)]
|
||||
pub total_objects: u64,
|
||||
#[serde(default)]
|
||||
pub total_bytes: u64,
|
||||
#[serde(default)]
|
||||
pub baseline_generation: Option<u64>,
|
||||
#[serde(default)]
|
||||
pub baseline_known: bool,
|
||||
/// Persistent telemetry fence for counter/byte overflow or corruption.
|
||||
#[serde(default)]
|
||||
pub counter_unknown: bool,
|
||||
}
|
||||
|
||||
impl ResumeCheckpoint {
|
||||
@@ -70,6 +94,17 @@ impl ResumeCheckpoint {
|
||||
processed_objects: HashSet::new(),
|
||||
failed_objects: HashSet::new(),
|
||||
skipped_objects: HashSet::new(),
|
||||
successful_objects: 0,
|
||||
failed_object_count: 0,
|
||||
skipped_object_count: 0,
|
||||
skipped_new_versions: 0,
|
||||
skipped_ilm_expired: 0,
|
||||
processed_bytes: 0,
|
||||
total_objects: 0,
|
||||
total_bytes: 0,
|
||||
baseline_generation: None,
|
||||
baseline_known: false,
|
||||
counter_unknown: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +126,34 @@ impl ResumeCheckpoint {
|
||||
self.skipped_objects.insert(object);
|
||||
}
|
||||
|
||||
pub fn update_progress(&mut self, successful: u64, failed: u64, skipped: u64, bytes: u64) {
|
||||
self.successful_objects = successful;
|
||||
self.failed_object_count = failed;
|
||||
self.skipped_object_count = skipped;
|
||||
self.processed_bytes = bytes;
|
||||
}
|
||||
|
||||
pub fn set_progress_baseline(&mut self, total_objects: u64, total_bytes: u64, generation: Option<u64>) {
|
||||
self.total_objects = total_objects;
|
||||
self.total_bytes = total_bytes;
|
||||
self.baseline_generation = generation;
|
||||
// The caller has already validated that this is a complete snapshot;
|
||||
// preserve the distinction between a known empty scope and an old
|
||||
// checkpoint that omitted all baseline fields.
|
||||
self.baseline_known = true;
|
||||
}
|
||||
|
||||
pub fn mark_counter_unknown(&mut self) {
|
||||
self.counter_unknown = true;
|
||||
self.checkpoint_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
|
||||
}
|
||||
|
||||
pub fn set_skipped_version_counts(&mut self, new_versions: u64, ilm_expired: u64) {
|
||||
self.skipped_new_versions = new_versions;
|
||||
self.skipped_ilm_expired = ilm_expired;
|
||||
self.checkpoint_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
|
||||
}
|
||||
|
||||
/// Advance past a fully-processed page: objects below `object_index` are
|
||||
/// skipped by position on resume, so the per-object sets no longer need
|
||||
/// their entries and would otherwise grow with the whole bucket.
|
||||
@@ -107,6 +170,17 @@ impl ResumeCheckpoint {
|
||||
self.update_position(0, 0);
|
||||
self.processed_objects.clear();
|
||||
self.skipped_objects.clear();
|
||||
self.successful_objects = 0;
|
||||
self.failed_object_count = 0;
|
||||
self.skipped_object_count = 0;
|
||||
self.skipped_new_versions = 0;
|
||||
self.skipped_ilm_expired = 0;
|
||||
self.processed_bytes = 0;
|
||||
self.total_objects = 0;
|
||||
self.total_bytes = 0;
|
||||
self.baseline_generation = None;
|
||||
self.baseline_known = false;
|
||||
self.counter_unknown = false;
|
||||
self.failed_objects.clear();
|
||||
}
|
||||
}
|
||||
@@ -185,6 +259,17 @@ impl CheckpointManager {
|
||||
checkpoint.processed_objects.clear();
|
||||
checkpoint.failed_objects.clear();
|
||||
checkpoint.skipped_objects.clear();
|
||||
checkpoint.successful_objects = 0;
|
||||
checkpoint.failed_object_count = 0;
|
||||
checkpoint.skipped_object_count = 0;
|
||||
checkpoint.skipped_new_versions = 0;
|
||||
checkpoint.skipped_ilm_expired = 0;
|
||||
checkpoint.processed_bytes = 0;
|
||||
checkpoint.total_objects = 0;
|
||||
checkpoint.total_bytes = 0;
|
||||
checkpoint.baseline_generation = None;
|
||||
checkpoint.baseline_known = false;
|
||||
checkpoint.counter_unknown = false;
|
||||
checkpoint.current_bucket_index = 0;
|
||||
checkpoint.current_object_index = 0;
|
||||
checkpoint.schema_version = CURRENT_CHECKPOINT_SCHEMA;
|
||||
@@ -267,6 +352,34 @@ impl CheckpointManager {
|
||||
self.save_checkpoint_if_due().await
|
||||
}
|
||||
|
||||
pub async fn update_progress(&self, successful: u64, failed: u64, skipped: u64, bytes: u64) -> Result<()> {
|
||||
let mut checkpoint = self.checkpoint.write().await;
|
||||
checkpoint.update_progress(successful, failed, skipped, bytes);
|
||||
drop(checkpoint);
|
||||
self.save_checkpoint_if_due().await
|
||||
}
|
||||
|
||||
pub async fn set_progress_baseline(&self, total_objects: u64, total_bytes: u64, generation: Option<u64>) -> Result<()> {
|
||||
let mut checkpoint = self.checkpoint.write().await;
|
||||
checkpoint.set_progress_baseline(total_objects, total_bytes, generation);
|
||||
drop(checkpoint);
|
||||
self.save_checkpoint_throttled().await
|
||||
}
|
||||
|
||||
pub async fn mark_counter_unknown(&self) -> Result<()> {
|
||||
let mut checkpoint = self.checkpoint.write().await;
|
||||
checkpoint.mark_counter_unknown();
|
||||
drop(checkpoint);
|
||||
self.save_checkpoint().await
|
||||
}
|
||||
|
||||
pub async fn set_skipped_version_counts(&self, new_versions: u64, ilm_expired: u64) -> Result<()> {
|
||||
let mut checkpoint = self.checkpoint.write().await;
|
||||
checkpoint.set_skipped_version_counts(new_versions, ilm_expired);
|
||||
drop(checkpoint);
|
||||
self.save_checkpoint_throttled().await
|
||||
}
|
||||
|
||||
async fn save_checkpoint_if_due(&self) -> Result<()> {
|
||||
let should_save = self.throttle.lock().map(|mut throttle| throttle.record()).unwrap_or(true);
|
||||
if !should_save {
|
||||
|
||||
@@ -1296,6 +1296,7 @@ async fn test_resume_state_progress() {
|
||||
assert_eq!(progress, 0.0); // total_objects is 0
|
||||
|
||||
state.total_objects = 100;
|
||||
state.baseline_known = true;
|
||||
let progress = state.get_progress_percentage();
|
||||
assert_eq!(progress, 10.0);
|
||||
}
|
||||
@@ -1639,6 +1640,120 @@ async fn current_normal_resume_schema_preserves_progress() {
|
||||
temp_dir.close().expect("remove schema test directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_checkpoint_restores_bytes_and_generation() {
|
||||
let mut checkpoint = ResumeCheckpoint::new("progress-checkpoint".to_string());
|
||||
checkpoint.set_progress_baseline(9, 4096, Some(77));
|
||||
checkpoint.update_progress(4, 1, 2, 2048);
|
||||
checkpoint.set_skipped_version_counts(3, 1);
|
||||
checkpoint.mark_counter_unknown();
|
||||
|
||||
let restored: ResumeCheckpoint =
|
||||
serde_json::from_slice(&serde_json::to_vec(&checkpoint).expect("serialize checkpoint")).expect("deserialize checkpoint");
|
||||
assert_eq!(restored.processed_bytes, 2048);
|
||||
assert_eq!(restored.total_objects, 9);
|
||||
assert_eq!(restored.total_bytes, 4096);
|
||||
assert_eq!(restored.baseline_generation, Some(77));
|
||||
assert!(restored.baseline_known);
|
||||
assert_eq!(restored.skipped_new_versions, 3);
|
||||
assert_eq!(restored.skipped_ilm_expired, 1);
|
||||
assert!(restored.counter_unknown);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_progress_schema_migrates_missing_fields_to_unknown() {
|
||||
let state = ResumeState::new(
|
||||
"legacy-progress".to_string(),
|
||||
"erasure_set".to_string(),
|
||||
"pool_0_set_0".to_string(),
|
||||
Vec::new(),
|
||||
);
|
||||
let mut value = serde_json::to_value(state).expect("serialize legacy-compatible state");
|
||||
let object = value.as_object_mut().expect("state must be an object");
|
||||
for field in [
|
||||
"processed_bytes",
|
||||
"total_bytes",
|
||||
"baseline_generation",
|
||||
"baseline_known",
|
||||
"skipped_new_versions",
|
||||
"skipped_ilm_expired",
|
||||
] {
|
||||
object.remove(field);
|
||||
}
|
||||
object.insert("total_objects".to_string(), serde_json::json!(10));
|
||||
object.insert("processed_objects".to_string(), serde_json::json!(5));
|
||||
let restored: ResumeState = serde_json::from_value(value).expect("deserialize old progress state");
|
||||
assert_eq!(restored.processed_bytes, 0);
|
||||
assert_eq!(restored.total_bytes, 0);
|
||||
assert_eq!(restored.baseline_generation, None);
|
||||
assert!(!restored.baseline_known, "missing baseline must remain unknown");
|
||||
assert_eq!(restored.get_progress_percentage(), 0.0);
|
||||
assert_eq!(restored.skipped_new_versions, 0);
|
||||
assert_eq!(restored.skipped_ilm_expired, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_counter_unknown_survives_resume_round_trip() {
|
||||
let mut state = ResumeState::new(
|
||||
"overflow-progress".to_string(),
|
||||
"erasure_set".to_string(),
|
||||
"pool_0_set_0".to_string(),
|
||||
Vec::new(),
|
||||
);
|
||||
state.mark_counter_unknown();
|
||||
|
||||
let restored: ResumeState =
|
||||
serde_json::from_slice(&serde_json::to_vec(&state).expect("serialize resume state")).expect("deserialize resume state");
|
||||
assert!(restored.counter_unknown);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn checkpoint_progress_survives_a_torn_resume_summary_write() {
|
||||
let (_temp_dir, disk) = schema_test_disk().await;
|
||||
let task_id = ResumeUtils::generate_task_id();
|
||||
let _resume = ResumeManager::new(
|
||||
disk.clone(),
|
||||
task_id.clone(),
|
||||
"erasure_set".to_string(),
|
||||
"pool_0_set_0".to_string(),
|
||||
vec!["bucket".to_string()],
|
||||
)
|
||||
.await
|
||||
.expect("resume state should persist");
|
||||
let checkpoint = CheckpointManager::new(disk.clone(), task_id.clone())
|
||||
.await
|
||||
.expect("checkpoint should persist");
|
||||
|
||||
// This is the ordering used by the erasure-set loop: the checkpoint is
|
||||
// durable before the summary write. Stop here to model a crash in the
|
||||
// inter-store window and verify that the recovery authority retains the
|
||||
// telemetry fence and bytes.
|
||||
checkpoint
|
||||
.update_progress(3, 0, 0, 1024)
|
||||
.await
|
||||
.expect("checkpoint progress should persist");
|
||||
checkpoint.mark_counter_unknown().await.expect("unknown fence should persist");
|
||||
checkpoint
|
||||
.update_position(0, 3)
|
||||
.await
|
||||
.expect("checkpoint position should persist");
|
||||
|
||||
let restored_checkpoint = CheckpointManager::load_from_disk(disk.clone(), &task_id)
|
||||
.await
|
||||
.expect("checkpoint should reload")
|
||||
.get_checkpoint()
|
||||
.await;
|
||||
let restored_resume = ResumeManager::load_from_disk(disk, &task_id)
|
||||
.await
|
||||
.expect("resume summary should reload")
|
||||
.get_state()
|
||||
.await;
|
||||
assert!(restored_checkpoint.counter_unknown);
|
||||
assert_eq!(restored_checkpoint.processed_bytes, 1024);
|
||||
assert_eq!(restored_checkpoint.current_object_index, 3);
|
||||
assert!(!restored_resume.counter_unknown, "summary is intentionally the torn/older store");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn future_resume_and_checkpoint_schemas_are_rejected() {
|
||||
let (temp_dir, disk) = schema_test_disk().await;
|
||||
|
||||
@@ -19,6 +19,8 @@ use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
use rustfs_common::heal_channel::{HealOpts, HealScanMode};
|
||||
use rustfs_madmin::heal_commands::HealResultItem;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::Arc;
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
@@ -34,6 +36,9 @@ pub use super::{HealObjectInfo, HealObjectOptions, HealPutObjReader};
|
||||
pub struct HealBucketUsageBaseline {
|
||||
pub objects_count: u64,
|
||||
pub bytes: u64,
|
||||
/// Stable identity of the validated usage snapshot and selected scope.
|
||||
/// `None` is retained for test/legacy providers that cannot expose one.
|
||||
pub generation: Option<u64>,
|
||||
}
|
||||
|
||||
pub struct HealLifecycleExpiryContext {
|
||||
@@ -785,11 +790,30 @@ impl HealStorageAPI for ECStoreHealStorage {
|
||||
let mut baseline = HealBucketUsageBaseline::default();
|
||||
for bucket in buckets {
|
||||
if let Some(usage) = info.buckets_usage.get(bucket) {
|
||||
baseline.objects_count = baseline.objects_count.saturating_add(usage.objects_count);
|
||||
baseline.bytes = baseline.bytes.saturating_add(usage.size);
|
||||
baseline.objects_count = match baseline.objects_count.checked_add(usage.objects_count) {
|
||||
Some(total) => total,
|
||||
// A corrupt/overflowing usage snapshot is not a usable
|
||||
// denominator. Leave progress indeterminate instead of
|
||||
// turning saturation into a plausible percentage.
|
||||
None => return Ok(None),
|
||||
};
|
||||
baseline.bytes = match baseline.bytes.checked_add(usage.size) {
|
||||
Some(total) => total,
|
||||
None => return Ok(None),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let identity = info.snapshot_identity();
|
||||
let mut hasher = DefaultHasher::new();
|
||||
identity.last_update.hash(&mut hasher);
|
||||
identity.scanner_cycle.hash(&mut hasher);
|
||||
identity.scanner_epoch.hash(&mut hasher);
|
||||
let mut scope = buckets.to_vec();
|
||||
scope.sort_unstable();
|
||||
scope.hash(&mut hasher);
|
||||
baseline.generation = Some(hasher.finish());
|
||||
|
||||
Ok(Some(baseline))
|
||||
}
|
||||
|
||||
|
||||
@@ -649,7 +649,7 @@ impl HealTask {
|
||||
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("skipped: {bucket}/{object}")));
|
||||
progress.update_progress(0, 1, 0, 0);
|
||||
progress.update_stage(1, 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -733,7 +733,7 @@ impl HealTask {
|
||||
"Heal object skipped for data usage cache after transient error"
|
||||
);
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
true
|
||||
}
|
||||
|
||||
@@ -757,7 +757,7 @@ impl HealTask {
|
||||
);
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("skipped: {bucket}/{object}")));
|
||||
progress.update_progress(4, 4, 0, 0);
|
||||
progress.update_stage(4, 4);
|
||||
true
|
||||
}
|
||||
|
||||
@@ -831,6 +831,10 @@ impl HealTask {
|
||||
|
||||
match &result {
|
||||
Ok(_) => {
|
||||
// A stage can reach its final step before the durable resume
|
||||
// ledger and cleanup fences commit. Publish terminal 100 only
|
||||
// after the enclosing operation has returned success.
|
||||
self.progress.write().await.mark_completed();
|
||||
let mut status = self.status.write().await;
|
||||
*status = HealTaskStatus::Completed;
|
||||
demote_to_debug_when!(self.heal_type.is_per_object(), info, target: "rustfs::heal::task", {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
/// bucket/cluster/prefix heal: the recursive bucket-objects sweep and the erasure-set usage baseline
|
||||
use super::*;
|
||||
use crate::heal::progress::{add_bytes, increment_counter};
|
||||
|
||||
impl HealTask {
|
||||
pub(super) async fn heal_bucket(&self, bucket: &str) -> Result<()> {
|
||||
@@ -32,7 +33,7 @@ impl HealTask {
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("bucket: {bucket}")));
|
||||
progress.update_progress(0, 3, 0, 0);
|
||||
progress.update_stage(0, 3);
|
||||
}
|
||||
|
||||
// Step 1: Check if bucket exists
|
||||
@@ -66,7 +67,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(1, 3, 0, 0);
|
||||
progress.update_stage(1, 3);
|
||||
}
|
||||
|
||||
// Step 2: Perform bucket heal using ecstore
|
||||
@@ -122,7 +123,7 @@ impl HealTask {
|
||||
|
||||
if !self.options.recursive {
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -142,7 +143,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
Err(Error::TaskExecutionFailed {
|
||||
message: format!("Failed to heal bucket {bucket}: {e}"),
|
||||
@@ -245,6 +246,7 @@ impl HealTask {
|
||||
let mut scanned = 0u64;
|
||||
let mut healed = 0u64;
|
||||
let mut failed = 0u64;
|
||||
let mut skipped = 0u64;
|
||||
let mut retryable_failed = 0u64;
|
||||
let mut permanent_failed = 0u64;
|
||||
let mut bytes = 0u64;
|
||||
@@ -286,14 +288,14 @@ impl HealTask {
|
||||
let mut retry = Vec::with_capacity(pending.len());
|
||||
for item in pending {
|
||||
self.check_control_flags().await?;
|
||||
let mut telemetry_unknown = false;
|
||||
let object = item.name.as_str();
|
||||
if retry_attempt == 0 {
|
||||
scanned = scanned.saturating_add(1);
|
||||
telemetry_unknown |= !increment_counter(&mut scanned);
|
||||
}
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("{bucket}/{object}")));
|
||||
progress.update_progress(scanned, healed, failed, bytes);
|
||||
}
|
||||
|
||||
let error = match self
|
||||
@@ -304,13 +306,13 @@ impl HealTask {
|
||||
.await
|
||||
{
|
||||
Ok((result, None)) => {
|
||||
healed = healed.saturating_add(1);
|
||||
bytes = bytes.saturating_add(u64::try_from(result.object_size).unwrap_or_default());
|
||||
telemetry_unknown |= !increment_counter(&mut healed);
|
||||
telemetry_unknown |= !add_bytes(&mut bytes, u64::try_from(result.object_size).unwrap_or(u64::MAX));
|
||||
self.record_result_item(result).await;
|
||||
None
|
||||
}
|
||||
Ok((_, Some(err))) if is_missing_object_dir_heal_result(object, &err) => {
|
||||
healed = healed.saturating_add(1);
|
||||
telemetry_unknown |= !increment_counter(&mut healed);
|
||||
debug!(
|
||||
target: "rustfs::heal::task",
|
||||
event = EVENT_HEAL_BUCKET_RESULT,
|
||||
@@ -329,6 +331,7 @@ impl HealTask {
|
||||
|
||||
if let Some(err) = error {
|
||||
if Self::should_skip_data_usage_cache_heal_error(bucket, object, &err) {
|
||||
telemetry_unknown |= !increment_counter(&mut skipped);
|
||||
warn!(
|
||||
target: "rustfs::heal::task",
|
||||
event = EVENT_HEAL_BUCKET_RESULT,
|
||||
@@ -357,7 +360,7 @@ impl HealTask {
|
||||
);
|
||||
retry.push(item);
|
||||
} else {
|
||||
failed = failed.saturating_add(1);
|
||||
telemetry_unknown |= !increment_counter(&mut failed);
|
||||
if err.is_recoverable_heal() {
|
||||
retryable_failed = retryable_failed.saturating_add(1);
|
||||
} else {
|
||||
@@ -384,7 +387,10 @@ impl HealTask {
|
||||
}
|
||||
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(scanned, healed, failed, bytes);
|
||||
progress.update_object_progress(scanned, healed, failed, skipped, bytes);
|
||||
if telemetry_unknown {
|
||||
progress.mark_unknown();
|
||||
}
|
||||
}
|
||||
pending = retry;
|
||||
retry_attempt = retry_attempt.saturating_add(1);
|
||||
@@ -431,7 +437,7 @@ impl HealTask {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn apply_erasure_set_usage_baseline(&self, buckets: &[String]) -> Result<()> {
|
||||
pub(super) async fn apply_erasure_set_usage_baseline(&self, buckets: &[String], set_disk_id: &str) -> Result<()> {
|
||||
let baseline = match self
|
||||
.await_with_control(self.storage.erasure_set_usage_baseline(buckets))
|
||||
.await
|
||||
@@ -442,9 +448,26 @@ impl HealTask {
|
||||
Err(_) => return Ok(()),
|
||||
};
|
||||
|
||||
let HealBucketUsageBaseline { objects_count, bytes } = baseline;
|
||||
let HealBucketUsageBaseline {
|
||||
objects_count,
|
||||
bytes,
|
||||
generation,
|
||||
} = baseline;
|
||||
let generation = generation.map(|snapshot_generation| {
|
||||
use std::hash::{Hash, Hasher};
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
snapshot_generation.hash(&mut hasher);
|
||||
set_disk_id.hash(&mut hasher);
|
||||
self.options.pool_index.hash(&mut hasher);
|
||||
self.options.set_index.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
});
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_total_baseline(objects_count, bytes);
|
||||
if let Some(generation) = generation {
|
||||
progress.set_total_baseline_with_generation(objects_count, bytes, generation);
|
||||
} else {
|
||||
progress.set_total_baseline(objects_count, bytes);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl HealTask {
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("erasure_set: {} ({} buckets)", set_disk_id, buckets.len())));
|
||||
progress.update_progress(0, 4, 0, 0);
|
||||
progress.update_stage(0, 4);
|
||||
}
|
||||
|
||||
let is_auto_replacement = matches!(self.source, HealRequestSource::AutoHeal) && !self.heal_endpoints.is_empty();
|
||||
@@ -158,7 +158,7 @@ impl HealTask {
|
||||
None
|
||||
};
|
||||
|
||||
self.apply_erasure_set_usage_baseline(&buckets).await?;
|
||||
self.apply_erasure_set_usage_baseline(&buckets, &set_disk_id).await?;
|
||||
|
||||
let healing_marker = format!("{set_disk_id}:{}", self.id);
|
||||
if let Some((disk, resume_manager, _)) = replacement_resume.as_ref() {
|
||||
@@ -244,7 +244,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(4, 4, 0, 0);
|
||||
progress.update_stage(4, 4);
|
||||
}
|
||||
return Err(Error::TaskExecutionFailed {
|
||||
message: format!("Failed to heal disk format for {set_disk_id}: {e}"),
|
||||
@@ -297,7 +297,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(4, 4, 0, 0);
|
||||
progress.update_stage(4, 4);
|
||||
}
|
||||
return Err(Error::TaskExecutionFailed {
|
||||
message: format!("Failed to heal disk format for {set_disk_id}: {e}"),
|
||||
@@ -307,7 +307,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(1, 4, 0, 0);
|
||||
progress.update_stage(1, 4);
|
||||
}
|
||||
|
||||
// The rebuilt disks are formatted now: mark them as healing so
|
||||
@@ -336,7 +336,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(2, 4, 0, 0);
|
||||
progress.update_stage(2, 4);
|
||||
}
|
||||
|
||||
// Step 3: Heal bucket structure
|
||||
@@ -420,7 +420,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 4, 0, 0);
|
||||
progress.update_stage(3, 4);
|
||||
}
|
||||
|
||||
// Step 4: Execute erasure set heal with resume
|
||||
@@ -463,9 +463,7 @@ impl HealTask {
|
||||
};
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
let bytes_processed = progress.bytes_processed;
|
||||
progress.update_progress(4, 4, 0, bytes_processed);
|
||||
self.progress.write().await.update_stage(4, 4);
|
||||
}
|
||||
|
||||
match result {
|
||||
|
||||
@@ -32,7 +32,7 @@ impl HealTask {
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("metadata: {bucket}/{object}")));
|
||||
progress.update_progress(0, 3, 0, 0);
|
||||
progress.update_stage(0, 3);
|
||||
}
|
||||
|
||||
// Step 1: Check if object exists
|
||||
@@ -74,7 +74,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(1, 3, 0, 0);
|
||||
progress.update_stage(1, 3);
|
||||
}
|
||||
|
||||
// Step 2: Perform metadata heal using ecstore
|
||||
@@ -122,7 +122,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
return Err(Error::TaskExecutionFailed {
|
||||
message: format!("Failed to heal metadata {bucket}/{object}: {e}"),
|
||||
@@ -145,7 +145,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
self.record_result_item(result).await;
|
||||
Ok(())
|
||||
@@ -167,7 +167,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
Err(Error::TaskExecutionFailed {
|
||||
message: format!("Failed to heal metadata {bucket}/{object}: {e}"),
|
||||
@@ -194,7 +194,7 @@ impl HealTask {
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("ec_decode: {bucket}/{object}")));
|
||||
progress.update_progress(0, 3, 0, 0);
|
||||
progress.update_stage(0, 3);
|
||||
}
|
||||
|
||||
// Step 1: Check if object exists
|
||||
@@ -236,7 +236,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(1, 3, 0, 0);
|
||||
progress.update_stage(1, 3);
|
||||
}
|
||||
|
||||
// Step 2: Perform EC decode heal using ecstore
|
||||
@@ -284,7 +284,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
return Err(Error::TaskExecutionFailed {
|
||||
message: format!("Failed to heal EC decode {bucket}/{object}: {e}"),
|
||||
@@ -309,7 +309,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, object_size);
|
||||
progress.update_object_progress(1, 1, 0, 0, object_size);
|
||||
}
|
||||
self.record_result_item(result).await;
|
||||
Ok(())
|
||||
@@ -331,7 +331,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
Err(Error::TaskExecutionFailed {
|
||||
message: format!("Failed to heal EC decode {bucket}/{object}: {e}"),
|
||||
|
||||
@@ -36,7 +36,7 @@ impl HealTask {
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.set_current_object(Some(format!("{bucket}/{object}")));
|
||||
progress.update_progress(0, 4, 0, 0);
|
||||
progress.update_stage(0, 4);
|
||||
}
|
||||
|
||||
// Step 1: Check if object exists and get metadata
|
||||
@@ -132,7 +132,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(1, 3, 0, 0);
|
||||
progress.update_stage(1, 3);
|
||||
}
|
||||
|
||||
// Step 2: directly call ecstore to perform heal
|
||||
@@ -187,7 +187,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
@@ -207,7 +207,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
|
||||
if Self::should_return_typed_heal_error(&e) {
|
||||
@@ -249,7 +249,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, object_size);
|
||||
progress.update_object_progress(1, 1, 0, 0, object_size);
|
||||
}
|
||||
self.record_result_item(result).await;
|
||||
Ok(())
|
||||
@@ -275,7 +275,7 @@ impl HealTask {
|
||||
);
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
@@ -295,7 +295,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(3, 3, 0, 0);
|
||||
progress.update_stage(3, 3);
|
||||
}
|
||||
|
||||
if Self::should_return_typed_heal_error(&e) {
|
||||
@@ -414,7 +414,7 @@ impl HealTask {
|
||||
|
||||
{
|
||||
let mut progress = self.progress.write().await;
|
||||
progress.update_progress(4, 4, 0, object_size);
|
||||
progress.update_object_progress(1, 1, 0, 0, object_size);
|
||||
}
|
||||
self.record_result_item(result).await;
|
||||
Ok(())
|
||||
|
||||
@@ -2096,6 +2096,7 @@ async fn erasure_set_heal_applies_usage_baseline_to_progress() {
|
||||
usage_baseline: Mutex::new(Some(HealBucketUsageBaseline {
|
||||
objects_count: 10,
|
||||
bytes: 8,
|
||||
generation: Some(1),
|
||||
})),
|
||||
..Default::default()
|
||||
});
|
||||
@@ -2119,6 +2120,8 @@ async fn erasure_set_heal_applies_usage_baseline_to_progress() {
|
||||
let progress = task.get_progress().await;
|
||||
assert_eq!(progress.objects_total_count, 10);
|
||||
assert_eq!(progress.objects_total_size, 8);
|
||||
assert!(progress.baseline_generation.is_some());
|
||||
assert!(progress.baseline_known);
|
||||
assert_eq!(progress.bytes_processed, 2);
|
||||
assert!((progress.progress_percentage - 25.0).abs() < 0.001);
|
||||
}
|
||||
|
||||
@@ -70,12 +70,6 @@ const SITE_REPLICATION_EDIT_ROUTE: &str = "/rustfs/admin/v3/site-replication/edi
|
||||
const SITE_REPLICATION_RESYNC_ROUTE: &str = "/rustfs/admin/v3/site-replication/resync/op";
|
||||
const SITE_REPLICATION_REPAIR_ROUTE: &str = "/rustfs/admin/v3/site-replication/repair";
|
||||
const SITE_REPLICATION_REPAIR_STATUS_ROUTE: &str = "/rustfs/admin/v3/site-replication/repair/status";
|
||||
const IAM_POLICY_ATTACH_ROUTE: &str = "/rustfs/admin/v3/idp/builtin/policy/attach";
|
||||
const IAM_POLICY_DETACH_ROUTE: &str = "/rustfs/admin/v3/idp/builtin/policy/detach";
|
||||
const IAM_POLICY_ENTITIES_ROUTE: &str = "/rustfs/admin/v3/idp/builtin/policy-entities";
|
||||
const IAM_ACCESS_KEYS_BULK_ROUTE: &str = "/rustfs/admin/v3/list-access-keys-bulk";
|
||||
const IAM_ACCESS_KEYS_BULK_LDAP_ROUTE: &str = "/rustfs/admin/v3/idp/ldap/list-access-keys-bulk";
|
||||
const IAM_ACCESS_KEYS_BULK_OPENID_ROUTE: &str = "/rustfs/admin/v3/idp/openid/list-access-keys-bulk";
|
||||
|
||||
macro_rules! log_system_request_rejected {
|
||||
($operation:expr, $reason:expr) => {
|
||||
@@ -667,24 +661,9 @@ pub struct RuntimeCapabilitiesSummary {
|
||||
pub manual_transition_jobs: CapabilityStatus,
|
||||
}
|
||||
|
||||
/// One named admin capability advertised to management clients
|
||||
/// (rustfs/backlog#1900). `name` is a cross-repo wire contract: the rc
|
||||
/// client gates commands on these exact strings (see rustfs/cli
|
||||
/// `IAM_POLICY_DETACH_CAPABILITY` etc.), so entries may be added but
|
||||
/// existing names must never be renamed or removed.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
pub struct AdvertisedAdminCapability {
|
||||
pub name: &'static str,
|
||||
pub status: CapabilityStatus,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
pub struct RuntimeCapabilitiesResponse {
|
||||
pub summary: RuntimeCapabilitiesSummary,
|
||||
/// Additive field: absent in responses from older servers, so clients
|
||||
/// must treat a missing list as "no dynamic advertisement" and fall
|
||||
/// back to their pinned per-version contract.
|
||||
pub advertised: Vec<AdvertisedAdminCapability>,
|
||||
pub replication: ReplicationCapabilities,
|
||||
pub manual_transition_jobs: ManualTransitionJobCapabilities,
|
||||
pub diagnostic_probes: DiagnosticProbeCapabilities,
|
||||
@@ -1007,7 +986,6 @@ pub(crate) async fn build_runtime_capabilities_response()
|
||||
|
||||
Ok(RuntimeCapabilitiesResponse {
|
||||
summary,
|
||||
advertised: advertised_admin_capabilities(),
|
||||
replication: ReplicationCapabilities::current(),
|
||||
manual_transition_jobs: ManualTransitionJobCapabilities::current(),
|
||||
diagnostic_probes: DiagnosticProbeCapabilities::current(),
|
||||
@@ -1099,23 +1077,6 @@ fn admin_route_capability(method: HttpMethod, path: &str) -> CapabilityStatus {
|
||||
admin_route_capability_from_inventory(method, path, ADMIN_ROUTE_POLICY_SPECS, DEFERRED_ADMIN_ROUTE_POLICIES)
|
||||
}
|
||||
|
||||
fn advertised_admin_capabilities() -> Vec<AdvertisedAdminCapability> {
|
||||
[
|
||||
("admin.iam.policy-attach", HttpMethod::Post, IAM_POLICY_ATTACH_ROUTE),
|
||||
("admin.iam.policy-detach", HttpMethod::Post, IAM_POLICY_DETACH_ROUTE),
|
||||
("admin.iam.policy-entities", HttpMethod::Get, IAM_POLICY_ENTITIES_ROUTE),
|
||||
("admin.iam.access-keys-bulk", HttpMethod::Get, IAM_ACCESS_KEYS_BULK_ROUTE),
|
||||
("admin.iam.access-keys-bulk.ldap", HttpMethod::Get, IAM_ACCESS_KEYS_BULK_LDAP_ROUTE),
|
||||
("admin.iam.access-keys-bulk.openid", HttpMethod::Get, IAM_ACCESS_KEYS_BULK_OPENID_ROUTE),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, method, route)| AdvertisedAdminCapability {
|
||||
name,
|
||||
status: admin_route_capability(method, route),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn admin_route_capability_from_inventory(
|
||||
method: HttpMethod,
|
||||
path: &str,
|
||||
@@ -1278,48 +1239,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Wire-contract pin (rustfs/backlog#1900): the rc client keys its
|
||||
/// command gates on these exact capability names, and parses each
|
||||
/// entry as `{name, status: {state, reason?}}`. Renaming or dropping
|
||||
/// a name silently disables the corresponding rc command.
|
||||
#[tokio::test]
|
||||
async fn runtime_capabilities_response_advertises_iam_capabilities() {
|
||||
let response = build_runtime_capabilities_response()
|
||||
.await
|
||||
.expect("runtime capabilities response should build");
|
||||
|
||||
let expected_supported = [
|
||||
"admin.iam.policy-attach",
|
||||
"admin.iam.policy-detach",
|
||||
"admin.iam.policy-entities",
|
||||
"admin.iam.access-keys-bulk",
|
||||
"admin.iam.access-keys-bulk.ldap",
|
||||
"admin.iam.access-keys-bulk.openid",
|
||||
];
|
||||
for name in expected_supported {
|
||||
let entry = response
|
||||
.advertised
|
||||
.iter()
|
||||
.find(|capability| capability.name == name)
|
||||
.unwrap_or_else(|| panic!("{name} must be advertised"));
|
||||
assert_eq!(entry.status.state, CapabilityState::Supported, "{name} must be supported");
|
||||
}
|
||||
|
||||
let mut names: Vec<&str> = response.advertised.iter().map(|capability| capability.name).collect();
|
||||
let total = names.len();
|
||||
names.sort_unstable();
|
||||
names.dedup();
|
||||
assert_eq!(names.len(), total, "advertised capability names must be unique");
|
||||
|
||||
let serialized = serde_json::to_value(&response).expect("response should serialize");
|
||||
let advertised = serialized["advertised"].as_array().expect("advertised must be an array");
|
||||
let detach = advertised
|
||||
.iter()
|
||||
.find(|entry| entry["name"] == "admin.iam.policy-detach")
|
||||
.expect("serialized detach entry must exist");
|
||||
assert_eq!(detach["status"]["state"], "supported");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn runtime_capabilities_response_reports_missing_topology_before_storage_init() {
|
||||
let response = build_runtime_capabilities_response()
|
||||
|
||||
Reference in New Issue
Block a user