From 91d0a8c3d25af24f2da60015a851870ad648bcd1 Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Thu, 20 Sep 2018 18:18:22 -0700 Subject: [PATCH] Fix index bug in float encoder --- tsdb/engine/tsm1/batch_float.go | 2 +- tsdb/engine/tsm1/batch_float_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tsdb/engine/tsm1/batch_float.go b/tsdb/engine/tsm1/batch_float.go index 44a9e399bd..18a71d5327 100644 --- a/tsdb/engine/tsm1/batch_float.go +++ b/tsdb/engine/tsm1/batch_float.go @@ -68,7 +68,7 @@ func FloatArrayEncodeAll(src []float64, b []byte) ([]byte, error) { // First the current bit of the current byte is set to indicate we're // writing a delta value to the stream. - if n>>3 >= uint64(len(b)) { // Grow b — no room in current byte. + for n>>3 >= uint64(len(b)) { // Keep growing b until we can fit all bits in. b = append(b, byte(0)) } diff --git a/tsdb/engine/tsm1/batch_float_test.go b/tsdb/engine/tsm1/batch_float_test.go index 41f4b5f7b1..e834c266d4 100644 --- a/tsdb/engine/tsm1/batch_float_test.go +++ b/tsdb/engine/tsm1/batch_float_test.go @@ -15,6 +15,13 @@ import ( "github.com/influxdata/influxdb/tsdb/engine/tsm1" ) +var fullBlockFloat64Ones []float64 + +func init() { + for i := 0; i < 1000; i++ { + fullBlockFloat64Ones = append(fullBlockFloat64Ones, 1.0) + } +} func TestFloatArrayEncodeAll(t *testing.T) { examples := [][]float64{ {12, 12, 24, 13, 24, 24, 24, 24}, // From example paper. @@ -28,6 +35,7 @@ func TestFloatArrayEncodeAll(t *testing.T) { 3.5635180996210295e+307}, // Failed during early development {6.00065e+06, 6.000656e+06, 6.000657e+06, 6.000659e+06, 6.000661e+06}, // Similar values. twoHoursData, + fullBlockFloat64Ones, {}, }