From a8c22c85cc610a4d479dc4c8dcc9f2c9325e95f4 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Mon, 12 Mar 2018 13:16:59 +0000 Subject: [PATCH] Correctly handle pruning wraparound after ring expansion (#3942) Fixes #3939 --- storage/buffer.go | 1 + storage/buffer_test.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/storage/buffer.go b/storage/buffer.go index 0159cfa3f..77476c614 100644 --- a/storage/buffer.go +++ b/storage/buffer.go @@ -178,6 +178,7 @@ func (r *sampleRing) add(t int64, v float64) { r.buf = buf r.i = r.f r.f += l + l = 2 * l } else { r.i++ if r.i >= l { diff --git a/storage/buffer_test.go b/storage/buffer_test.go index 2a1b87248..5b752dec2 100644 --- a/storage/buffer_test.go +++ b/storage/buffer_test.go @@ -48,6 +48,11 @@ func TestSampleRing(t *testing.T) { delta: 7, size: 1, }, + { + input: []int64{1, 2, 3, 4, 6}, + delta: 4, + size: 4, + }, } for _, c := range cases { r := newSampleRing(c.delta, c.size)