From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 911148F6F for ; Tue, 1 Aug 2023 11:29:56 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7A93AC3E8 for ; Tue, 1 Aug 2023 11:29:56 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 1 Aug 2023 11:29:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 25CFD4392E for ; Tue, 1 Aug 2023 11:29:55 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 1 Aug 2023 11:29:52 +0200 Message-Id: <20230801092954.1686860-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230801092954.1686860-1-d.csapak@proxmox.com> References: <20230801092954.1686860-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 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 T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [environment.rs, datastore.rs] Subject: [pbs-devel] [RFC PATCH proxmox-backup 1/3] api-types: make UploadStatistic an api type 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: , X-List-Received-Date: Tue, 01 Aug 2023 09:29:56 -0000 and move it to pbs_api_types. We'll want this to expose on the api. Signed-off-by: Dominik Csapak --- pbs-api-types/src/datastore.rs | 38 ++++++++++++++++++++++++++++++++++ src/api2/backup/environment.rs | 35 +------------------------------ 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index 73c4890e..41db680c 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -419,6 +419,44 @@ pub struct SnapshotVerifyState { pub state: VerifyState, } +#[api()] +#[derive(Copy, Clone, Serialize, Deserialize)] +/// Chunk upload statistics of a snapshot +pub struct UploadStatistic { + /// Amount of chunks uploaded (incl. duplicates) + pub count: u64, + /// Uncompressed bytes uploaded + pub size: u64, + /// Compressed bytes uploaded + pub compressed_size: u64, + /// Amount of duplicate chunks uploaded + pub duplicates: u64, +} + +impl UploadStatistic { + pub fn new() -> Self { + Self { + count: 0, + size: 0, + compressed_size: 0, + duplicates: 0, + } + } +} + +impl std::ops::Add for UploadStatistic { + type Output = Self; + + fn add(self, other: Self) -> Self { + Self { + count: self.count + other.count, + size: self.size + other.size, + compressed_size: self.compressed_size + other.compressed_size, + duplicates: self.duplicates + other.duplicates, + } + } +} + /// A namespace provides a logical separation between backup groups from different domains /// (cluster, sites, ...) where uniqueness cannot be guaranteed anymore. It allows users to share a /// datastore (i.e., one deduplication domain (chunk store)) with multiple (trusted) sites and diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs index 5291bce8..0188bffc 100644 --- a/src/api2/backup/environment.rs +++ b/src/api2/backup/environment.rs @@ -3,13 +3,12 @@ use nix::dir::Dir; use std::collections::HashMap; use std::sync::{Arc, Mutex}; -use ::serde::Serialize; use serde_json::{json, Value}; use proxmox_router::{RpcEnvironment, RpcEnvironmentType}; use proxmox_sys::fs::{lock_dir_noblock_shared, replace_file, CreateOptions}; -use pbs_api_types::Authid; +use pbs_api_types::{Authid, UploadStatistic}; use pbs_datastore::backup_info::{BackupDir, BackupInfo}; use pbs_datastore::dynamic_index::DynamicIndexWriter; use pbs_datastore::fixed_index::FixedIndexWriter; @@ -20,38 +19,6 @@ use crate::backup::verify_backup_dir_with_lock; use hyper::{Body, Response}; -#[derive(Copy, Clone, Serialize)] -struct UploadStatistic { - count: u64, - size: u64, - compressed_size: u64, - duplicates: u64, -} - -impl UploadStatistic { - fn new() -> Self { - Self { - count: 0, - size: 0, - compressed_size: 0, - duplicates: 0, - } - } -} - -impl std::ops::Add for UploadStatistic { - type Output = Self; - - fn add(self, other: Self) -> Self { - Self { - count: self.count + other.count, - size: self.size + other.size, - compressed_size: self.compressed_size + other.compressed_size, - duplicates: self.duplicates + other.duplicates, - } - } -} - struct DynamicWriterState { name: String, index: DynamicIndexWriter, -- 2.30.2