// CreateMeasurementIndexIfNotExists creates or retrieves an in memory index object for the measurement func (d *DatabaseIndex) CreateMeasurementIndexIfNotExists(name string) *Measurement { name = escape.UnescapeString(name) // See if the measurement exists using a read-lock d.mu.RLock() m := d.measurements[name] if m != nil { d.mu.RUnlock() return m } d.mu.RUnlock() // Doesn't exist, so lock the index to create it d.mu.Lock() defer d.mu.Unlock() // Make sure it was created in between the time we released our read-lock // and acquire the write lock m = d.measurements[name] if m == nil { m = NewMeasurement(name) d.measurements[name] = m d.statMap.Add(statDatabaseMeasurements, 1) } return m }
// CreateMeasurementIndexIfNotExists creates or retrieves an in memory index object for the measurement func (d *DatabaseIndex) CreateMeasurementIndexIfNotExists(name string) *Measurement { name = escape.UnescapeString(name) m := d.measurements[name] if m == nil { m = NewMeasurement(name, d) d.measurements[name] = m } return m }
// MeasurementFromSeriesKey returns the name of the measurement from a key that // contains a measurement name. func MeasurementFromSeriesKey(key string) string { // Ignoring the error because the func returns "missing fields" k, _, _ := models.ParseKey(key) return escape.UnescapeString(k) }