check: do not consider orphan chunks a problem

if we use AdHocCache or NewCache, we do not have precise refcounting.
thus, we do not delete repo objects as their refcount does not go to zero.

check --repair will just remove the orphans.
This commit is contained in:
Thomas Waldmann 2023-09-30 23:32:03 +02:00
parent e2a1999c59
commit 4cd9bc8a6b
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
2 changed files with 6 additions and 5 deletions

View File

@ -2331,10 +2331,10 @@ class ArchiveChecker:
unused = {id_ for id_, entry in self.chunks.iteritems() if entry.refcount == 0} unused = {id_ for id_, entry in self.chunks.iteritems() if entry.refcount == 0}
orphaned = unused - self.possibly_superseded orphaned = unused - self.possibly_superseded
if orphaned: if orphaned:
logger.error(f"{len(orphaned)} orphaned objects found!") logger.info(f"{len(orphaned)} orphaned (unused) objects found.")
for chunk_id in orphaned: for chunk_id in orphaned:
logger.debug(f"chunk {bin_to_hex(chunk_id)} is orphaned.") logger.debug(f"chunk {bin_to_hex(chunk_id)} is orphaned.")
self.error_found = True # To support working with AdHocCache or NewCache, we do not set self.error_found = True.
if self.repair and unused: if self.repair and unused:
logger.info( logger.info(
"Deleting %d orphaned and %d superseded objects..." % (len(orphaned), len(self.possibly_superseded)) "Deleting %d orphaned and %d superseded objects..." % (len(orphaned), len(self.possibly_superseded))

View File

@ -338,10 +338,11 @@ def test_extra_chunks(archivers, request):
with Repository(archiver.repository_location, exclusive=True) as repository: with Repository(archiver.repository_location, exclusive=True) as repository:
repository.put(b"01234567890123456789012345678901", b"xxxx") repository.put(b"01234567890123456789012345678901", b"xxxx")
repository.commit(compact=False) repository.commit(compact=False)
cmd(archiver, "check", exit_code=1) output = cmd(archiver, "check", "-v", exit_code=0) # orphans are not considered warnings anymore
cmd(archiver, "check", exit_code=1) assert "1 orphaned (unused) objects found." in output
cmd(archiver, "check", "--repair", exit_code=0) cmd(archiver, "check", "--repair", exit_code=0)
cmd(archiver, "check", exit_code=0) output = cmd(archiver, "check", "-v", exit_code=0)
assert "orphaned (unused) objects found." not in output
cmd(archiver, "extract", "archive1", "--dry-run", exit_code=0) cmd(archiver, "extract", "archive1", "--dry-run", exit_code=0)