From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 37BA91FF2A0 for ; Mon, 15 Jul 2024 12:16:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 359B9161; Mon, 15 Jul 2024 12:17:20 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 15 Jul 2024 12:15:52 +0200 Message-Id: <20240715101602.274244-15-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240715101602.274244-1-c.ebner@proxmox.com> References: <20240715101602.274244-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.021 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [RFC proxmox-backup 14/24] server: sync: move skip info/reason to common sync module X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Make `SkipReason` and `SkipInfo` accessible for sync operations of both direction variants, push and pull. Signed-off-by: Christian Ebner --- src/server/pull.rs | 82 ++-------------------------------------------- src/server/sync.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 80 deletions(-) diff --git a/src/server/pull.rs b/src/server/pull.rs index c6932dcc5..d18c6d643 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -28,7 +28,8 @@ use pbs_datastore::{check_backup_owner, DataStore, StoreProgress}; use pbs_tools::sha::sha256; use super::sync::{ - LocalSource, RemoteSource, RemovedVanishedStats, SyncSource, SyncSourceReader, SyncStats, + LocalSource, RemoteSource, RemovedVanishedStats, SkipInfo, SkipReason, SyncSource, + SyncSourceReader, SyncStats, }; use crate::backup::{check_ns_modification_privs, check_ns_privs}; use crate::tools::parallel_handler::ParallelHandler; @@ -474,85 +475,6 @@ async fn pull_snapshot_from<'a>( Ok(sync_stats) } -#[derive(PartialEq, Eq)] -enum SkipReason { - AlreadySynced, - TransferLast, -} - -impl std::fmt::Display for SkipReason { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - match self { - SkipReason::AlreadySynced => "older than the newest local snapshot", - SkipReason::TransferLast => "due to transfer-last", - } - ) - } -} - -struct SkipInfo { - oldest: i64, - newest: i64, - count: u64, - skip_reason: SkipReason, -} - -impl SkipInfo { - fn new(skip_reason: SkipReason) -> Self { - SkipInfo { - oldest: i64::MAX, - newest: i64::MIN, - count: 0, - skip_reason, - } - } - - fn reset(&mut self) { - self.count = 0; - self.oldest = i64::MAX; - self.newest = i64::MIN; - } - - fn update(&mut self, backup_time: i64) { - self.count += 1; - - if backup_time < self.oldest { - self.oldest = backup_time; - } - - if backup_time > self.newest { - self.newest = backup_time; - } - } - - fn affected(&self) -> Result { - match self.count { - 0 => Ok(String::new()), - 1 => Ok(proxmox_time::epoch_to_rfc3339_utc(self.oldest)?), - _ => Ok(format!( - "{} .. {}", - proxmox_time::epoch_to_rfc3339_utc(self.oldest)?, - proxmox_time::epoch_to_rfc3339_utc(self.newest)?, - )), - } - } -} - -impl std::fmt::Display for SkipInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "skipped: {} snapshot(s) ({}) - {}", - self.count, - self.affected().map_err(|_| std::fmt::Error)?, - self.skip_reason, - ) - } -} - /// Pulls a group according to `params`. /// /// Pulling a group consists of the following steps: diff --git a/src/server/sync.rs b/src/server/sync.rs index f8a1e133d..ffc32f45f 100644 --- a/src/server/sync.rs +++ b/src/server/sync.rs @@ -467,3 +467,82 @@ impl SyncSource for LocalSource { })) } } + +#[derive(PartialEq, Eq)] +pub(crate) enum SkipReason { + AlreadySynced, + TransferLast, +} + +impl std::fmt::Display for SkipReason { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + SkipReason::AlreadySynced => "older than the newest local snapshot", + SkipReason::TransferLast => "due to transfer-last", + } + ) + } +} + +pub(crate) struct SkipInfo { + oldest: i64, + newest: i64, + pub(crate) count: u64, + skip_reason: SkipReason, +} + +impl SkipInfo { + pub(crate) fn new(skip_reason: SkipReason) -> Self { + SkipInfo { + oldest: i64::MAX, + newest: i64::MIN, + count: 0, + skip_reason, + } + } + + pub(crate) fn reset(&mut self) { + self.count = 0; + self.oldest = i64::MAX; + self.newest = i64::MIN; + } + + pub(crate) fn update(&mut self, backup_time: i64) { + self.count += 1; + + if backup_time < self.oldest { + self.oldest = backup_time; + } + + if backup_time > self.newest { + self.newest = backup_time; + } + } + + fn affected(&self) -> Result { + match self.count { + 0 => Ok(String::new()), + 1 => Ok(proxmox_time::epoch_to_rfc3339_utc(self.oldest)?), + _ => Ok(format!( + "{} .. {}", + proxmox_time::epoch_to_rfc3339_utc(self.oldest)?, + proxmox_time::epoch_to_rfc3339_utc(self.newest)?, + )), + } + } +} + +impl std::fmt::Display for SkipInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "skipped: {} snapshot(s) ({}) - {}", + self.count, + self.affected().map_err(|_| std::fmt::Error)?, + self.skip_reason, + ) + } +} -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel