Fix tsdb/index/inmem benchmark tests

pull/9778/head
Jacob Marble 2018-04-23 14:18:08 -07:00
parent 1816de09c1
commit 1c63c4a3da
1 changed files with 56 additions and 8 deletions

View File

@ -2,6 +2,8 @@ package inmem_test
import (
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/influxdata/influxdb/models"
@ -21,9 +23,11 @@ func createData(lo, hi int) (keys, names [][]byte, tags []models.Tags) {
}
func BenchmarkShardIndex_CreateSeriesListIfNotExists_MaxValuesExceeded(b *testing.B) {
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", nil)}
sfile := mustOpenSeriesFile()
defer sfile.Close()
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", sfile.SeriesFile)}
opt.Config.MaxValuesPerTag = 10
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), nil, opt)
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), sfile.SeriesFile, opt)
si.Open()
keys, names, tags := createData(0, 10)
si.CreateSeriesListIfNotExists(keys, names, tags)
@ -37,9 +41,11 @@ func BenchmarkShardIndex_CreateSeriesListIfNotExists_MaxValuesExceeded(b *testin
}
func BenchmarkShardIndex_CreateSeriesListIfNotExists_MaxValuesNotExceeded(b *testing.B) {
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", nil)}
sfile := mustOpenSeriesFile()
defer sfile.Close()
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", sfile.SeriesFile)}
opt.Config.MaxValuesPerTag = 100000
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), nil, opt)
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), sfile.SeriesFile, opt)
si.Open()
keys, names, tags := createData(0, 10)
si.CreateSeriesListIfNotExists(keys, names, tags)
@ -53,8 +59,10 @@ func BenchmarkShardIndex_CreateSeriesListIfNotExists_MaxValuesNotExceeded(b *tes
}
func BenchmarkShardIndex_CreateSeriesListIfNotExists_NoMaxValues(b *testing.B) {
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", nil)}
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), nil, opt)
sfile := mustOpenSeriesFile()
defer sfile.Close()
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", sfile.SeriesFile)}
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), sfile.SeriesFile, opt)
si.Open()
keys, names, tags := createData(0, 10)
si.CreateSeriesListIfNotExists(keys, names, tags)
@ -68,10 +76,12 @@ func BenchmarkShardIndex_CreateSeriesListIfNotExists_NoMaxValues(b *testing.B) {
}
func BenchmarkShardIndex_CreateSeriesListIfNotExists_MaxSeriesExceeded(b *testing.B) {
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", nil)}
sfile := mustOpenSeriesFile()
defer sfile.Close()
opt := tsdb.EngineOptions{InmemIndex: inmem.NewIndex("foo", sfile.SeriesFile)}
opt.Config.MaxValuesPerTag = 0
opt.Config.MaxSeriesPerDatabase = 10
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), nil, opt)
si := inmem.NewShardIndex(1, "foo", "bar", tsdb.NewSeriesIDSet(), sfile.SeriesFile, opt)
si.Open()
keys, names, tags := createData(0, 10)
si.CreateSeriesListIfNotExists(keys, names, tags)
@ -83,3 +93,41 @@ func BenchmarkShardIndex_CreateSeriesListIfNotExists_MaxSeriesExceeded(b *testin
si.CreateSeriesListIfNotExists(keys, names, tags)
}
}
// seriesFileWrapper is a test wrapper for tsdb.seriesFileWrapper.
type seriesFileWrapper struct {
*tsdb.SeriesFile
}
// newSeriesFileWrapper returns a new instance of seriesFileWrapper with a temporary file path.
func newSeriesFileWrapper() *seriesFileWrapper {
dir, err := ioutil.TempDir("", "tsdb-series-file-")
if err != nil {
panic(err)
}
return &seriesFileWrapper{SeriesFile: tsdb.NewSeriesFile(dir)}
}
// mustOpenSeriesFile returns a new, open instance of seriesFileWrapper. Panic on error.
func mustOpenSeriesFile() *seriesFileWrapper {
f := newSeriesFileWrapper()
if err := f.Open(); err != nil {
panic(err)
}
return f
}
// Close closes the log file and removes it from disk.
func (f *seriesFileWrapper) Close() error {
defer os.RemoveAll(f.Path())
return f.SeriesFile.Close()
}
// reopen initialises a new series file using the existing one.
func (f *seriesFileWrapper) reopen() error {
if err := f.SeriesFile.Close(); err != nil {
return err
}
f.SeriesFile = tsdb.NewSeriesFile(f.SeriesFile.Path())
return nil
}