mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-23 20:59:05 +00:00
fix(ecstore): resolve CI clippy failures
This commit is contained in:
@@ -1420,6 +1420,7 @@ pub(crate) async fn migrate_decommission_object(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
pub(crate) async fn migrate_object(
|
pub(crate) async fn migrate_object(
|
||||||
store: Arc<ECStore>,
|
store: Arc<ECStore>,
|
||||||
pool_idx: usize,
|
pool_idx: usize,
|
||||||
|
|||||||
@@ -50,6 +50,22 @@ fn ensure_rebalance_entry_active(cancel: &CancellationToken) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct RebalanceEntryTarget {
|
||||||
|
bucket: String,
|
||||||
|
pool_index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct RebalanceEntryCleanupContext<'a> {
|
||||||
|
run_guard: &'a super::control::RebalanceRunGuard,
|
||||||
|
pool_index: usize,
|
||||||
|
bucket: &'a str,
|
||||||
|
object: &'a str,
|
||||||
|
stats_updates: &'a [&'a FileInfo],
|
||||||
|
expected_id: &'a str,
|
||||||
|
cancel: &'a CancellationToken,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
static REBALANCE_RUN_SIGNAL_TEST_FENCES: std::sync::OnceLock<
|
static REBALANCE_RUN_SIGNAL_TEST_FENCES: std::sync::OnceLock<
|
||||||
std::sync::Mutex<std::collections::HashMap<String, Arc<std::sync::atomic::AtomicBool>>>,
|
std::sync::Mutex<std::collections::HashMap<String, Arc<std::sync::atomic::AtomicBool>>>,
|
||||||
@@ -113,39 +129,39 @@ fn attach_rebalance_run_signal_test_fence(
|
|||||||
impl ECStore {
|
impl ECStore {
|
||||||
async fn finish_rebalance_entry_after_cleanup(
|
async fn finish_rebalance_entry_after_cleanup(
|
||||||
&self,
|
&self,
|
||||||
run_guard: &super::control::RebalanceRunGuard,
|
context: &RebalanceEntryCleanupContext<'_>,
|
||||||
pool_index: usize,
|
|
||||||
bucket: &str,
|
|
||||||
object: &str,
|
|
||||||
stats_updates: &[&FileInfo],
|
|
||||||
expected_id: &str,
|
|
||||||
cancel: &CancellationToken,
|
|
||||||
cleanup: impl std::future::Future<Output = std::result::Result<ObjectInfo, data_movement::SourceCleanupError>>,
|
cleanup: impl std::future::Future<Output = std::result::Result<ObjectInfo, data_movement::SourceCleanupError>>,
|
||||||
) -> Result<RebalanceEntryCleanupResult> {
|
) -> Result<RebalanceEntryCleanupResult> {
|
||||||
// Persisted stats can complete a pool on restart, so source cleanup must resolve first.
|
// Persisted stats can complete a pool on restart, so source cleanup must resolve first.
|
||||||
ensure_rebalance_entry_active(cancel)?;
|
ensure_rebalance_entry_active(context.cancel)?;
|
||||||
run_guard.ensure_held("rebalance source cleanup")?;
|
context.run_guard.ensure_held("rebalance source cleanup")?;
|
||||||
let cleanup_result = cleanup.await;
|
let cleanup_result = cleanup.await;
|
||||||
ensure_rebalance_entry_active(cancel)?;
|
ensure_rebalance_entry_active(context.cancel)?;
|
||||||
run_guard.ensure_held("rebalance source cleanup")?;
|
context.run_guard.ensure_held("rebalance source cleanup")?;
|
||||||
let cleanup_result = resolve_rebalance_entry_cleanup_delete_result(cleanup_result, bucket, object);
|
let cleanup_result = resolve_rebalance_entry_cleanup_delete_result(cleanup_result, context.bucket, context.object);
|
||||||
let RebalanceEntryCleanupResult::Completed { warning } = cleanup_result else {
|
let RebalanceEntryCleanupResult::Completed { warning } = cleanup_result else {
|
||||||
return Ok(cleanup_result);
|
return Ok(cleanup_result);
|
||||||
};
|
};
|
||||||
if let Some(message) = warning.as_ref() {
|
if let Some(message) = warning.as_ref() {
|
||||||
run_guard.ensure_held("record rebalance cleanup warning")?;
|
context.run_guard.ensure_held("record rebalance cleanup warning")?;
|
||||||
let warning_result = self
|
let warning_result = self
|
||||||
.record_rebalance_cleanup_warning(pool_index, bucket, object, message.clone(), expected_id)
|
.record_rebalance_cleanup_warning(
|
||||||
|
context.pool_index,
|
||||||
|
context.bucket,
|
||||||
|
context.object,
|
||||||
|
message.clone(),
|
||||||
|
context.expected_id,
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
run_guard.ensure_held("record rebalance cleanup warning")?;
|
context.run_guard.ensure_held("record rebalance cleanup warning")?;
|
||||||
if let Err(err) = warning_result {
|
if let Err(err) = warning_result {
|
||||||
error!(
|
error!(
|
||||||
event = EVENT_REBALANCE_ENTRY,
|
event = EVENT_REBALANCE_ENTRY,
|
||||||
component = LOG_COMPONENT_ECSTORE,
|
component = LOG_COMPONENT_ECSTORE,
|
||||||
subsystem = LOG_SUBSYSTEM_REBALANCE,
|
subsystem = LOG_SUBSYSTEM_REBALANCE,
|
||||||
pool_index,
|
pool_index = context.pool_index,
|
||||||
bucket,
|
bucket = context.bucket,
|
||||||
object,
|
object = context.object,
|
||||||
stage = "cleanup_source",
|
stage = "cleanup_source",
|
||||||
error = ?err,
|
error = ?err,
|
||||||
"Failed to record rebalance source cleanup warning"
|
"Failed to record rebalance source cleanup warning"
|
||||||
@@ -153,22 +169,26 @@ impl ECStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run_guard.ensure_held("record rebalance entry stats")?;
|
context.run_guard.ensure_held("record rebalance entry stats")?;
|
||||||
let stats_result = self
|
let stats_result = self
|
||||||
.update_pool_stats_batch_for_rebalance(pool_index, bucket.to_string(), stats_updates, expected_id)
|
.update_pool_stats_batch_for_rebalance(
|
||||||
|
context.pool_index,
|
||||||
|
context.bucket.to_string(),
|
||||||
|
context.stats_updates,
|
||||||
|
context.expected_id,
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
run_guard.ensure_held("record rebalance entry stats")?;
|
context.run_guard.ensure_held("record rebalance entry stats")?;
|
||||||
resolve_rebalance_stats_update_result(stats_result, pool_index, bucket, object)?;
|
resolve_rebalance_stats_update_result(stats_result, context.pool_index, context.bucket, context.object)?;
|
||||||
|
|
||||||
Ok(RebalanceEntryCleanupResult::Completed { warning })
|
Ok(RebalanceEntryCleanupResult::Completed { warning })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
#[tracing::instrument(skip(self, set))]
|
#[tracing::instrument(skip(self, set, target), fields(bucket = %target.bucket, pool_index = target.pool_index))]
|
||||||
async fn rebalance_entry(
|
async fn rebalance_entry(
|
||||||
self: Arc<Self>,
|
self: Arc<Self>,
|
||||||
bucket: String,
|
target: RebalanceEntryTarget,
|
||||||
pool_index: usize,
|
|
||||||
entry: MetaCacheEntry,
|
entry: MetaCacheEntry,
|
||||||
set: Arc<SetDisks>,
|
set: Arc<SetDisks>,
|
||||||
bucket_configs: Arc<RebalanceBucketConfigs>,
|
bucket_configs: Arc<RebalanceBucketConfigs>,
|
||||||
@@ -176,6 +196,7 @@ impl ECStore {
|
|||||||
cancel: CancellationToken,
|
cancel: CancellationToken,
|
||||||
// wk: Arc<Workers>,
|
// wk: Arc<Workers>,
|
||||||
) -> Result<RebalanceEntryOutcome> {
|
) -> Result<RebalanceEntryOutcome> {
|
||||||
|
let RebalanceEntryTarget { bucket, pool_index } = target;
|
||||||
debug!(
|
debug!(
|
||||||
event = EVENT_REBALANCE_ENTRY,
|
event = EVENT_REBALANCE_ENTRY,
|
||||||
component = LOG_COMPONENT_ECSTORE,
|
component = LOG_COMPONENT_ECSTORE,
|
||||||
@@ -445,13 +466,15 @@ impl ECStore {
|
|||||||
}
|
}
|
||||||
let cleanup_result = self
|
let cleanup_result = self
|
||||||
.finish_rebalance_entry_after_cleanup(
|
.finish_rebalance_entry_after_cleanup(
|
||||||
&run_guard,
|
&RebalanceEntryCleanupContext {
|
||||||
pool_index,
|
run_guard: &run_guard,
|
||||||
bucket.as_str(),
|
pool_index,
|
||||||
entry.name.as_str(),
|
bucket: bucket.as_str(),
|
||||||
stats_updates.as_slice(),
|
object: entry.name.as_str(),
|
||||||
rebalance_id.as_ref(),
|
stats_updates: stats_updates.as_slice(),
|
||||||
&cancel,
|
expected_id: rebalance_id.as_ref(),
|
||||||
|
cancel: &cancel,
|
||||||
|
},
|
||||||
data_movement::cleanup_source_entry_if_unchanged(
|
data_movement::cleanup_source_entry_if_unchanged(
|
||||||
set.clone(),
|
set.clone(),
|
||||||
bucket.as_str(),
|
bucket.as_str(),
|
||||||
@@ -687,8 +710,7 @@ impl ECStore {
|
|||||||
);
|
);
|
||||||
let result = this
|
let result = this
|
||||||
.rebalance_entry(
|
.rebalance_entry(
|
||||||
bucket,
|
RebalanceEntryTarget { bucket, pool_index },
|
||||||
pool_index,
|
|
||||||
entry,
|
entry,
|
||||||
set,
|
set,
|
||||||
bucket_configs,
|
bucket_configs,
|
||||||
@@ -875,8 +897,10 @@ pub mod test_util {
|
|||||||
let entry_task = tokio::spawn(async move {
|
let entry_task = tokio::spawn(async move {
|
||||||
entry_store
|
entry_store
|
||||||
.rebalance_entry(
|
.rebalance_entry(
|
||||||
bucket.to_string(),
|
RebalanceEntryTarget {
|
||||||
0,
|
bucket: bucket.to_string(),
|
||||||
|
pool_index: 0,
|
||||||
|
},
|
||||||
entry,
|
entry,
|
||||||
entry_set,
|
entry_set,
|
||||||
Arc::new(RebalanceBucketConfigs::default()),
|
Arc::new(RebalanceBucketConfigs::default()),
|
||||||
@@ -1050,8 +1074,10 @@ mod tests {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
store
|
store
|
||||||
.rebalance_entry(
|
.rebalance_entry(
|
||||||
crate::disk::RUSTFS_META_BUCKET.to_string(),
|
RebalanceEntryTarget {
|
||||||
0,
|
bucket: crate::disk::RUSTFS_META_BUCKET.to_string(),
|
||||||
|
pool_index: 0,
|
||||||
|
},
|
||||||
entry,
|
entry,
|
||||||
set,
|
set,
|
||||||
bucket_configs,
|
bucket_configs,
|
||||||
@@ -1102,20 +1128,21 @@ mod tests {
|
|||||||
.rebalance_run_guard(rebalance_id, "rebalance source cleanup test")
|
.rebalance_run_guard(rebalance_id, "rebalance source cleanup test")
|
||||||
.await
|
.await
|
||||||
.expect("rebalance source cleanup test guard should be acquired");
|
.expect("rebalance source cleanup test guard should be acquired");
|
||||||
|
let stats_updates = [&version];
|
||||||
|
let cleanup_context = RebalanceEntryCleanupContext {
|
||||||
|
run_guard: &run_guard,
|
||||||
|
pool_index: 0,
|
||||||
|
bucket: "bucket",
|
||||||
|
object: "object.bin",
|
||||||
|
stats_updates: &stats_updates,
|
||||||
|
expected_id: rebalance_id,
|
||||||
|
cancel: &cancel,
|
||||||
|
};
|
||||||
finish_store
|
finish_store
|
||||||
.finish_rebalance_entry_after_cleanup(
|
.finish_rebalance_entry_after_cleanup(&cleanup_context, async move {
|
||||||
&run_guard,
|
cleanup_released.await.expect("cleanup release sender should remain alive");
|
||||||
0,
|
Ok(ObjectInfo::default())
|
||||||
"bucket",
|
})
|
||||||
"object.bin",
|
|
||||||
&[&version],
|
|
||||||
rebalance_id,
|
|
||||||
&cancel,
|
|
||||||
async move {
|
|
||||||
cleanup_released.await.expect("cleanup release sender should remain alive");
|
|
||||||
Ok(ObjectInfo::default())
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1162,17 +1189,19 @@ mod tests {
|
|||||||
.rebalance_run_guard(rebalance_id, "rebalance cleanup warning test")
|
.rebalance_run_guard(rebalance_id, "rebalance cleanup warning test")
|
||||||
.await
|
.await
|
||||||
.expect("rebalance cleanup warning test guard should be acquired");
|
.expect("rebalance cleanup warning test guard should be acquired");
|
||||||
|
let warning_cancel = CancellationToken::new();
|
||||||
|
let warning_stats_updates = [&warning_version];
|
||||||
|
let warning_cleanup_context = RebalanceEntryCleanupContext {
|
||||||
|
run_guard: &warning_guard,
|
||||||
|
pool_index: 0,
|
||||||
|
bucket: "bucket",
|
||||||
|
object: "object.bin",
|
||||||
|
stats_updates: &warning_stats_updates,
|
||||||
|
expected_id: rebalance_id,
|
||||||
|
cancel: &warning_cancel,
|
||||||
|
};
|
||||||
let warning_result = store
|
let warning_result = store
|
||||||
.finish_rebalance_entry_after_cleanup(
|
.finish_rebalance_entry_after_cleanup(&warning_cleanup_context, async { Err(Error::SlowDown.into()) })
|
||||||
&warning_guard,
|
|
||||||
0,
|
|
||||||
"bucket",
|
|
||||||
"object.bin",
|
|
||||||
&[&warning_version],
|
|
||||||
rebalance_id,
|
|
||||||
&CancellationToken::new(),
|
|
||||||
async { Err(Error::SlowDown.into()) },
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.expect("cleanup warnings should not fail the completed migration");
|
.expect("cleanup warnings should not fail the completed migration");
|
||||||
assert!(matches!(warning_result, RebalanceEntryCleanupResult::Completed { warning: Some(_) }));
|
assert!(matches!(warning_result, RebalanceEntryCleanupResult::Completed { warning: Some(_) }));
|
||||||
@@ -1191,17 +1220,21 @@ mod tests {
|
|||||||
.rebalance_run_guard(rebalance_id, "rebalance cleanup deferral test")
|
.rebalance_run_guard(rebalance_id, "rebalance cleanup deferral test")
|
||||||
.await
|
.await
|
||||||
.expect("rebalance cleanup deferral test guard should be acquired");
|
.expect("rebalance cleanup deferral test guard should be acquired");
|
||||||
|
let deferred_cancel = CancellationToken::new();
|
||||||
|
let deferred_stats_updates = [&warning_version];
|
||||||
|
let deferred_cleanup_context = RebalanceEntryCleanupContext {
|
||||||
|
run_guard: &deferred_guard,
|
||||||
|
pool_index: 0,
|
||||||
|
bucket: "bucket",
|
||||||
|
object: "object.bin",
|
||||||
|
stats_updates: &deferred_stats_updates,
|
||||||
|
expected_id: rebalance_id,
|
||||||
|
cancel: &deferred_cancel,
|
||||||
|
};
|
||||||
let deferred = store
|
let deferred = store
|
||||||
.finish_rebalance_entry_after_cleanup(
|
.finish_rebalance_entry_after_cleanup(&deferred_cleanup_context, async {
|
||||||
&deferred_guard,
|
Err(data_movement::SourceCleanupError::SourceChanged)
|
||||||
0,
|
})
|
||||||
"bucket",
|
|
||||||
"object.bin",
|
|
||||||
&[&warning_version],
|
|
||||||
rebalance_id,
|
|
||||||
&CancellationToken::new(),
|
|
||||||
async { Err(data_movement::SourceCleanupError::SourceChanged) },
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.expect("source changes should defer cleanup without failing the worker");
|
.expect("source changes should defer cleanup without failing the worker");
|
||||||
assert!(matches!(deferred, RebalanceEntryCleanupResult::Deferred { .. }));
|
assert!(matches!(deferred, RebalanceEntryCleanupResult::Deferred { .. }));
|
||||||
@@ -1280,8 +1313,10 @@ mod tests {
|
|||||||
let mut entry_task = tokio::spawn(async move {
|
let mut entry_task = tokio::spawn(async move {
|
||||||
entry_store
|
entry_store
|
||||||
.rebalance_entry(
|
.rebalance_entry(
|
||||||
bucket.to_string(),
|
RebalanceEntryTarget {
|
||||||
0,
|
bucket: bucket.to_string(),
|
||||||
|
pool_index: 0,
|
||||||
|
},
|
||||||
entry,
|
entry,
|
||||||
entry_set,
|
entry_set,
|
||||||
Arc::new(RebalanceBucketConfigs::default()),
|
Arc::new(RebalanceBucketConfigs::default()),
|
||||||
|
|||||||
@@ -189,16 +189,16 @@ impl ECStore {
|
|||||||
cancel_tx.cancel();
|
cancel_tx.cancel();
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
if !must_persist {
|
if !must_persist
|
||||||
if let Err(err) = commit_local_rebalance_worker_activation_candidate(
|
&& let Err(err) = commit_local_rebalance_worker_activation_candidate(
|
||||||
meta,
|
meta,
|
||||||
expected_id.as_ref(),
|
expected_id.as_ref(),
|
||||||
expected_cancel.as_ref(),
|
expected_cancel.as_ref(),
|
||||||
candidate.clone(),
|
candidate.clone(),
|
||||||
) {
|
)
|
||||||
cancel_tx.cancel();
|
{
|
||||||
return Err(err);
|
cancel_tx.cancel();
|
||||||
}
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3194,7 +3194,7 @@ impl ECStore {
|
|||||||
|
|
||||||
// Default return value
|
// Default return value
|
||||||
let mut del_objects = vec![DeletedObject::default(); objects.len()];
|
let mut del_objects = vec![DeletedObject::default(); objects.len()];
|
||||||
let mut accounting = vec![None; objects.len()];
|
let accounting = vec![None; objects.len()];
|
||||||
|
|
||||||
let mut del_errs = Vec::with_capacity(objects.len());
|
let mut del_errs = Vec::with_capacity(objects.len());
|
||||||
for _ in 0..objects.len() {
|
for _ in 0..objects.len() {
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ pub(super) fn resolve_latest_object_info_candidates(
|
|||||||
.filter(|candidate| latest_candidate_mod_time(candidate) == Some(latest_mod_time))
|
.filter(|candidate| latest_candidate_mod_time(candidate) == Some(latest_mod_time))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
latest_candidates.sort_by(|left, right| right.idx.cmp(&left.idx));
|
latest_candidates.sort_by_key(|candidate| std::cmp::Reverse(candidate.idx));
|
||||||
|
|
||||||
let Some(winner) = latest_candidates.first() else {
|
let Some(winner) = latest_candidates.first() else {
|
||||||
return Err(Error::ErasureReadQuorum);
|
return Err(Error::ErasureReadQuorum);
|
||||||
|
|||||||
Reference in New Issue
Block a user