tape/pool_writer: give proper types to 'contains_snapshot'

instead of a string. The underlying catalog implementation has to
care about how this is formatted, not the external caller

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2022-05-16 13:36:09 +02:00 committed by Fabian Grünbichler
parent 789e22d905
commit 8bec3ff691
4 changed files with 41 additions and 11 deletions

View File

@ -496,7 +496,11 @@ fn backup_worker(
if let Some(info) = snapshot_list.pop() { if let Some(info) = snapshot_list.pop() {
let rel_path = let rel_path =
print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref()); print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref());
if pool_writer.contains_snapshot(datastore_name, &rel_path) { if pool_writer.contains_snapshot(
datastore_name,
&info.backup_dir.backup_ns(),
info.backup_dir.as_ref(),
) {
task_log!(worker, "skip snapshot {}", rel_path); task_log!(worker, "skip snapshot {}", rel_path);
continue; continue;
} }
@ -517,7 +521,11 @@ fn backup_worker(
let rel_path = let rel_path =
print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref()); print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref());
if pool_writer.contains_snapshot(datastore_name, &rel_path) { if pool_writer.contains_snapshot(
datastore_name,
&info.backup_dir.backup_ns(),
info.backup_dir.as_ref(),
) {
task_log!(worker, "skip snapshot {}", rel_path); task_log!(worker, "skip snapshot {}", rel_path);
continue; continue;
} }

View File

@ -411,10 +411,16 @@ impl MediaCatalog {
} }
/// Test if the catalog already contain a snapshot /// Test if the catalog already contain a snapshot
pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool { pub fn contains_snapshot(
&self,
store: &str,
ns: &BackupNamespace,
snapshot: &BackupDir,
) -> bool {
let path = print_ns_and_snapshot(ns, snapshot);
match self.content.get(store) { match self.content.get(store) {
None => false, None => false,
Some(content) => content.snapshot_index.contains_key(snapshot), Some(content) => content.snapshot_index.contains_key(&path),
} }
} }
@ -960,9 +966,14 @@ impl MediaSetCatalog {
} }
/// Test if the catalog already contain a snapshot /// Test if the catalog already contain a snapshot
pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool { pub fn contains_snapshot(
&self,
store: &str,
ns: &BackupNamespace,
snapshot: &BackupDir,
) -> bool {
for catalog in self.catalog_list.values() { for catalog in self.catalog_list.values() {
if catalog.contains_snapshot(store, snapshot) { if catalog.contains_snapshot(store, ns, snapshot) {
return true; return true;
} }
} }

View File

@ -29,13 +29,19 @@ impl CatalogSet {
} }
/// Test if the catalog already contains a snapshot /// Test if the catalog already contains a snapshot
pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool { pub fn contains_snapshot(
&self,
store: &str,
ns: &pbs_api_types::BackupNamespace,
snapshot: &pbs_api_types::BackupDir,
) -> bool {
if let Some(ref catalog) = self.catalog { if let Some(ref catalog) = self.catalog {
if catalog.contains_snapshot(store, snapshot) { if catalog.contains_snapshot(store, ns, snapshot) {
return true; return true;
} }
} }
self.media_set_catalog.contains_snapshot(store, snapshot) self.media_set_catalog
.contains_snapshot(store, ns, snapshot)
} }
/// Test if the catalog already contains a chunk /// Test if the catalog already contains a chunk

View File

@ -100,11 +100,16 @@ impl PoolWriter {
Ok(()) Ok(())
} }
pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool { pub fn contains_snapshot(
&self,
store: &str,
ns: &pbs_api_types::BackupNamespace,
snapshot: &pbs_api_types::BackupDir,
) -> bool {
self.catalog_set self.catalog_set
.lock() .lock()
.unwrap() .unwrap()
.contains_snapshot(store, snapshot) .contains_snapshot(store, ns, snapshot)
} }
/// Eject media and drop PoolWriterState (close drive) /// Eject media and drop PoolWriterState (close drive)