From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 5C1CC1FF163 for ; Thu, 12 Sep 2024 16:34:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 10AAF34815; Thu, 12 Sep 2024 16:34:30 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Thu, 12 Sep 2024 16:32:58 +0200 Message-Id: <20240912143322.548839-10-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240912143322.548839-1-c.ebner@proxmox.com> References: <20240912143322.548839-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 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] [PATCH v3 proxmox-backup 09/33] 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 --- changes since version 2: - no changes 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