2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 22:27:35 +00:00

Merge pull request #4109 from MichaelEischer/fix-prune-uncompressed-accounting

prune: Fix calculation of remaining uncompressed data
This commit is contained in:
Michael Eischer 2023-01-03 23:28:10 +01:00 committed by GitHub
commit e02a10c58a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -254,6 +254,7 @@ type packInfo struct {
type packInfoWithID struct { type packInfoWithID struct {
ID restic.ID ID restic.ID
packInfo packInfo
mustCompress bool
} }
// planPrune selects which files to rewrite and which to delete and which blobs to keep. // planPrune selects which files to rewrite and which to delete and which blobs to keep.
@ -507,8 +508,6 @@ func decidePackAction(ctx context.Context, opts PruneOptions, repo restic.Reposi
// compress data blobs if requested // compress data blobs if requested
mustCompress = (p.tpe == restic.TreeBlob || opts.RepackUncompressed) && p.uncompressed mustCompress = (p.tpe == restic.TreeBlob || opts.RepackUncompressed) && p.uncompressed
} }
// use as flag that pack must be compressed
p.uncompressed = mustCompress
// decide what to do // decide what to do
switch { switch {
@ -527,12 +526,12 @@ func decidePackAction(ctx context.Context, opts PruneOptions, repo restic.Reposi
// All blobs in pack are used and not mixed => keep pack! // All blobs in pack are used and not mixed => keep pack!
stats.packs.keep++ stats.packs.keep++
} else { } else {
repackSmallCandidates = append(repackSmallCandidates, packInfoWithID{ID: id, packInfo: p}) repackSmallCandidates = append(repackSmallCandidates, packInfoWithID{ID: id, packInfo: p, mustCompress: mustCompress})
} }
default: default:
// all other packs are candidates for repacking // all other packs are candidates for repacking
repackCandidates = append(repackCandidates, packInfoWithID{ID: id, packInfo: p}) repackCandidates = append(repackCandidates, packInfoWithID{ID: id, packInfo: p, mustCompress: mustCompress})
} }
delete(indexPack, id) delete(indexPack, id)
@ -606,7 +605,9 @@ func decidePackAction(ctx context.Context, opts PruneOptions, repo restic.Reposi
stats.size.repack += p.unusedSize + p.usedSize stats.size.repack += p.unusedSize + p.usedSize
stats.blobs.repackrm += p.unusedBlobs stats.blobs.repackrm += p.unusedBlobs
stats.size.repackrm += p.unusedSize stats.size.repackrm += p.unusedSize
stats.size.uncompressed -= p.unusedSize + p.usedSize if p.uncompressed {
stats.size.uncompressed -= p.unusedSize + p.usedSize
}
} }
// calculate limit for number of unused bytes in the repo after repacking // calculate limit for number of unused bytes in the repo after repacking
@ -621,7 +622,7 @@ func decidePackAction(ctx context.Context, opts PruneOptions, repo restic.Reposi
case reachedRepackSize: case reachedRepackSize:
stats.packs.keep++ stats.packs.keep++
case p.tpe != restic.DataBlob, p.uncompressed: case p.tpe != restic.DataBlob, p.mustCompress:
// repacking non-data packs / uncompressed-trees is only limited by repackSize // repacking non-data packs / uncompressed-trees is only limited by repackSize
repack(p.ID, p.packInfo) repack(p.ID, p.packInfo)