Fix 32bit overflow; limit capacity
parent
33623c1fa9
commit
149b1cef1d
|
@ -2,7 +2,6 @@ package mmap_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ type HashMap struct {
|
||||||
|
|
||||||
func NewHashMap(opt Options) *HashMap {
|
func NewHashMap(opt Options) *HashMap {
|
||||||
m := &HashMap{
|
m := &HashMap{
|
||||||
capacity: pow2(opt.Capacity),
|
capacity: pow2(opt.Capacity), // Limited to 2^32.
|
||||||
loadFactor: opt.LoadFactor,
|
loadFactor: opt.LoadFactor,
|
||||||
}
|
}
|
||||||
m.alloc()
|
m.alloc()
|
||||||
|
|
|
@ -44,7 +44,7 @@ func TestEngine_LoadMetadataIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify index is correct.
|
// Verify index is correct.
|
||||||
m, err := index.Measurement("cpu")
|
m, err := index.Measurement([]byte("cpu"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if m == nil {
|
} else if m == nil {
|
||||||
|
@ -70,7 +70,7 @@ func TestEngine_LoadMetadataIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify index is correct.
|
// Verify index is correct.
|
||||||
if m, err = index.Measurement("cpu"); err != nil {
|
if m, err = index.Measurement([]byte("cpu")); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if m == nil {
|
} else if m == nil {
|
||||||
t.Fatal("measurement not found")
|
t.Fatal("measurement not found")
|
||||||
|
@ -97,7 +97,7 @@ func TestEngine_LoadMetadataIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify index is correct.
|
// Verify index is correct.
|
||||||
if m, err = index.Measurement("cpu"); err != nil {
|
if m, err = index.Measurement([]byte("cpu")); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if m == nil {
|
} else if m == nil {
|
||||||
t.Fatal("measurement not found")
|
t.Fatal("measurement not found")
|
||||||
|
@ -121,7 +121,7 @@ func TestEngine_DeleteWALLoadMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove series.
|
// Remove series.
|
||||||
if err := e.DeleteSeriesRange([]string{"cpu,host=A"}, math.MinInt64, math.MaxInt64); err != nil {
|
if err := e.DeleteSeriesRange([][]byte{[]byte("cpu,host=A")}, math.MinInt64, math.MaxInt64); err != nil {
|
||||||
t.Fatalf("failed to delete series: %s", err.Error())
|
t.Fatalf("failed to delete series: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ func TestEngine_CreateIterator_Cache_Ascending(t *testing.T) {
|
||||||
|
|
||||||
e.CreateMeasurement("cpu")
|
e.CreateMeasurement("cpu")
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
||||||
e.CreateSeries("cpu", tsdb.NewSeries("cpu,host=A", models.NewTags(map[string]string{"host": "A"})))
|
e.CreateSeries("cpu", tsdb.NewSeries([]byte("cpu,host=A"), models.NewTags(map[string]string{"host": "A"})))
|
||||||
if err := e.WritePointsString(
|
if err := e.WritePointsString(
|
||||||
`cpu,host=A value=1.1 1000000000`,
|
`cpu,host=A value=1.1 1000000000`,
|
||||||
`cpu,host=A value=1.2 2000000000`,
|
`cpu,host=A value=1.2 2000000000`,
|
||||||
|
@ -284,7 +284,7 @@ func TestEngine_CreateIterator_Cache_Descending(t *testing.T) {
|
||||||
|
|
||||||
e.CreateMeasurement("cpu")
|
e.CreateMeasurement("cpu")
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
||||||
e.CreateSeries("cpu", tsdb.NewSeries("cpu,host=A", models.NewTags(map[string]string{"host": "A"})))
|
e.CreateSeries("cpu", tsdb.NewSeries([]byte("cpu,host=A"), models.NewTags(map[string]string{"host": "A"})))
|
||||||
if err := e.WritePointsString(
|
if err := e.WritePointsString(
|
||||||
`cpu,host=A value=1.1 1000000000`,
|
`cpu,host=A value=1.1 1000000000`,
|
||||||
`cpu,host=A value=1.2 2000000000`,
|
`cpu,host=A value=1.2 2000000000`,
|
||||||
|
@ -337,7 +337,7 @@ func TestEngine_CreateIterator_TSM_Ascending(t *testing.T) {
|
||||||
|
|
||||||
e.CreateMeasurement("cpu")
|
e.CreateMeasurement("cpu")
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
||||||
e.CreateSeries("cpu", tsdb.NewSeries("cpu,host=A", models.NewTags(map[string]string{"host": "A"})))
|
e.CreateSeries("cpu", tsdb.NewSeries([]byte("cpu,host=A"), models.NewTags(map[string]string{"host": "A"})))
|
||||||
if err := e.WritePointsString(
|
if err := e.WritePointsString(
|
||||||
`cpu,host=A value=1.1 1000000000`,
|
`cpu,host=A value=1.1 1000000000`,
|
||||||
`cpu,host=A value=1.2 2000000000`,
|
`cpu,host=A value=1.2 2000000000`,
|
||||||
|
@ -391,7 +391,7 @@ func TestEngine_CreateIterator_TSM_Descending(t *testing.T) {
|
||||||
|
|
||||||
e.CreateMeasurement("cpu")
|
e.CreateMeasurement("cpu")
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
||||||
e.CreateSeries("cpu", tsdb.NewSeries("cpu,host=A", models.NewTags(map[string]string{"host": "A"})))
|
e.CreateSeries("cpu", tsdb.NewSeries([]byte("cpu,host=A"), models.NewTags(map[string]string{"host": "A"})))
|
||||||
if err := e.WritePointsString(
|
if err := e.WritePointsString(
|
||||||
`cpu,host=A value=1.1 1000000000`,
|
`cpu,host=A value=1.1 1000000000`,
|
||||||
`cpu,host=A value=1.2 2000000000`,
|
`cpu,host=A value=1.2 2000000000`,
|
||||||
|
@ -446,7 +446,7 @@ func TestEngine_CreateIterator_Aux(t *testing.T) {
|
||||||
e.CreateMeasurement("cpu")
|
e.CreateMeasurement("cpu")
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("F", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("F", influxql.Float, false)
|
||||||
e.CreateSeries("cpu", tsdb.NewSeries("cpu,host=A", models.NewTags(map[string]string{"host": "A"})))
|
e.CreateSeries("cpu", tsdb.NewSeries([]byte("cpu,host=A"), models.NewTags(map[string]string{"host": "A"})))
|
||||||
if err := e.WritePointsString(
|
if err := e.WritePointsString(
|
||||||
`cpu,host=A value=1.1 1000000000`,
|
`cpu,host=A value=1.1 1000000000`,
|
||||||
`cpu,host=A F=100 1000000000`,
|
`cpu,host=A F=100 1000000000`,
|
||||||
|
@ -507,7 +507,7 @@ func TestEngine_CreateIterator_Condition(t *testing.T) {
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("X", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("X", influxql.Float, false)
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("Y", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("Y", influxql.Float, false)
|
||||||
e.CreateSeries("cpu", tsdb.NewSeries("cpu,host=A", models.NewTags(map[string]string{"host": "A"})))
|
e.CreateSeries("cpu", tsdb.NewSeries([]byte("cpu,host=A"), models.NewTags(map[string]string{"host": "A"})))
|
||||||
if err := e.WritePointsString(
|
if err := e.WritePointsString(
|
||||||
`cpu,host=A value=1.1 1000000000`,
|
`cpu,host=A value=1.1 1000000000`,
|
||||||
`cpu,host=A X=10 1000000000`,
|
`cpu,host=A X=10 1000000000`,
|
||||||
|
@ -592,7 +592,7 @@ func TestEngine_DeleteSeries(t *testing.T) {
|
||||||
t.Fatalf("series count mismatch: exp %v, got %v", exp, got)
|
t.Fatalf("series count mismatch: exp %v, got %v", exp, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := e.DeleteSeriesRange([]string{"cpu,host=A"}, math.MinInt64, math.MaxInt64); err != nil {
|
if err := e.DeleteSeriesRange([][]byte{[]byte("cpu,host=A")}, math.MinInt64, math.MaxInt64); err != nil {
|
||||||
t.Fatalf("failed to delete series: %v", err)
|
t.Fatalf("failed to delete series: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -901,7 +901,7 @@ func MustInitBenchmarkEngine(pointN int) *Engine {
|
||||||
// Initialize metadata.
|
// Initialize metadata.
|
||||||
e.CreateMeasurement("cpu")
|
e.CreateMeasurement("cpu")
|
||||||
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
e.MeasurementFields("cpu").CreateFieldIfNotExists("value", influxql.Float, false)
|
||||||
e.CreateSeries("cpu", tsdb.NewSeries("cpu,host=A", models.NewTags(map[string]string{"host": "A"})))
|
e.CreateSeries("cpu", tsdb.NewSeries([]byte("cpu,host=A"), models.NewTags(map[string]string{"host": "A"})))
|
||||||
|
|
||||||
// Generate time ascending points with jitterred time & value.
|
// Generate time ascending points with jitterred time & value.
|
||||||
rand := rand.New(rand.NewSource(0))
|
rand := rand.New(rand.NewSource(0))
|
||||||
|
@ -1003,7 +1003,7 @@ func (e *Engine) MustWriteSnapshot() {
|
||||||
// MustMeasurement calls Measurement on the underlying tsdb.Engine, and panics
|
// MustMeasurement calls Measurement on the underlying tsdb.Engine, and panics
|
||||||
// if it returns an error.
|
// if it returns an error.
|
||||||
func (e *Engine) MustMeasurement(name string) *tsdb.Measurement {
|
func (e *Engine) MustMeasurement(name string) *tsdb.Measurement {
|
||||||
m, err := e.Engine.Measurement(name)
|
m, err := e.Engine.Measurement([]byte(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ func TestMeasurement_AppendSeriesKeysByID_Exists(t *testing.T) {
|
||||||
func BenchmarkMeasurement_SeriesIDForExp_EQRegex(b *testing.B) {
|
func BenchmarkMeasurement_SeriesIDForExp_EQRegex(b *testing.B) {
|
||||||
m := tsdb.NewMeasurement("cpu")
|
m := tsdb.NewMeasurement("cpu")
|
||||||
for i := 0; i < 100000; i++ {
|
for i := 0; i < 100000; i++ {
|
||||||
s := tsdb.NewSeries("cpu", models.Tags{models.Tag{
|
s := tsdb.NewSeries([]byte("cpu"), models.Tags{models.Tag{
|
||||||
Key: []byte("host"),
|
Key: []byte("host"),
|
||||||
Value: []byte(fmt.Sprintf("host%d", i))}})
|
Value: []byte(fmt.Sprintf("host%d", i))}})
|
||||||
s.ID = uint64(i)
|
s.ID = uint64(i)
|
||||||
|
@ -153,7 +153,7 @@ func BenchmarkMeasurement_SeriesIDForExp_EQRegex(b *testing.B) {
|
||||||
func BenchmarkMeasurement_SeriesIDForExp_NERegex(b *testing.B) {
|
func BenchmarkMeasurement_SeriesIDForExp_NERegex(b *testing.B) {
|
||||||
m := tsdb.NewMeasurement("cpu")
|
m := tsdb.NewMeasurement("cpu")
|
||||||
for i := 0; i < 100000; i++ {
|
for i := 0; i < 100000; i++ {
|
||||||
s := tsdb.NewSeries("cpu", models.Tags{models.Tag{
|
s := tsdb.NewSeries([]byte("cpu"), models.Tags{models.Tag{
|
||||||
Key: []byte("host"),
|
Key: []byte("host"),
|
||||||
Value: []byte(fmt.Sprintf("host%d", i))}})
|
Value: []byte(fmt.Sprintf("host%d", i))}})
|
||||||
s.ID = uint64(i)
|
s.ID = uint64(i)
|
||||||
|
@ -279,7 +279,7 @@ func genTestSeries(mCnt, tCnt, vCnt int) []*TestSeries {
|
||||||
for _, ts := range tagSets {
|
for _, ts := range tagSets {
|
||||||
series = append(series, &TestSeries{
|
series = append(series, &TestSeries{
|
||||||
Measurement: m,
|
Measurement: m,
|
||||||
Series: tsdb.NewSeries(fmt.Sprintf("%s:%s", m, string(tsdb.MarshalTags(ts))), models.NewTags(ts)),
|
Series: tsdb.NewSeries([]byte(fmt.Sprintf("%s:%s", m, string(tsdb.MarshalTags(ts)))), models.NewTags(ts)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,11 +74,11 @@ func TestShardWriteAndIndex(t *testing.T) {
|
||||||
t.Fatalf("got %v series, exp %v series in index", got, exp)
|
t.Fatalf("got %v series, exp %v series in index", got, exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
seriesTags := sh.Series(string(pt.Key())).Tags
|
seriesTags := sh.Series(pt.Key()).Tags
|
||||||
if len(seriesTags) != len(pt.Tags()) || pt.Tags().GetString("host") != seriesTags.GetString("host") {
|
if len(seriesTags) != len(pt.Tags()) || pt.Tags().GetString("host") != seriesTags.GetString("host") {
|
||||||
t.Fatalf("tags weren't properly saved to series index: %v, %v", pt.Tags(), seriesTags)
|
t.Fatalf("tags weren't properly saved to series index: %v, %v", pt.Tags(), seriesTags)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(sh.Measurement("cpu").TagKeys(), []string{"host"}) {
|
if !reflect.DeepEqual(sh.Measurement([]byte("cpu")).TagKeys(), []string{"host"}) {
|
||||||
t.Fatalf("tag key wasn't saved to measurement index")
|
t.Fatalf("tag key wasn't saved to measurement index")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ func TestWriteTimeTag(t *testing.T) {
|
||||||
t.Fatalf("unexpected log message: %s", strings.TrimSpace(got))
|
t.Fatalf("unexpected log message: %s", strings.TrimSpace(got))
|
||||||
}
|
}
|
||||||
|
|
||||||
m := sh.Measurement("cpu")
|
m := sh.Measurement([]byte("cpu"))
|
||||||
if m != nil {
|
if m != nil {
|
||||||
t.Fatal("unexpected cpu measurement")
|
t.Fatal("unexpected cpu measurement")
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ func TestWriteTimeTag(t *testing.T) {
|
||||||
t.Fatalf("unexpected log message: %s", strings.TrimSpace(got))
|
t.Fatalf("unexpected log message: %s", strings.TrimSpace(got))
|
||||||
}
|
}
|
||||||
|
|
||||||
m = sh.Measurement("cpu")
|
m = sh.Measurement([]byte("cpu"))
|
||||||
if m == nil {
|
if m == nil {
|
||||||
t.Fatal("expected cpu measurement")
|
t.Fatal("expected cpu measurement")
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ func TestWriteTimeField(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
key := models.MakeKey([]byte("cpu"), nil)
|
key := models.MakeKey([]byte("cpu"), nil)
|
||||||
series := sh.Series(string(key))
|
series := sh.Series(key)
|
||||||
if series == nil {
|
if series == nil {
|
||||||
t.Fatal("expected series")
|
t.Fatal("expected series")
|
||||||
} else if len(series.Tags) != 0 {
|
} else if len(series.Tags) != 0 {
|
||||||
|
@ -354,15 +354,15 @@ func TestShardWriteAddNewField(t *testing.T) {
|
||||||
t.Fatalf("got %d series, exp %d series in index", got, exp)
|
t.Fatalf("got %d series, exp %d series in index", got, exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
seriesTags := sh.Series(string(pt.Key())).Tags
|
seriesTags := sh.Series(pt.Key()).Tags
|
||||||
if len(seriesTags) != len(pt.Tags()) || pt.Tags().GetString("host") != seriesTags.GetString("host") {
|
if len(seriesTags) != len(pt.Tags()) || pt.Tags().GetString("host") != seriesTags.GetString("host") {
|
||||||
t.Fatalf("tags weren't properly saved to series index: %v, %v", pt.Tags(), seriesTags)
|
t.Fatalf("tags weren't properly saved to series index: %v, %v", pt.Tags(), seriesTags)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(sh.Measurement("cpu").TagKeys(), []string{"host"}) {
|
if !reflect.DeepEqual(sh.Measurement([]byte("cpu")).TagKeys(), []string{"host"}) {
|
||||||
t.Fatalf("tag key wasn't saved to measurement index")
|
t.Fatalf("tag key wasn't saved to measurement index")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sh.Measurement("cpu").FieldNames()) != 2 {
|
if len(sh.Measurement([]byte("cpu")).FieldNames()) != 2 {
|
||||||
t.Fatalf("field names wasn't saved to measurement index")
|
t.Fatalf("field names wasn't saved to measurement index")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue