From 3d12c62121efc0e378fd61d4fa02005b8e10f1ed Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Thu, 27 Jul 2017 11:08:17 -0600 Subject: [PATCH] Avoid repeatedly growning decoded values slices --- tsdb/engine/tsm1/encoding.go | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tsdb/engine/tsm1/encoding.go b/tsdb/engine/tsm1/encoding.go index 2cd5e30940..d6a751c14e 100644 --- a/tsdb/engine/tsm1/encoding.go +++ b/tsdb/engine/tsm1/encoding.go @@ -407,6 +407,14 @@ func DecodeFloatBlock(block []byte, a *[]FloatValue) ([]FloatValue, error) { return nil, err } + sz := CountTimestamps(tb) + + if cap(*a) < sz { + *a = make([]FloatValue, sz) + } else { + *a = (*a)[:sz] + } + tdec := timeDecoderPool.Get(0).(*TimeDecoder) vdec := floatDecoderPool.Get(0).(*FloatDecoder) @@ -537,6 +545,14 @@ func DecodeBooleanBlock(block []byte, a *[]BooleanValue) ([]BooleanValue, error) return nil, err } + sz := CountTimestamps(tb) + + if cap(*a) < sz { + *a = make([]BooleanValue, sz) + } else { + *a = (*a)[:sz] + } + tdec := timeDecoderPool.Get(0).(*TimeDecoder) vdec := booleanDecoderPool.Get(0).(*BooleanDecoder) @@ -655,6 +671,14 @@ func DecodeIntegerBlock(block []byte, a *[]IntegerValue) ([]IntegerValue, error) return nil, err } + sz := CountTimestamps(tb) + + if cap(*a) < sz { + *a = make([]IntegerValue, sz) + } else { + *a = (*a)[:sz] + } + tdec := timeDecoderPool.Get(0).(*TimeDecoder) vdec := integerDecoderPool.Get(0).(*IntegerDecoder) @@ -773,6 +797,14 @@ func DecodeUnsignedBlock(block []byte, a *[]UnsignedValue) ([]UnsignedValue, err return nil, err } + sz := CountTimestamps(tb) + + if cap(*a) < sz { + *a = make([]UnsignedValue, sz) + } else { + *a = (*a)[:sz] + } + tdec := timeDecoderPool.Get(0).(*TimeDecoder) vdec := integerDecoderPool.Get(0).(*IntegerDecoder) @@ -892,6 +924,14 @@ func DecodeStringBlock(block []byte, a *[]StringValue) ([]StringValue, error) { return nil, err } + sz := CountTimestamps(tb) + + if cap(*a) < sz { + *a = make([]StringValue, sz) + } else { + *a = (*a)[:sz] + } + tdec := timeDecoderPool.Get(0).(*TimeDecoder) vdec := stringDecoderPool.Get(0).(*StringDecoder)