瀏覽代碼

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.
Thomas Waldmann 3 年之前
父節點
當前提交
f4b9f63856
共有 1 個文件被更改,包括 2 次插入3 次删除
  1. 2 3
      src/borg/repository.py

+ 2 - 3
src/borg/repository.py

@@ -806,6 +806,7 @@ class Repository:
                         # 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 @@ class Repository:
                     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 @@ class Repository:
                         # 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 @@ class Repository:
             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