mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-06 05:17:42 +00:00
375482a4b6
* refactor(issue-633): clarify layered io control policies * refactor(issue-633): consolidate timeout and deadlock layers * refactor(issue-633): align storage backpressure metadata * refactor(issue-633): unify storage backpressure transitions * refactor(issue-633): simplify watermark transition API * test(issue-633): add storage backpressure transition test * refactor(issue-633): align storage pipe meta shape * refactor(issue-633): enrich storage monitor metadata * refactor(issue-633): finalize storage backpressure convergence * refactor(issue-633): complete scheduler layer convergence * refactor(issue-633): reduce concurrency facade config duplication * refactor(issue-633): migrate storage callsites to final policy names * chore(issue-633): apply final pre-commit normalization * refactor(issue-633): unify timeout wrapper dynamic size path * refactor(issue-633): make concurrency policies copyable * refactor(issue-633): converge storage io hot paths * fix(issue-633): honor storage timeout min bound * fix(storage): avoid timeout calc panic on huge sizes * refactor(storage): consolidate timeout checks and test attrs * fix(storage): harden io scheduler core config mapping * refactor(storage): eliminate patch-on-patch patterns and dead code - Remove trivial accessor methods on ConcurrencyConfig that just return pub fields - Remove dead BackpressureEvent/BackpressureEventType types from concurrency crate - Fix io_schedule test using wrong constructor (from_core_config -> from_scheduler_config) - Update manager.rs to use config fields directly instead of removed accessors * fix: adopt review feedback for config guards * test: remove needless struct update defaults * fix: harden timeout policy and preserve api alias
174 lines
4.9 KiB
Rust
174 lines
4.9 KiB
Rust
// Copyright 2024 RustFS Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//! # RustFS Concurrency Management
|
|
//!
|
|
//! This crate provides comprehensive concurrency management for RustFS,
|
|
//! including timeout control, lock optimization, deadlock detection,
|
|
//! backpressure management, and I/O scheduling.
|
|
//!
|
|
//! ## Features
|
|
//!
|
|
//! All features are controlled by feature flags and can be enabled/disabled at compile time:
|
|
//!
|
|
//! - **timeout**: Dynamic timeout calculation based on data size and transfer rate
|
|
//! - **lock**: Early lock release to reduce contention
|
|
//! - **deadlock**: Request tracking and cycle detection
|
|
//! - **backpressure**: Buffer-based flow control
|
|
//! - **scheduler**: Adaptive buffer sizing and priority queuing
|
|
//!
|
|
//! ## Architecture
|
|
//!
|
|
//! ```text
|
|
//! rustfs-concurrency (Business Layer)
|
|
//! ├── timeout (Timeout Control)
|
|
//! ├── lock (Lock Optimization)
|
|
//! ├── deadlock (Deadlock Detection)
|
|
//! ├── backpressure (Backpressure Management)
|
|
//! └── scheduler (I/O Scheduling)
|
|
//! │
|
|
//! ├── rustfs-io-core (Core Algorithms)
|
|
//! └── rustfs-io-metrics (Metrics Collection)
|
|
//! ```
|
|
//!
|
|
//! ## Usage
|
|
//!
|
|
//! ```rust,no_run
|
|
//! use rustfs_concurrency::{ConcurrencyConfig, ConcurrencyManager};
|
|
//!
|
|
//! # #[tokio::main]
|
|
//! # async fn main() {
|
|
//! // Create manager with all features enabled
|
|
//! let config = ConcurrencyConfig::default();
|
|
//! let manager = ConcurrencyManager::new(config);
|
|
//!
|
|
//! // Start services
|
|
//! manager.start().await;
|
|
//!
|
|
//! // Use timeout control (if enabled)
|
|
//! if manager.is_timeout_enabled() {
|
|
//! let timeout_manager = manager.timeout();
|
|
//! let _ = timeout_manager;
|
|
//! }
|
|
//!
|
|
//! // Use lock optimization (if enabled)
|
|
//! if manager.is_lock_enabled() {
|
|
//! let lock_manager = manager.lock();
|
|
//! let _ = lock_manager;
|
|
//! }
|
|
//!
|
|
//! // Stop services
|
|
//! manager.stop().await;
|
|
//! # }
|
|
//! ```
|
|
|
|
#![deny(missing_docs)]
|
|
#![deny(unsafe_code)]
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
|
|
|
// Re-export core types from io-core
|
|
pub use rustfs_io_core::{
|
|
// Backpressure types
|
|
BackpressureConfig as CoreBackpressureConfig,
|
|
BackpressureMonitor as CoreBackpressureMonitor,
|
|
BackpressureState,
|
|
|
|
// Deadlock types
|
|
DeadlockDetector as CoreDeadlockDetector,
|
|
IoLoadLevel,
|
|
IoLoadMetrics,
|
|
IoPriority,
|
|
// Scheduler types
|
|
IoScheduler,
|
|
IoSchedulingContext,
|
|
LockInfo,
|
|
LockOptimizer as CoreLockOptimizer,
|
|
|
|
// Lock types
|
|
LockStats as CoreLockStats,
|
|
LockType,
|
|
// Timeout types
|
|
OperationProgress,
|
|
TimeoutError,
|
|
TimeoutStats,
|
|
WaitGraphEdge,
|
|
|
|
calculate_adaptive_timeout,
|
|
estimate_bytes_per_second,
|
|
};
|
|
|
|
// Module declarations with feature gates
|
|
#[cfg(feature = "timeout")]
|
|
mod timeout;
|
|
|
|
#[cfg(feature = "lock")]
|
|
mod lock;
|
|
|
|
#[cfg(feature = "deadlock")]
|
|
mod deadlock;
|
|
|
|
#[cfg(feature = "backpressure")]
|
|
mod backpressure;
|
|
|
|
#[cfg(feature = "scheduler")]
|
|
mod scheduler;
|
|
|
|
pub mod workers;
|
|
|
|
// Public module exports with feature gates
|
|
#[cfg(feature = "timeout")]
|
|
pub use timeout::{TimeoutGuard, TimeoutManager, TimeoutManagerPolicy};
|
|
|
|
#[cfg(feature = "lock")]
|
|
pub use lock::{LockConfig, LockManager, LockScopeGuard, OptimizedLockGuard};
|
|
|
|
#[cfg(feature = "deadlock")]
|
|
pub use deadlock::{DeadlockManager, DeadlockMonitorPolicy, RequestTracker};
|
|
|
|
#[cfg(feature = "backpressure")]
|
|
pub use backpressure::{BackpressureManager, BackpressurePipe, PipeBackpressurePolicy};
|
|
|
|
#[cfg(feature = "scheduler")]
|
|
pub use scheduler::{IoStrategy, SchedulerManager, SchedulerPolicy};
|
|
|
|
// Configuration
|
|
mod config;
|
|
pub use config::{ConcurrencyConfig, ConcurrencyFeatures};
|
|
|
|
// Manager
|
|
mod manager;
|
|
pub use manager::{ConcurrencyManager, GetObjectQueueSnapshot};
|
|
|
|
// Prelude for convenient imports
|
|
pub mod prelude {
|
|
//! Prelude module for convenient imports
|
|
|
|
#[cfg(feature = "timeout")]
|
|
pub use crate::timeout::{TimeoutGuard, TimeoutManager, TimeoutManagerPolicy};
|
|
|
|
#[cfg(feature = "lock")]
|
|
pub use crate::lock::{LockConfig, LockManager, LockScopeGuard, OptimizedLockGuard};
|
|
|
|
#[cfg(feature = "deadlock")]
|
|
pub use crate::deadlock::{DeadlockManager, DeadlockMonitorPolicy, RequestTracker};
|
|
|
|
#[cfg(feature = "backpressure")]
|
|
pub use crate::backpressure::{BackpressureManager, BackpressurePipe, PipeBackpressurePolicy};
|
|
|
|
#[cfg(feature = "scheduler")]
|
|
pub use crate::scheduler::{IoStrategy, SchedulerManager, SchedulerPolicy};
|
|
|
|
pub use crate::{ConcurrencyConfig, ConcurrencyFeatures, ConcurrencyManager};
|
|
}
|