diff --git a/tsdb/exemplar.go b/tsdb/exemplar.go index c7cefaba0..1e09da21e 100644 --- a/tsdb/exemplar.go +++ b/tsdb/exemplar.go @@ -279,7 +279,7 @@ func (ce *CircularExemplarStorage) Resize(l int64) int { migrated := 0 - if l > 0 { + if l > 0 && len(oldBuffer) > 0 { // Rewind previous next index by count with wrap-around. // This math is essentially looking at nextIndex, where we would write the next exemplar to, // and find the index in the old exemplar buffer that we should start migrating exemplars from. diff --git a/tsdb/exemplar_test.go b/tsdb/exemplar_test.go index 8fcaf6d2e..eb95daa34 100644 --- a/tsdb/exemplar_test.go +++ b/tsdb/exemplar_test.go @@ -413,7 +413,7 @@ func TestResize(t *testing.T) { expectedMigrated: 50, }, { - name: "Zero", + name: "ShrinkToZero", startSize: 100, newCount: 0, expectedSeries: []int{}, @@ -436,6 +436,14 @@ func TestResize(t *testing.T) { notExpectedSeries: []int{}, expectedMigrated: 0, }, + { + name: "GrowFromZero", + startSize: 0, + newCount: 10, + expectedSeries: []int{}, + notExpectedSeries: []int{}, + expectedMigrated: 0, + }, } for _, tc := range testCases {