mirror of
https://github.com/kopia/kopia.git
synced 2026-05-09 15:23:02 -04:00
fix(general): retained log size double counting (#5302)
Fix computation CleanupLogsStats.RetainedBlobSize. The size of the first blob being deleted was also accounted towards the retained blob size. Fix: retainedSize is now incremented only after the size check. Rename package-private rate limiter variable from limit to negativeValueWarningLimit for clarity.
This commit is contained in:
@@ -69,9 +69,9 @@ func CleanupLogs(ctx context.Context, rep repo.DirectRepositoryWriter, opt LogRe
|
||||
deletePosition := len(allLogBlobs)
|
||||
|
||||
for i, bm := range allLogBlobs {
|
||||
retainedSize += maintenancestats.ToUint64(bm.Length)
|
||||
bmlen := maintenancestats.ToUint64(bm.Length)
|
||||
|
||||
if opt.MaxTotalSize > 0 && retainedSize > uint64(opt.MaxTotalSize) {
|
||||
if opt.MaxTotalSize > 0 && retainedSize+bmlen > uint64(opt.MaxTotalSize) {
|
||||
deletePosition = i
|
||||
break
|
||||
}
|
||||
@@ -85,6 +85,8 @@ func CleanupLogs(ctx context.Context, rep repo.DirectRepositoryWriter, opt LogRe
|
||||
deletePosition = i
|
||||
break
|
||||
}
|
||||
|
||||
retainedSize += bmlen
|
||||
}
|
||||
|
||||
toDelete := allLogBlobs[deletePosition:]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
var limit = rate.Sometimes{First: 10} //nolint:mnd
|
||||
var negativeValueWarningLimit = rate.Sometimes{First: 10} //nolint:mnd
|
||||
|
||||
// ToUint64 converts v from a signed integer type T to uint64 while checking that
|
||||
// the value is non-negative. It returns 0 for negative values.
|
||||
@@ -15,7 +15,7 @@ func ToUint64[T int8 | int16 | int32 | int | int64](v T) uint64 {
|
||||
return uint64(v)
|
||||
}
|
||||
|
||||
limit.Do(func() {
|
||||
negativeValueWarningLimit.Do(func() {
|
||||
log.Println("warning, converting negative value to uint64:", v)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user