diff --git a/src/dbnode/encoding/encoding_mock.go b/src/dbnode/encoding/encoding_mock.go index 0383b2851c..d2f140e5ea 100644 --- a/src/dbnode/encoding/encoding_mock.go +++ b/src/dbnode/encoding/encoding_mock.go @@ -561,34 +561,6 @@ func (mr *MockOptionsMockRecorder) SetTimeEncodingSchemes(value interface{}) *go return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTimeEncodingSchemes", reflect.TypeOf((*MockOptions)(nil).SetTimeEncodingSchemes), value) } -// SetValueDecreaseTolerance mocks base method. -func (m *MockOptions) SetValueDecreaseTolerance(value float64) Options { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetValueDecreaseTolerance", value) - ret0, _ := ret[0].(Options) - return ret0 -} - -// SetValueDecreaseTolerance indicates an expected call of SetValueDecreaseTolerance. -func (mr *MockOptionsMockRecorder) SetValueDecreaseTolerance(value interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetValueDecreaseTolerance", reflect.TypeOf((*MockOptions)(nil).SetValueDecreaseTolerance), value) -} - -// SetValueDecreaseToleranceUntil mocks base method. -func (m *MockOptions) SetValueDecreaseToleranceUntil(value time0.UnixNano) Options { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetValueDecreaseToleranceUntil", value) - ret0, _ := ret[0].(Options) - return ret0 -} - -// SetValueDecreaseToleranceUntil indicates an expected call of SetValueDecreaseToleranceUntil. -func (mr *MockOptionsMockRecorder) SetValueDecreaseToleranceUntil(value interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetValueDecreaseToleranceUntil", reflect.TypeOf((*MockOptions)(nil).SetValueDecreaseToleranceUntil), value) -} - // TimeEncodingSchemes mocks base method. func (m *MockOptions) TimeEncodingSchemes() TimeEncodingSchemes { m.ctrl.T.Helper() @@ -603,21 +575,6 @@ func (mr *MockOptionsMockRecorder) TimeEncodingSchemes() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TimeEncodingSchemes", reflect.TypeOf((*MockOptions)(nil).TimeEncodingSchemes)) } -// ValueDecreaseTolerance mocks base method. -func (m *MockOptions) ValueDecreaseTolerance() (float64, time0.UnixNano) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ValueDecreaseTolerance") - ret0, _ := ret[0].(float64) - ret1, _ := ret[1].(time0.UnixNano) - return ret0, ret1 -} - -// ValueDecreaseTolerance indicates an expected call of ValueDecreaseTolerance. -func (mr *MockOptionsMockRecorder) ValueDecreaseTolerance() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValueDecreaseTolerance", reflect.TypeOf((*MockOptions)(nil).ValueDecreaseTolerance)) -} - // MockIterator is a mock of Iterator interface. type MockIterator struct { ctrl *gomock.Controller diff --git a/src/dbnode/encoding/m3tsz/iterator.go b/src/dbnode/encoding/m3tsz/iterator.go index 2d5cf870c4..c1ead34e08 100644 --- a/src/dbnode/encoding/m3tsz/iterator.go +++ b/src/dbnode/encoding/m3tsz/iterator.go @@ -99,14 +99,7 @@ func (it *readerIterator) Next() bool { if !it.intOptimized || it.isFloat { it.curr.Value = math.Float64frombits(it.floatIter.PrevFloatBits) } else { - prevValue := it.curr.Value - currValue := convertFromIntFloat(it.intVal, it.mult) - decreaseTolerance, toleranceUntil := it.opts.ValueDecreaseTolerance() - if decreaseTolerance > 0 && it.curr.TimestampNanos.Before(toleranceUntil) && - !first && currValue < prevValue && currValue > prevValue*(1-decreaseTolerance) { - currValue = prevValue - } - it.curr.Value = currValue + it.curr.Value = convertFromIntFloat(it.intVal, it.mult) } return it.hasNext() diff --git a/src/dbnode/encoding/m3tsz/iterator_test.go b/src/dbnode/encoding/m3tsz/iterator_test.go index b973b63576..017c0a25f3 100644 --- a/src/dbnode/encoding/m3tsz/iterator_test.go +++ b/src/dbnode/encoding/m3tsz/iterator_test.go @@ -28,10 +28,8 @@ import ( "github.com/m3db/m3/src/dbnode/encoding" "github.com/m3db/m3/src/dbnode/ts" "github.com/m3db/m3/src/dbnode/x/xio" - "github.com/m3db/m3/src/x/context" xtime "github.com/m3db/m3/src/x/time" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -412,93 +410,3 @@ func TestReaderIteratorDecodingRegression(t *testing.T) { require.NoError(t, it.Err()) } - -func TestReaderIteratorDecodingDecreaseTolerance(t *testing.T) { - now := xtime.Now().Truncate(time.Hour) - tests := []struct { - name string - given []float64 - tolerance float64 - until xtime.UnixNano - want []float64 - }{ - { - name: "no tolerance", - given: []float64{187.80131100000006, 187.801311, 187.80131100000006, 187.801311, 200, 199.99}, - tolerance: 0, - until: 0, - want: []float64{187.80131100000006, 187.801311, 187.80131100000006, 187.801311, 200, 199.99}, - }, - { - name: "low tolerance", - given: []float64{187.80131100000006, 187.801311, 187.80131100000006, 187.801311, 200, 199.99}, - tolerance: 0.00000001, - until: now.Add(time.Hour), - want: []float64{187.80131100000006, 187.80131100000006, 187.80131100000006, 187.80131100000006, 200, 199.99}, - }, - { - name: "high tolerance", - given: []float64{187.80131100000006, 187.801311, 187.80131100000006, 187.801311, 200, 199.99}, - tolerance: 0.0001, - until: now.Add(time.Hour), - want: []float64{187.80131100000006, 187.80131100000006, 187.80131100000006, 187.80131100000006, 200, 200}, - }, - { - name: "tolerance expired", - given: []float64{200, 199.99, 200, 199.99, 200, 199.99}, - tolerance: 0.0001, - until: now, - want: []float64{200, 199.99, 200, 199.99, 200, 199.99}, - }, - { - name: "tolerance expires in the middle", - given: []float64{200, 199.99, 200, 199.99, 200, 199.99}, - tolerance: 0.0001, - until: now.Add(3 * time.Minute), - want: []float64{200, 200, 200, 199.99, 200, 199.99}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - testReaderIteratorDecodingDecreaseTolerance(t, now, tt.given, tt.want, tt.tolerance, tt.until) - }) - } -} - -func testReaderIteratorDecodingDecreaseTolerance( - t *testing.T, - now xtime.UnixNano, - input []float64, - expectedOutput []float64, - decreaseTolerance float64, - toleranceUntil xtime.UnixNano, -) { - ctx := context.NewBackground() - defer ctx.Close() - - enc := NewEncoder(testStartTime, nil, true, nil) - for _, v := range input { - dp := ts.Datapoint{TimestampNanos: now, Value: v} - err := enc.Encode(dp, xtime.Second, nil) - require.NoError(t, err) - now = now.Add(time.Minute) - } - - stream, ok := enc.Stream(ctx) - require.True(t, ok) - - opts := encoding.NewOptions(). - SetValueDecreaseTolerance(decreaseTolerance). - SetValueDecreaseToleranceUntil(toleranceUntil) - dec := NewDecoder(true, opts) - it := dec.Decode(stream) - defer it.Close() - - for i, expected := range expectedOutput { - require.True(t, it.Next()) - dp, _, _ := it.Current() - assert.Equal(t, expected, dp.Value, "datapoint #%d", i) - } - require.NoError(t, it.Err()) -} diff --git a/src/dbnode/encoding/options.go b/src/dbnode/encoding/options.go index ad96828958..b286d2d568 100644 --- a/src/dbnode/encoding/options.go +++ b/src/dbnode/encoding/options.go @@ -53,9 +53,6 @@ type options struct { iStreamReaderSizeM3TSZ int iStreamReaderSizeProto int metrics Metrics - - valueDecreaseTolerance float64 - valueDecreaseToleranceUntil xtime.UnixNano } func newOptions() Options { @@ -194,19 +191,3 @@ func (o *options) SetMetrics(value Metrics) Options { func (o *options) Metrics() Metrics { return o.metrics } - -func (o *options) SetValueDecreaseTolerance(value float64) Options { - opts := *o - opts.valueDecreaseTolerance = value - return &opts -} - -func (o *options) SetValueDecreaseToleranceUntil(value xtime.UnixNano) Options { - opts := *o - opts.valueDecreaseToleranceUntil = value - return &opts -} - -func (o *options) ValueDecreaseTolerance() (float64, xtime.UnixNano) { - return o.valueDecreaseTolerance, o.valueDecreaseToleranceUntil -} diff --git a/src/dbnode/encoding/types.go b/src/dbnode/encoding/types.go index c851ea5902..af9c048fac 100644 --- a/src/dbnode/encoding/types.go +++ b/src/dbnode/encoding/types.go @@ -171,15 +171,6 @@ type Options interface { // Metrics returns the encoding metrics. Metrics() Metrics - - // SetValueDecreaseTolerance sets relative tolerance against decoded time series value decrease. - SetValueDecreaseTolerance(value float64) Options - - // SetValueDecreaseToleranceUntil sets the timestamp (exclusive) until which the tolerance applies. - SetValueDecreaseToleranceUntil(value xtime.UnixNano) Options - - // ValueDecreaseTolerance returns relative tolerance against decoded time series value decrease. - ValueDecreaseTolerance() (float64, xtime.UnixNano) } // Iterator is the generic interface for iterating over encoded data.