diff --git a/cmd/influx_tsm/converter_test.go b/cmd/influx_tsm/converter_test.go index 31d0a41083..7ce8b1ea3b 100644 --- a/cmd/influx_tsm/converter_test.go +++ b/cmd/influx_tsm/converter_test.go @@ -1,46 +1,58 @@ package main import ( + "fmt" "math" "reflect" + "strings" "testing" "time" "github.com/influxdb/influxdb/tsdb/engine/tsm1" ) -func Test_scrubValuesNoFilter(t *testing.T) { - values := []tsm1.Value{tsm1.NewValue(time.Unix(0, 0), 1.0)} - scrubbed := scrubValues(values) - if !reflect.DeepEqual(values, scrubbed) { - t.Fatalf("mismatch:\n\nexp=%+v\n\ngot=%+v\n\n", values, scrubbed) +func TestScrubValues(t *testing.T) { + dummy := Converter{ + tracker: new(tracker), + } + + epoch := time.Unix(0, 0) + simple := []tsm1.Value{tsm1.NewValue(epoch, 1.0)} + + for _, tt := range []struct { + input, expected []tsm1.Value + }{ + { + input: simple, + expected: simple, + }, { + input: []tsm1.Value{simple[0], tsm1.NewValue(epoch, math.NaN())}, + expected: simple, + }, { + input: []tsm1.Value{simple[0], tsm1.NewValue(epoch, math.Inf(-1))}, + expected: simple, + }, { + input: []tsm1.Value{simple[0], tsm1.NewValue(epoch, math.Inf(1)), tsm1.NewValue(epoch, math.NaN())}, + expected: simple, + }, + } { + out := dummy.scrubValues(tt.input) + if !reflect.DeepEqual(out, tt.expected) { + t.Errorf("Failed to scrub '%s': Got '%s', Expected '%s'", pretty(tt.input), pretty(out), pretty(tt.expected)) + } } } -func Test_scrubValuesFilterNaN(t *testing.T) { - intV := tsm1.NewValue(time.Unix(0, 0), 1.0) - values := []tsm1.Value{intV, tsm1.NewValue(time.Unix(0, 0), math.NaN())} - scrubbed := scrubValues(values) - if !reflect.DeepEqual([]tsm1.Value{intV}, scrubbed) { - t.Fatalf("mismatch:\n\nexp=%+v\n\ngot=%+v\n\n", []tsm1.Value{intV}, scrubbed) +func pretty(vals []tsm1.Value) string { + if len(vals) == 0 { + return "[]" } -} -func Test_scrubValuesFilterInf(t *testing.T) { - intV := tsm1.NewValue(time.Unix(0, 0), 1.0) - values := []tsm1.Value{intV, tsm1.NewValue(time.Unix(0, 0), math.Inf(-1))} - scrubbed := scrubValues(values) - if !reflect.DeepEqual([]tsm1.Value{intV}, scrubbed) { - t.Fatalf("mismatch:\n\nexp=%+v\n\ngot=%+v\n\n", []tsm1.Value{intV}, scrubbed) - } -} + strs := make([]string, len(vals)) -func Test_scrubValuesFilterBoth(t *testing.T) { - intV := tsm1.NewValue(time.Unix(0, 0), 1.0) - values := []tsm1.Value{intV, tsm1.NewValue(time.Unix(0, 0), math.Inf(-1)), tsm1.NewValue(time.Unix(0, 0), math.NaN())} - scrubbed := scrubValues(values) - if !reflect.DeepEqual([]tsm1.Value{intV}, scrubbed) { - t.Fatalf("mismatch:\n\nexp=%+v\n\ngot=%+v\n\n", []tsm1.Value{intV}, scrubbed) + for i := range vals { + strs[i] = fmt.Sprintf("{%v: %v}", vals[i].UnixNano(), vals[i].Value()) } - return + + return "[" + strings.Join(strs, ", ") + "]" } diff --git a/cmd/influx_tsm/main.go b/cmd/influx_tsm/main.go index b43465a195..eca0fe5674 100644 --- a/cmd/influx_tsm/main.go +++ b/cmd/influx_tsm/main.go @@ -108,7 +108,7 @@ func (o *options) Parse() error { var opts options -const maxTSMSz = 2 * 1024 * 1024 * 1024 +const maxTSMSz uint64 = 2 * 1024 * 1024 * 1024 func init() { log.SetOutput(os.Stderr) @@ -240,7 +240,6 @@ func copyDir(dest, src string) error { return err } - // TODO(jlegasse): this just appends to the current backup file, if it exists out, err := os.OpenFile(toPath, os.O_CREATE|os.O_WRONLY, info.Mode()) if err != nil { return err diff --git a/cmd/influx_tsm/tracker.go b/cmd/influx_tsm/tracker.go index 6928eca4f0..3bfd0624cf 100644 --- a/cmd/influx_tsm/tracker.go +++ b/cmd/influx_tsm/tracker.go @@ -16,13 +16,13 @@ import ( // tracker will orchestrate and track the conversions of non-TSM shards to TSM type tracker struct { + stats Stats + shards tsdb.ShardInfos opts options pg ParallelGroup wg sync.WaitGroup - - stats Stats } type Stats struct {