From d0b81c1e6c4dccd350d525b6d60e53d90feb0939 Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Wed, 27 Sep 2017 17:44:00 +0100 Subject: [PATCH] Fix race on Cache entry --- tsdb/engine/tsm1/cache.go | 8 ++++++++ tsdb/engine/tsm1/engine.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tsdb/engine/tsm1/cache.go b/tsdb/engine/tsm1/cache.go index 7f3b155c87..66f4743906 100644 --- a/tsdb/engine/tsm1/cache.go +++ b/tsdb/engine/tsm1/cache.go @@ -8,6 +8,7 @@ import ( "sync/atomic" "time" + "github.com/influxdata/influxdb/influxql" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/tsdb" "github.com/uber-go/zap" @@ -147,6 +148,13 @@ func (e *entry) size() int { return sz } +// InfluxQLType returns for the entry the data type of its values. +func (e *entry) InfluxQLType() (influxql.DataType, error) { + e.mu.RLock() + defer e.mu.RUnlock() + return e.values.InfluxQLType() +} + // Statistics gathered by the Cache. const ( // levels - point in time measures diff --git a/tsdb/engine/tsm1/engine.go b/tsdb/engine/tsm1/engine.go index 23f9a0ce73..b6ddbcef0b 100644 --- a/tsdb/engine/tsm1/engine.go +++ b/tsdb/engine/tsm1/engine.go @@ -1331,7 +1331,7 @@ func (e *Engine) onFileStoreReplace(newFiles []TSMFile) { // load metadata from the Cache e.Cache.ApplyEntryFn(func(key []byte, entry *entry) error { - fieldType, err := entry.values.InfluxQLType() + fieldType, err := entry.InfluxQLType() if err != nil { e.logger.Error(fmt.Sprintf("refresh index (3): %v", err)) return nil