Skip to content

Commit

Permalink
fix(changelog): size enforcement corrupted cache
Browse files Browse the repository at this point in the history
Fix bug with changelog max size enforcement that caused the remove of
wrong entries from the timestamps cache, corrupting it.
  • Loading branch information
AlonZivony authored and yanivagman committed Jun 2, 2024
1 parent 73839cf commit 0889b0d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,13 @@ func (clv *Changelog[T]) enforceSizeBoundary() {
return false
})

clv.changes = clv.changes[len(clv.changes)-clv.maxSize:]
for i := 0; i < boundaryDiff; i++ {
delete(clv.timestamps, clv.changes[i].timestamp)
if boundaryDiff == 0 {
return
}
removedChanges := clv.changes[:boundaryDiff]
clv.changes = clv.changes[boundaryDiff:]
for _, removedChange := range removedChanges {
delete(clv.timestamps, removedChange.timestamp)
}
}
}
Expand Down

0 comments on commit 0889b0d

Please sign in to comment.