Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[query] Optional value decrease tolerance in M3TSZ decoder (#3876)" #3939

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions src/dbnode/encoding/encoding_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions src/dbnode/encoding/m3tsz/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
92 changes: 0 additions & 92 deletions src/dbnode/encoding/m3tsz/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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())
}
19 changes: 0 additions & 19 deletions src/dbnode/encoding/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ type options struct {
iStreamReaderSizeM3TSZ int
iStreamReaderSizeProto int
metrics Metrics

valueDecreaseTolerance float64
valueDecreaseToleranceUntil xtime.UnixNano
}

func newOptions() Options {
Expand Down Expand Up @@ -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
}
9 changes: 0 additions & 9 deletions src/dbnode/encoding/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down