mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
tier: avoid stats infinite loop in forwardTo method (#15640)
under some sequence of events following code would reach an infinite loop. ``` idx1, idx2 := 0, 1 for ; idx2 != idx1; idx2++ { fmt.Println(idx2) } ``` fixes #15639
This commit is contained in:
parent
5ce1448049
commit
f649968c69
@ -38,6 +38,10 @@ func (l *lastDayTierStats) addStats(ts tierStats) {
|
|||||||
|
|
||||||
// forwardTo moves time to t, clearing entries between last update and t.
|
// forwardTo moves time to t, clearing entries between last update and t.
|
||||||
func (l *lastDayTierStats) forwardTo(t time.Time) {
|
func (l *lastDayTierStats) forwardTo(t time.Time) {
|
||||||
|
if t.IsZero() {
|
||||||
|
t = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
since := t.Sub(l.UpdatedAt).Hours()
|
since := t.Sub(l.UpdatedAt).Hours()
|
||||||
// within the hour since l.UpdatedAt
|
// within the hour since l.UpdatedAt
|
||||||
if since < 1 {
|
if since < 1 {
|
||||||
@ -45,15 +49,17 @@ func (l *lastDayTierStats) forwardTo(t time.Time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
idx, lastIdx := t.Hour(), l.UpdatedAt.Hour()
|
idx, lastIdx := t.Hour(), l.UpdatedAt.Hour()
|
||||||
l.UpdatedAt = t
|
|
||||||
|
l.UpdatedAt = t // update to the latest time index
|
||||||
|
|
||||||
if since >= 24 {
|
if since >= 24 {
|
||||||
l.Bins = [24]tierStats{}
|
l.Bins = [24]tierStats{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for ; lastIdx != idx; lastIdx++ {
|
for lastIdx != idx {
|
||||||
l.Bins[(lastIdx+1)%24] = tierStats{}
|
lastIdx = (lastIdx + 1) % 24
|
||||||
|
l.Bins[lastIdx] = tierStats{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user