Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/borg/legacyrepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,12 @@ def complete_xfer(intermediate=True):
for segment in unused:
logger.debug("complete_xfer: Deleting unused segment %d", segment)
count = self.segments.pop(segment)
assert count == 0, "Corrupted segment reference count - corrupted index or hints"
if count != 0:
logger.warning(
"Corrupted segment reference count %d (expected 0) for segment %d - corrupted index or hints",
count,
segment,
)
self.io.delete_segment(segment)
del self.compact[segment]
unused = []
Expand All @@ -748,7 +753,8 @@ def complete_xfer(intermediate=True):
for segment, freeable_space in sorted(self.compact.items()):
if not self.io.segment_exists(segment):
logger.warning("Segment %d not found, but listed in compaction data", segment)
del self.compact[segment]
self.compact.pop(segment, None)
self.segments.pop(segment, None)
pi.show()
self._send_log()
continue
Expand Down Expand Up @@ -867,7 +873,12 @@ def complete_xfer(intermediate=True):
if not self.shadow_index[key]:
# shadowed segments list is empty -> remove it
del self.shadow_index[key]
assert segments[segment] == 0, "Corrupted segment reference count - corrupted index or hints"
if segments[segment] != 0:
logger.warning(
"Corrupted segment reference count %d (expected 0) for segment %d - corrupted index or hints",
segments[segment],
segment,
)
unused.append(segment)
pi.show()
self._send_log()
Expand Down
13 changes: 8 additions & 5 deletions src/borg/testsuite/legacyrepository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,17 +654,20 @@ def test_subtly_corrupted_hints(repository):
assert pdchunk(repository.get(H(2))) == b"bazz"


def test_subtly_corrupted_hints_without_integrity(repository):
def test_subtly_corrupted_hints_without_integrity(repository, caplog):
make_auxiliary(repository)
_subtly_corrupted_hints_setup(repository)
integrity_path = os.path.join(repository.path, "integrity.5")
os.unlink(integrity_path)
with repository:
repository.put(H(3), fchunk(b"1234"))
# do a compaction run, which fails since the corrupted refcount wasn't detected and causes an assertion failure.
with pytest.raises(AssertionError) as exc_info:
repository.commit(compact=True)
assert "Corrupted segment reference count" in str(exc_info.value)
# Do a compaction run.
# The corrupted refcount is detected and logged as a warning, but compaction proceeds.
caplog.set_level(logging.WARNING, logger="borg.legacyrepository")
repository.commit(compact=True)
assert "Corrupted segment reference count" in caplog.text
# We verify that the repository is still consistent.
assert repository.check()


def list_indices(repo_path):
Expand Down
Loading