From fa77efcd8b12238c5c30f59fac5ce4a1a9566c7c Mon Sep 17 00:00:00 2001 From: baojun-zhang Date: Tue, 27 Oct 2026 14:02:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(multiwrite):=20=E5=A4=9A=E5=86=99=20IOPS?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=201.=20=E5=8E=BB=E9=99=A4=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=20checkpoint=20ticker=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=90=AF=E5=8A=A8=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=20IOPS=20=E5=B3=B0=E5=80=BC=202.=20=E5=A2=9E=E5=8A=A0=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E5=80=BC=E8=AE=BE=E7=BD=AE=E5=88=9D=E6=AC=A1=20checkp?= =?UTF-8?q?oint=20=E6=97=B6=E6=9C=BA=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=A4=9A?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=90=8C=E6=97=B6=E5=90=AF=E5=8A=A8=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=B9=B6=E5=8F=91=20IOPS=20=E5=B3=B0=E5=80=BC=203.=20?= =?UTF-8?q?flush=20worker=20=E4=BD=BF=E7=94=A8=E5=86=85=E5=AD=98=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E8=AE=B0=E5=BD=95account=20=E5=88=86=E5=8C=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E6=AF=8F?= =?UTF-8?q?=E4=B8=AA=20batch=20=E6=9F=A5=E8=AF=A2=20account=20=E5=88=86?= =?UTF-8?q?=E5=8C=BA=E4=BF=A1=E6=81=AF=204.=20=E5=A2=9E=E5=8A=A0=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=BF=9B=E5=BA=A6=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/ragfs/src/multibackend/checkpoint.rs | 35 +++++++++++++-- crates/ragfs/src/multibackend/gc.rs | 18 +++++++- crates/ragfs/src/multibackend/runtime.rs | 49 +++++++++++---------- 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/crates/ragfs/src/multibackend/checkpoint.rs b/crates/ragfs/src/multibackend/checkpoint.rs index 85f0987b38c..48f72db7745 100644 --- a/crates/ragfs/src/multibackend/checkpoint.rs +++ b/crates/ragfs/src/multibackend/checkpoint.rs @@ -6,8 +6,9 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use async_trait::async_trait; use chrono::{DateTime, Utc}; +use rand::Rng; use tokio::sync::watch; -use tracing::warn; +use tracing::{info, warn}; use crate::core::context::{FsContextInner, FS_CTX}; use crate::core::errors::{Error, Result}; @@ -52,8 +53,7 @@ impl CheckpointWorker { /// Run checkpoint rounds at the configured interval until cancellation. pub async fn run(&self, interval: Duration, mut cancellation: watch::Receiver) { - let mut ticker = tokio::time::interval(interval); - ticker.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); + let mut ticker = checkpoint_ticker(interval); loop { tokio::select! { _ = ticker.tick() => if let Err(error) = self.run_once(interval).await { @@ -82,6 +82,7 @@ impl CheckpointWorker { if self.store.protocol_status().await? != ProtocolStatus::Stable { return Ok(()); } + info!("multi-write checkpoint round started"); let now = now_ns()?; let interval_ns = u64::try_from(interval.as_nanos()).unwrap_or(u64::MAX); for account in self.store.initialized_accounts().await? { @@ -157,10 +158,30 @@ impl CheckpointWorker { } } } + info!("multi-write checkpoint round completed"); Ok(()) } } +/// Create the periodic timer for checkpoint discovery rounds. +fn checkpoint_ticker(interval: Duration) -> tokio::time::Interval { + let jitter_bound_secs = interval.as_secs().saturating_div(60).min(i64::MAX as u64) as i64; + let jitter_secs = if jitter_bound_secs == 0 { + 0 + } else { + rand::thread_rng().gen_range(-jitter_bound_secs..=jitter_bound_secs) + }; + let delay = if jitter_secs.is_negative() { + interval.saturating_sub(Duration::from_secs((-jitter_secs) as u64)) + } else { + interval.saturating_add(Duration::from_secs(jitter_secs as u64)) + }; + let start = tokio::time::Instant::now() + delay; + let mut ticker = tokio::time::interval_at(start, interval); + ticker.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); + ticker +} + /// Result of one bounded checkpoint build attempt. pub enum CheckpointBuildResult { /// No new sealed sequence exists for this scope. @@ -372,6 +393,14 @@ impl CheckpointBuilder { CheckpointsManifest::validate, ) .await?; + info!( + account = %scope.account_id, + partition = scope.partition_id, + epoch = scope.epoch, + checkpoint_to_seq = latest.checkpoint_to_seq, + checkpoint_path = %latest.path, + "multi-write checkpoint published" + ); Ok(CheckpointBuildResult::Published(latest)) } .await; diff --git a/crates/ragfs/src/multibackend/gc.rs b/crates/ragfs/src/multibackend/gc.rs index 64507ca22ab..d42b27e54ee 100644 --- a/crates/ragfs/src/multibackend/gc.rs +++ b/crates/ragfs/src/multibackend/gc.rs @@ -9,6 +9,7 @@ use crate::multibackend::constants::SEGMENT_FILE_EXTENSION; use crate::multibackend::meta::{MetadataStore, MultiWriteWorker}; use crate::multibackend::model::{is_checkpoint_directory_name, CheckpointsManifest, DirectoryEvent, LatestCheckpoint,PartitionState, PartitionsManifest, ProtocolStatus, ScopeKey, SegmentManifest,}; use crate::multibackend::provider::MultiWriteProvider; +use tracing::info; struct ScopeSnapshot { latest: Option, segments: SegmentManifest} @@ -26,13 +27,26 @@ impl MetadataGc { /// Collect one scope while treating concurrent account deletion as complete. pub async fn collect_scope(&self, scope: &ScopeKey) -> Result<()> { + info!( + account = %scope.account_id, + partition = scope.partition_id, + epoch = scope.epoch, + "multi-write metadata gc started" + ); match self.collect_scope_inner(scope).await { - Err(Error::NotFound(_)) => Ok(()), + Ok(()) | Err(Error::NotFound(_)) => { + info!( + account = %scope.account_id, + partition = scope.partition_id, + epoch = scope.epoch, + "multi-write metadata gc completed" + ); + Ok(()) + } Err(error) => { self.store.record_worker_error(MultiWriteWorker::Gc); Err(error) } - result => result, } } diff --git a/crates/ragfs/src/multibackend/runtime.rs b/crates/ragfs/src/multibackend/runtime.rs index c9f2e16b851..4a5c285b59e 100644 --- a/crates/ragfs/src/multibackend/runtime.rs +++ b/crates/ragfs/src/multibackend/runtime.rs @@ -280,6 +280,7 @@ pub struct FlushWorker { router: AccountRouter, initial_partitions: u32, backup_names: Vec, + initialized_accounts: HashSet, } impl FlushWorker { @@ -298,6 +299,7 @@ impl FlushWorker { primary, initial_partitions, backup_names, + initialized_accounts: HashSet::new(), } } @@ -324,6 +326,7 @@ impl FlushWorker { let mut accounts = HashMap::>::new(); for event in batch { if matches!(event.kind, PendingEventKind::DeleteAccount) { + self.initialized_accounts.remove(&event.account_id); accounts .entry(SYSTEM_DIR.to_string()) .or_default() @@ -347,35 +350,35 @@ impl FlushWorker { } Ok(true) => {} } - match self - .store - .initialize_account(&account, self.initial_partitions, &self.backup_names) - .await - { - Ok(partitions) => { - if let Err(error) = bootstrap_account( - self.provider.as_ref(), - self.store.as_ref(), - &account, - &partitions, - ) + if !self.initialized_accounts.contains(&account) { + match self + .store + .initialize_account(&account, self.initial_partitions, &self.backup_names) .await - { + { + Ok(partitions) => { + if let Err(error) = bootstrap_account( + self.provider.as_ref(), + self.store.as_ref(), + &account, + &partitions, + ) + .await + { + failed = true; + error!(account = %account, error = %error, + "multi-write provider bootstrap failed"); + continue; + } + self.initialized_accounts.insert(account.clone()); + } + Err(error) => { failed = true; error!(account = %account, error = %error, - "multi-write provider bootstrap failed"); + "multi-write account initialization failed"); continue; } } - Err(error) => { - failed = true; - error!( - account = %account, - error = %error, - "multi-write account initialization failed" - ); - continue; - } } let mut groups = HashMap::)>::new();