From f4b9f638566814adbbeaa05a201a376dcca3f56e Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 8 Jan 2022 22:19:33 +0100 Subject: [PATCH] repository: fix used quota computation storage_quota_use should reflect current disk space usage (not considering some overheads like for the index etc.). if a chunk is deleted, but the segment file containing the chunk is not yet compacted, the chunk's disk space is still in use! when compact_segments is dropping the unused chunks, it is the right time to reduce storage_quota_use. storage_quota_use includes the put header overhead. --- src/borg/repository.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/borg/repository.py b/src/borg/repository.py index 7bf925e62..c89e0376e 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -806,6 +806,7 @@ def complete_xfer(intermediate=True): # do not remove entry with empty shadowed_segments list here, # it is needed for shadowed_put_exists code (see below)! pass + self.storage_quota_use -= len(data) + self.io.put_header_fmt.size elif tag == TAG_DELETE and not in_index: # If the shadow index doesn't contain this key, then we can't say if there's a shadowed older tag, # therefore we do not drop the delete, but write it to a current segment. @@ -906,7 +907,7 @@ def _update_index(self, segment, objects, report=None): pass self.index[key] = segment, offset self.segments[segment] += 1 - self.storage_quota_use += size + self.storage_quota_use += size # note: size already includes the put_header_fmt overhead elif tag == TAG_DELETE: try: # if the deleted PUT is not in the index, there is nothing to clean up @@ -919,7 +920,6 @@ def _update_index(self, segment, objects, report=None): # is already gone, then it was already compacted. self.segments[s] -= 1 size = self.io.read(s, offset, key, read_data=False) - self.storage_quota_use -= size self.compact[s] += size elif tag == TAG_COMMIT: continue @@ -1239,7 +1239,6 @@ def _delete(self, id, segment, offset, *, update_shadow_index): self.shadow_index.setdefault(id, []).append(segment) self.segments[segment] -= 1 size = self.io.read(segment, offset, id, read_data=False) - self.storage_quota_use -= size self.compact[segment] += size segment, size = self.io.write_delete(id) self.compact[segment] += size