mirror of https://github.com/restic/restic.git
prune: Fix calculation of remaining uncompressed data
Only the repacking of *un*compressed packs reduces the amount of uncompressed data. Previously the counter even overflowed for fully compressed repositories.
This commit is contained in:
parent
bcae28afb4
commit
81dc8c8d13
|
@ -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,8 +605,10 @@ 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
|
||||||
|
if p.uncompressed {
|
||||||
stats.size.uncompressed -= p.unusedSize + p.usedSize
|
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
|
||||||
maxUnusedSizeAfter := opts.maxUnusedBytes(stats.size.used)
|
maxUnusedSizeAfter := opts.maxUnusedBytes(stats.size.used)
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue