From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 4/7] tape: media_catalog: add local type aliases to make code more clear
Date: Thu, 22 Jul 2021 15:41:03 +0200 [thread overview]
Message-ID: <20210722134106.1280517-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210722134106.1280517-1-d.csapak@proxmox.com>
by adding some type aliases like 'type Store = String',
the more complex types/return values are easier to read.
For example
HashMap<String, u64>
turns into:
HashMap<Snapshot, FileNr>
since those types are not public, the generated cargo docs, do not
contain them
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/tape/media_catalog.rs | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs
index f7fcdd0a..296d1d2f 100644
--- a/src/tape/media_catalog.rs
+++ b/src/tape/media_catalog.rs
@@ -31,9 +31,14 @@ use crate::{
},
};
+type Store = String;
+type Snapshot = String;
+type FileNr = u64;
+type Chunk = [u8; 32];
+
pub struct DatastoreContent {
- pub snapshot_index: HashMap<String, u64>, // snapshot => file_nr
- pub chunk_index: HashMap<[u8;32], u64>, // chunk => file_nr
+ pub snapshot_index: HashMap<Snapshot, FileNr>,
+ pub chunk_index: HashMap<Chunk, FileNr>,
}
impl DatastoreContent {
@@ -61,11 +66,11 @@ pub struct MediaCatalog {
log_to_stdout: bool,
- current_archive: Option<(Uuid, u64, String)>, // (uuid, file_nr, store)
+ current_archive: Option<(Uuid, FileNr, Store)>,
- last_entry: Option<(Uuid, u64)>,
+ last_entry: Option<(Uuid, FileNr)>,
- content: HashMap<String, DatastoreContent>,
+ content: HashMap<Store, DatastoreContent>,
pending: Vec<u8>,
}
@@ -363,13 +368,13 @@ impl MediaCatalog {
}
/// Accessor to content list
- pub fn content(&self) -> &HashMap<String, DatastoreContent> {
+ pub fn content(&self) -> &HashMap<Store, DatastoreContent> {
&self.content
}
fn load_fast_catalog(
file: &mut File,
- ) -> Result<Vec<(String, String)>, Error> {
+ ) -> Result<Vec<(Store, Snapshot)>, Error> {
let mut list = Vec::new();
let file = BufReader::new(file);
for line in file.lines() {
@@ -391,7 +396,7 @@ impl MediaCatalog {
pub fn snapshot_list(
base_path: &Path,
media_id: &MediaId,
- ) -> Result<Vec<(String, String)>, Error> {
+ ) -> Result<Vec<(Store, Snapshot)>, Error> {
let uuid = &media_id.label.uuid;
let mut path = base_path.to_owned();
@@ -531,7 +536,7 @@ impl MediaCatalog {
}
/// Returns the snapshot archive file number
- pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option<u64> {
+ pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option<FileNr> {
match self.content.get(store) {
None => None,
Some(content) => content.snapshot_index.get(snapshot).copied(),
@@ -539,7 +544,7 @@ impl MediaCatalog {
}
/// Test if the catalog already contain a chunk
- pub fn contains_chunk(&self, store: &str, digest: &[u8;32]) -> bool {
+ pub fn contains_chunk(&self, store: &str, digest: &Chunk) -> bool {
match self.content.get(store) {
None => false,
Some(content) => content.chunk_index.contains_key(digest),
@@ -547,7 +552,7 @@ impl MediaCatalog {
}
/// Returns the chunk archive file number
- pub fn lookup_chunk(&self, store: &str, digest: &[u8;32]) -> Option<u64> {
+ pub fn lookup_chunk(&self, store: &str, digest: &Chunk) -> Option<FileNr> {
match self.content.get(store) {
None => None,
Some(content) => content.chunk_index.get(digest).copied(),
@@ -634,7 +639,7 @@ impl MediaCatalog {
/// Only valid after start_chunk_archive.
fn register_chunk(
&mut self,
- digest: &[u8;32],
+ digest: &Chunk,
) -> Result<(), Error> {
let (file_number, store) = match self.current_archive {
@@ -1052,7 +1057,7 @@ impl MediaSetCatalog {
}
/// Returns the media uuid and snapshot archive file number
- pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option<(&Uuid, u64)> {
+ pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option<(&Uuid, FileNr)> {
for (uuid, catalog) in self.catalog_list.iter() {
if let Some(nr) = catalog.lookup_snapshot(store, snapshot) {
return Some((uuid, nr));
@@ -1062,7 +1067,7 @@ impl MediaSetCatalog {
}
/// Test if the catalog already contain a chunk
- pub fn contains_chunk(&self, store: &str, digest: &[u8;32]) -> bool {
+ pub fn contains_chunk(&self, store: &str, digest: &Chunk) -> bool {
for catalog in self.catalog_list.values() {
if catalog.contains_chunk(store, digest) {
return true;
@@ -1072,7 +1077,7 @@ impl MediaSetCatalog {
}
/// Returns the media uuid and chunk archive file number
- pub fn lookup_chunk(&self, store: &str, digest: &[u8;32]) -> Option<(&Uuid, u64)> {
+ pub fn lookup_chunk(&self, store: &str, digest: &Chunk) -> Option<(&Uuid, FileNr)> {
for (uuid, catalog) in self.catalog_list.iter() {
if let Some(nr) = catalog.lookup_chunk(store, digest) {
return Some((uuid, nr));
--
2.30.2
next prev parent reply other threads:[~2021-07-22 13:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-22 13:40 [pbs-devel] [PATCH proxmox-backup v2 0/7] improve catalog handling Dominik Csapak
2021-07-22 13:41 ` [pbs-devel] [PATCH proxmox-backup v2 1/7] tape: media_catalog: improve chunk_archive interface Dominik Csapak
2021-07-26 8:21 ` [pbs-devel] applied: " Dietmar Maurer
2021-07-22 13:41 ` [pbs-devel] [PATCH proxmox-backup v2 2/7] tape: media_catalog: add fast_catalog beside normal catalog Dominik Csapak
2021-07-27 6:53 ` Dietmar Maurer
2021-07-22 13:41 ` [pbs-devel] [PATCH proxmox-backup v2 3/7] tape: pool_writer: finish the catalog when its done Dominik Csapak
2021-07-22 13:41 ` Dominik Csapak [this message]
2021-07-27 7:10 ` [pbs-devel] [PATCH proxmox-backup v2 4/7] tape: media_catalog: add local type aliases to make code more clear Dietmar Maurer
2021-07-22 13:41 ` [pbs-devel] [PATCH proxmox-backup v2 5/7] api2: tape/backup: commit pool_writer even on error Dominik Csapak
2021-07-22 13:41 ` [pbs-devel] [PATCH proxmox-backup v2 6/7] api2: tape/restore: finish temporary catalog at the end Dominik Csapak
2021-07-22 13:41 ` [pbs-devel] [PATCH proxmox-backup v2 7/7] api2: tape: media: use MediaCatalog::snapshot_list for content listing Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210722134106.1280517-5-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal