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:
Julio López
2026-04-11 11:59:07 -07:00
committed by GitHub
parent 2a8ac65be4
commit 775fadcfcf
3 changed files with 6 additions and 4 deletions

View File

@@ -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:]

View File

@@ -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)
})