mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 11:56:38 +00:00
refactor(replication): move queue contracts into crate (#4167)
This commit is contained in:
@@ -42,8 +42,8 @@ pub(crate) use replication_lifecycle_bridge::{ReplicationLifecycleBridge, Replic
|
||||
pub(crate) use replication_migration_bridge::ReplicationMigrationBridge;
|
||||
pub use replication_object_bridge::ReplicationObjectBridge;
|
||||
pub use replication_pool::{
|
||||
DynReplicationPool, ReplicationHealQueueResult, ReplicationPoolTrait, ReplicationQueueAdmission, get_global_replication_pool,
|
||||
get_global_replication_stats, init_background_replication,
|
||||
DynReplicationPool, ReplicationPoolTrait, get_global_replication_pool, get_global_replication_stats,
|
||||
init_background_replication,
|
||||
};
|
||||
pub use replication_resyncer::ReplicationConfig;
|
||||
pub use replication_scanner_bridge::ReplicationScannerBridge;
|
||||
@@ -51,5 +51,6 @@ pub use replication_state::{BucketStats, ReplicationStats};
|
||||
pub use replication_storage_boundary::{ReplicationObjectIO, ReplicationStorage};
|
||||
pub(crate) use replication_target_config_bridge::ReplicationTargetConfigBridge;
|
||||
pub use rustfs_replication::{
|
||||
BucketReplicationResyncStatus, DeletedObjectReplicationInfo, MustReplicateOptions, ResyncOpts, TargetReplicationResyncStatus,
|
||||
BucketReplicationResyncStatus, DeletedObjectReplicationInfo, MustReplicateOptions, ReplicationHealQueueResult,
|
||||
ReplicationOperation, ReplicationPriority, ReplicationQueueAdmission, ResyncOpts, TargetReplicationResyncStatus,
|
||||
};
|
||||
|
||||
@@ -31,9 +31,11 @@ use super::replication_target_boundary::ReplicationTargetStore;
|
||||
use super::runtime_boundary as runtime_sources;
|
||||
use super::{BucketReplicationResyncStatus, ResyncOpts, TargetReplicationResyncStatus};
|
||||
use lazy_static::lazy_static;
|
||||
use rustfs_replication::DeletedObjectReplicationInfo;
|
||||
use rustfs_replication::{
|
||||
DeletedObjectReplicationInfo, ReplicationHealQueueResult, ReplicationOperation, ReplicationPriority,
|
||||
ReplicationQueueAdmission,
|
||||
};
|
||||
use rustfs_utils::http::{SUFFIX_REPLICATION_TIMESTAMP, get_str};
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicI32;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -73,116 +75,6 @@ pub const MRF_WORKER_AUTO_DEFAULT: usize = 4;
|
||||
pub const LARGE_WORKER_COUNT: usize = 10;
|
||||
pub const MIN_LARGE_OBJ_SIZE: i64 = 128 * 1024 * 1024; // 128MiB
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub enum ReplicationQueueAdmission {
|
||||
#[default]
|
||||
Skipped,
|
||||
Queued,
|
||||
Missed,
|
||||
}
|
||||
|
||||
impl ReplicationQueueAdmission {
|
||||
fn merge(&mut self, other: Self) {
|
||||
*self = match (*self, other) {
|
||||
(Self::Missed, _) | (_, Self::Missed) => Self::Missed,
|
||||
(Self::Queued, _) | (_, Self::Queued) => Self::Queued,
|
||||
(Self::Skipped, Self::Skipped) => Self::Skipped,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ReplicationHealQueueResult {
|
||||
pub object_info: ReplicateObjectInfo,
|
||||
pub admission: ReplicationQueueAdmission,
|
||||
}
|
||||
|
||||
/// Priority levels for replication
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum ReplicationPriority {
|
||||
Fast,
|
||||
Slow,
|
||||
Auto,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for ReplicationPriority {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"fast" => Ok(ReplicationPriority::Fast),
|
||||
"slow" => Ok(ReplicationPriority::Slow),
|
||||
"auto" => Ok(ReplicationPriority::Auto),
|
||||
_ => Ok(ReplicationPriority::Auto), // Default to Auto for unknown values
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ReplicationPriority {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
ReplicationPriority::Fast => "fast",
|
||||
ReplicationPriority::Slow => "slow",
|
||||
ReplicationPriority::Auto => "auto",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Enum for different types of replication operations
|
||||
#[derive(Debug)]
|
||||
pub enum ReplicationOperation {
|
||||
Object(Box<ReplicateObjectInfo>),
|
||||
Delete(Box<DeletedObjectReplicationInfo>),
|
||||
}
|
||||
|
||||
impl ReplicationWorkerOperation for ReplicationOperation {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn to_mrf_entry(&self) -> MrfReplicateEntry {
|
||||
match self {
|
||||
ReplicationOperation::Object(obj) => obj.to_mrf_entry(),
|
||||
ReplicationOperation::Delete(del) => del.to_mrf_entry(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bucket(&self) -> &str {
|
||||
match self {
|
||||
ReplicationOperation::Object(obj) => obj.get_bucket(),
|
||||
ReplicationOperation::Delete(del) => del.get_bucket(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_object(&self) -> &str {
|
||||
match self {
|
||||
ReplicationOperation::Object(obj) => obj.get_object(),
|
||||
ReplicationOperation::Delete(del) => del.get_object(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_size(&self) -> i64 {
|
||||
match self {
|
||||
ReplicationOperation::Object(obj) => obj.get_size(),
|
||||
ReplicationOperation::Delete(del) => del.get_size(),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_delete_marker(&self) -> bool {
|
||||
match self {
|
||||
ReplicationOperation::Object(obj) => obj.is_delete_marker(),
|
||||
ReplicationOperation::Delete(del) => del.is_delete_marker(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_op_type(&self) -> ReplicationType {
|
||||
match self {
|
||||
ReplicationOperation::Object(obj) => obj.get_op_type(),
|
||||
ReplicationOperation::Delete(del) => del.get_op_type(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Replication pool options
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ReplicationPoolOpts {
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use super::replication_pool::{ReplicationHealQueueResult, queue_replication_heal_internal};
|
||||
use super::ReplicationHealQueueResult;
|
||||
use super::replication_pool::queue_replication_heal_internal;
|
||||
use super::replication_resyncer::ReplicationConfig;
|
||||
use super::replication_storage_boundary::ObjectInfo;
|
||||
|
||||
@@ -31,7 +32,7 @@ impl ReplicationScannerBridge {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::replication_pool::ReplicationQueueAdmission;
|
||||
use super::super::ReplicationQueueAdmission;
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user