mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 08:38:58 +00:00
fix(capacity): ignore future write buckets (#2440)
This commit is contained in:
@@ -423,7 +423,9 @@ impl WriteRecord {
|
||||
fn recent_write_count(&self, now_second: u64) -> usize {
|
||||
self.write_buckets
|
||||
.iter()
|
||||
.filter(|bucket| bucket.count > 0 && now_second.saturating_sub(bucket.second) < WRITE_WINDOW_SECS)
|
||||
.filter(|bucket| {
|
||||
bucket.count > 0 && bucket.second <= now_second && now_second.saturating_sub(bucket.second) < WRITE_WINDOW_SECS
|
||||
})
|
||||
.map(|bucket| bucket.count)
|
||||
.sum()
|
||||
}
|
||||
@@ -1132,6 +1134,25 @@ mod tests {
|
||||
assert_eq!(manager.get_write_frequency().await, 20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn test_recent_write_count_ignores_future_buckets() {
|
||||
let mut record = WriteRecord {
|
||||
last_write_time: None,
|
||||
write_count: 1,
|
||||
write_buckets: [WriteBucket::default(); WRITE_WINDOW_BUCKETS],
|
||||
};
|
||||
|
||||
record.write_buckets[0] = WriteBucket { second: 120, count: 3 };
|
||||
record.write_buckets[1] = WriteBucket { second: 90, count: 2 };
|
||||
|
||||
assert_eq!(
|
||||
record.recent_write_count(100),
|
||||
2,
|
||||
"buckets from future seconds should not inflate recent write frequency"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_needs_fast_update() {
|
||||
|
||||
Reference in New Issue
Block a user