mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-07-22 06:50:38 +02:00
fix(metricstore): guard stats fast path against empty buffer
Add len(b.data) > 0 guard to prevent infinite loop when an empty linked buffer is reachable. With the guard false, the normal path handles empty buffers safely via the existing t < b.start || idx >= len(b.data) check. Add regression test TestStatsFastPathThenPartialTail to pin the boundary: three-buffer chain where earlier buffers are fully covered (fast path) and the last buffer is partially covered (normal path). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -74,7 +74,7 @@ func (b *buffer) stats(from, to int64) (Stats, int64, int64, error) {
|
||||
// past the buffer's real data instead of scanning each point. Any slots
|
||||
// between len(data) and cap are handled as gaps by the normal loop after
|
||||
// t advances, so the returned `to` matches the scan semantics.
|
||||
if idx <= 0 && t <= b.firstWrite() && b.end() <= to {
|
||||
if len(b.data) > 0 && idx <= 0 && t <= b.firstWrite() && b.end() <= to {
|
||||
if !b.statsValid {
|
||||
b.recomputeStats()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user