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 94CF29768A for ; Tue, 5 Mar 2024 10:28:44 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3F47540B1 for ; Tue, 5 Mar 2024 10:27:51 +0100 (CET) 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, 5 Mar 2024 10:27:49 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4D0894881A for ; Tue, 5 Mar 2024 10:27:49 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Tue, 5 Mar 2024 10:26:51 +0100 Message-Id: <20240305092703.126906-25-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240305092703.126906-1-c.ebner@proxmox.com> References: <20240305092703.126906-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.043 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 - Subject: [pbs-devel] [RFC v2 proxmox-backup 24/36] index: fetch chunk form index by start/end-offset 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, 05 Mar 2024 09:28:44 -0000 In preparation for injecting reused payload chunks in payload streams for regular files with unchanged metaddata. Adds a function to get a list of DynamicEntry's from a chunk index by given start and end offset, the range of which will be contained within these returned chunks. In addition to the list of index entries, the padding to the start of the requested start offset from the first chunk is returned, as well as the end padding following the requested payload to the actual chunk end. The padding is used for calculation of the payload reference offset written to the metadata archive, required for payload access during decoding. Signed-off-by: Christian Ebner --- changes since version 1: - s/Appendable/Reusable/ incorrect naming leftover from previous approach pbs-datastore/src/dynamic_index.rs | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/pbs-datastore/src/dynamic_index.rs b/pbs-datastore/src/dynamic_index.rs index 71a5082e..85c86b32 100644 --- a/pbs-datastore/src/dynamic_index.rs +++ b/pbs-datastore/src/dynamic_index.rs @@ -74,6 +74,26 @@ impl DynamicEntry { } } +/// Dynamic Entry reusable by payload references +#[derive(Clone, Debug)] +#[repr(C)] +pub struct ReusableDynamicEntry { + size_le: u64, + digest: [u8; 32], +} + +impl ReusableDynamicEntry { + #[inline] + pub fn size(&self) -> u64 { + u64::from_le(self.size_le) + } + + #[inline] + pub fn digest(&self) -> [u8; 32] { + self.digest.clone() + } +} + pub struct DynamicIndexReader { _file: File, pub size: usize, @@ -188,6 +208,41 @@ impl DynamicIndexReader { self.binary_search(middle_idx + 1, middle_end, end_idx, end, offset) } } + + /// List of chunk indices containing the data from start_offset to end_offset + pub fn indices( + &self, + start_offset: u64, + end_offset: u64, + ) -> Result<(Vec, u64, u64), Error> { + let end_idx = self.index.len() - 1; + let chunk_end = self.chunk_end(end_idx); + let start = self.binary_search(0, 0, end_idx, chunk_end, start_offset)?; + let end = self.binary_search(0, 0, end_idx, chunk_end, end_offset - 1)?; + + let offset_first = if start == 0 { + 0 + } else { + self.index[start - 1].end() + }; + + let padding_start = start_offset - offset_first; + let padding_end = self.index[end].end() - end_offset; + + let mut indices = Vec::new(); + let mut prev_end = offset_first; + for dynamic_entry in &self.index[start..end + 1] { + let size = dynamic_entry.end() - prev_end; + let reusable_dynamic_entry = ReusableDynamicEntry { + size_le: size.to_le(), + digest: dynamic_entry.digest.clone(), + }; + prev_end += size; + indices.push(reusable_dynamic_entry); + } + + Ok((indices, padding_start, padding_end)) + } } impl IndexFile for DynamicIndexReader { -- 2.39.2