Don't panic when checking for field

pull/9551/head
Edd Robinson 2018-03-12 15:25:20 +00:00
parent ac0c0756bf
commit c1e1412dae
5 changed files with 23 additions and 6 deletions

View File

@ -2634,7 +2634,7 @@ func (e *Engine) buildCursor(ctx context.Context, measurement, seriesKey string,
}
// Look up fields for measurement.
mf := e.fieldset.Fields(measurement)
mf := e.fieldset.FieldsByString(measurement)
if mf == nil {
return nil
}

View File

@ -12,7 +12,7 @@ import (
func (e *Engine) CreateCursor(ctx context.Context, r *tsdb.CursorRequest) (tsdb.Cursor, error) {
// Look up fields for measurement.
mf := e.fieldset.Fields(r.Measurement)
mf := e.fieldset.FieldsByString(r.Measurement)
if mf == nil {
return nil, nil
}

View File

@ -1405,6 +1405,9 @@ func (m *MeasurementFields) Field(name string) *Field {
}
func (m *MeasurementFields) HasField(name string) bool {
if m == nil {
return false
}
m.mu.RLock()
f := m.fields[name]
m.mu.RUnlock()
@ -1480,7 +1483,15 @@ func NewMeasurementFieldSet(path string) (*MeasurementFieldSet, error) {
}
// Fields returns fields for a measurement by name.
func (fs *MeasurementFieldSet) Fields(name string) *MeasurementFields {
func (fs *MeasurementFieldSet) Fields(name []byte) *MeasurementFields {
fs.mu.RLock()
mf := fs.fields[string(name)]
fs.mu.RUnlock()
return mf
}
// FieldsByString returns fields for a measurment by name.
func (fs *MeasurementFieldSet) FieldsByString(name string) *MeasurementFields {
fs.mu.RLock()
mf := fs.fields[name]
fs.mu.RUnlock()

View File

@ -1548,7 +1548,7 @@ func TestMeasurementFieldSet_SaveLoad(t *testing.T) {
t.Fatalf("NewMeasurementFieldSet error: %v", err)
}
fields = mf.Fields("cpu")
fields = mf.FieldsByString("cpu")
field := fields.Field("value")
if field == nil {
t.Fatalf("field is null")
@ -1593,7 +1593,7 @@ func TestMeasurementFieldSet_Corrupt(t *testing.T) {
t.Fatal("NewMeasurementFieldSet expected error")
}
fields = mf.Fields("cpu")
fields = mf.FieldsByString("cpu")
if fields != nil {
t.Fatal("expecte fields to be nil")
}
@ -1622,7 +1622,7 @@ func TestMeasurementFieldSet_DeleteEmpty(t *testing.T) {
t.Fatalf("NewMeasurementFieldSet error: %v", err)
}
fields = mf.Fields("cpu")
fields = mf.FieldsByString("cpu")
field := fields.Field("value")
if field == nil {
t.Fatalf("field is null")

View File

@ -1138,18 +1138,24 @@ func TestStore_TagValues(t *testing.T) {
Name: "No WHERE clause",
Expr: &base,
Exp: []tsdb.TagValues{
createTagValues("cpu0", map[string][]string{"shard": {"s0"}}),
createTagValues("cpu1", map[string][]string{"shard": {"s1"}}),
createTagValues("cpu10", map[string][]string{"host": {"nofoo", "tv0", "tv1", "tv2", "tv3"}, "shard": {"s0", "s1", "s2"}}),
createTagValues("cpu11", map[string][]string{"host": {"nofoo", "tv0", "tv1", "tv2", "tv3"}, "shard": {"s0", "s1", "s2"}}),
createTagValues("cpu12", map[string][]string{"host": {"nofoo", "tv0", "tv1", "tv2", "tv3"}, "shard": {"s0", "s1", "s2"}}),
createTagValues("cpu2", map[string][]string{"shard": {"s2"}}),
},
},
{
Name: "With WHERE clause",
Expr: baseWhere,
Exp: []tsdb.TagValues{
createTagValues("cpu0", map[string][]string{"shard": {"s0"}}),
createTagValues("cpu1", map[string][]string{"shard": {"s1"}}),
createTagValues("cpu10", map[string][]string{"host": {"tv0", "tv1", "tv2", "tv3"}, "shard": {"s0", "s1", "s2"}}),
createTagValues("cpu11", map[string][]string{"host": {"tv0", "tv1", "tv2", "tv3"}, "shard": {"s0", "s1", "s2"}}),
createTagValues("cpu12", map[string][]string{"host": {"tv0", "tv1", "tv2", "tv3"}, "shard": {"s0", "s1", "s2"}}),
createTagValues("cpu2", map[string][]string{"shard": {"s2"}}),
},
},
}