mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-10 07:06:53 +00:00
refactor: bridge storage concurrency policies (#3683)
This commit is contained in:
@@ -42,6 +42,8 @@ use tokio::io::{DuplexStream, duplex};
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use metrics::counter;
|
||||
use rustfs_concurrency::PipeBackpressurePolicy;
|
||||
use rustfs_io_core::BackpressureConfig as CoreBackpressureConfig;
|
||||
|
||||
/// Object-transfer duplex pipe backpressure policy.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -98,6 +100,20 @@ impl ObjectPipeBackpressurePolicy {
|
||||
pub fn low_watermark_bytes(&self) -> usize {
|
||||
(self.buffer_size as u64 * self.low_watermark as u64 / 100) as usize
|
||||
}
|
||||
|
||||
/// Project this object-transfer policy into the shared concurrency facade policy.
|
||||
pub fn to_concurrency_policy(&self) -> PipeBackpressurePolicy {
|
||||
PipeBackpressurePolicy {
|
||||
buffer_size: self.buffer_size,
|
||||
high_watermark: self.high_watermark,
|
||||
low_watermark: self.low_watermark,
|
||||
}
|
||||
}
|
||||
|
||||
/// Project this object-transfer policy into the reusable io-core admission config.
|
||||
pub fn to_core_config(&self) -> CoreBackpressureConfig {
|
||||
self.to_concurrency_policy().to_core_config()
|
||||
}
|
||||
}
|
||||
|
||||
/// Backpressure state.
|
||||
@@ -487,6 +503,24 @@ mod tests {
|
||||
assert_eq!(config.low_watermark_bytes(), 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backpressure_policy_projects_to_concurrency_and_core_config() {
|
||||
let config = ObjectPipeBackpressurePolicy {
|
||||
buffer_size: 2000,
|
||||
high_watermark: 75,
|
||||
low_watermark: 40,
|
||||
};
|
||||
let concurrency = config.to_concurrency_policy();
|
||||
let core = config.to_core_config();
|
||||
|
||||
assert_eq!(concurrency.buffer_size, config.buffer_size);
|
||||
assert_eq!(concurrency.high_watermark, config.high_watermark);
|
||||
assert_eq!(concurrency.low_watermark, config.low_watermark);
|
||||
assert_eq!(core.high_water_mark, 0.75);
|
||||
assert_eq!(core.low_water_mark, 0.40);
|
||||
assert!(core.enabled);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backpressure_state_display() {
|
||||
assert_eq!(format!("{}", BackpressureState::Normal), "normal");
|
||||
|
||||
@@ -66,6 +66,7 @@ use tokio::sync::broadcast;
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
use metrics::counter;
|
||||
use rustfs_concurrency::DeadlockMonitorPolicy;
|
||||
use rustfs_io_core::DeadlockDetectorConfig as CoreDeadlockConfig;
|
||||
|
||||
/// Request identifier type.
|
||||
@@ -124,10 +125,15 @@ impl RequestHangDetectionPolicy {
|
||||
|
||||
/// Convert the request-level policy into the shared io-core deadlock config.
|
||||
pub fn to_core_config(&self) -> CoreDeadlockConfig {
|
||||
CoreDeadlockConfig {
|
||||
self.to_concurrency_policy().to_core_config()
|
||||
}
|
||||
|
||||
/// Convert the request-level policy into the shared concurrency facade policy.
|
||||
pub fn to_concurrency_policy(&self) -> DeadlockMonitorPolicy {
|
||||
DeadlockMonitorPolicy {
|
||||
enabled: self.enabled,
|
||||
detection_interval: self.check_interval,
|
||||
max_hold_time: self.hang_threshold,
|
||||
check_interval: self.check_interval,
|
||||
hang_threshold: self.hang_threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -612,6 +618,26 @@ mod tests {
|
||||
assert_eq!(config.hang_threshold, Duration::from_secs(10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_request_hang_policy_projects_to_concurrency_and_core_config() {
|
||||
let config = RequestHangDetectionPolicy {
|
||||
enabled: true,
|
||||
check_interval: Duration::from_secs(7),
|
||||
hang_threshold: Duration::from_secs(11),
|
||||
capture_backtrace: true,
|
||||
};
|
||||
let concurrency = config.to_concurrency_policy();
|
||||
let core = config.to_core_config();
|
||||
|
||||
assert!(concurrency.enabled);
|
||||
assert_eq!(concurrency.check_interval, config.check_interval);
|
||||
assert_eq!(concurrency.hang_threshold, config.hang_threshold);
|
||||
assert!(core.enabled);
|
||||
assert_eq!(core.detection_interval, config.check_interval);
|
||||
assert_eq!(core.max_hold_time, config.hang_threshold);
|
||||
assert!(config.capture_backtrace);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_request_resource_tracker() {
|
||||
let tracker = RequestResourceTracker::new("req-1".to_string(), "GetObject bucket/key");
|
||||
|
||||
Reference in New Issue
Block a user