Inline mutex into TagValueSeriesIDCache.

pull/10234/head
Ben Johnson 2018-08-16 09:38:23 -06:00 committed by Edd Robinson
parent e4f8637234
commit fcbc03240a
2 changed files with 10 additions and 10 deletions

View File

@ -21,7 +21,7 @@ import (
// order by which items should be evicted from the cache, and a hashmap implementation
// to provide constant time retrievals of items from the cache.
type TagValueSeriesIDCache struct {
mu sync.RWMutex
sync.RWMutex
cache map[string]map[string]map[string]*list.Element
evictor *list.List
@ -40,8 +40,8 @@ func NewTagValueSeriesIDCache(c int) *TagValueSeriesIDCache {
// Get returns the SeriesIDSet associated with the {name, key, value} tuple if it
// exists.
func (c *TagValueSeriesIDCache) Get(name, key, value []byte) *tsdb.SeriesIDSet {
c.mu.Lock()
defer c.mu.Unlock()
c.Lock()
defer c.Unlock()
return c.get(name, key, value)
}
@ -97,13 +97,13 @@ func (c *TagValueSeriesIDCache) measurementContainsSets(name []byte) bool {
// Put adds the SeriesIDSet to the cache under the tuple {name, key, value}. If
// the cache is at its limit, then the least recently used item is evicted.
func (c *TagValueSeriesIDCache) Put(name, key, value []byte, ss *tsdb.SeriesIDSet) {
c.mu.Lock()
c.Lock()
// Check under the write lock if the relevant item is now in the cache.
if c.exists(name, key, value) {
c.mu.Unlock()
c.Unlock()
return
}
defer c.mu.Unlock()
defer c.Unlock()
// Create list item, and add to the front of the eviction list.
listElement := c.evictor.PushFront(&seriesIDCacheElement{

View File

@ -680,7 +680,7 @@ func (i *Index) CreateSeriesListIfNotExists(keys [][]byte, names [][]byte, tagsS
}
// Some cached bitset results may need to be updated.
i.tagValueCache.mu.RLock()
i.tagValueCache.RLock()
for j, id := range ids {
if id == 0 {
continue
@ -708,7 +708,7 @@ func (i *Index) CreateSeriesListIfNotExists(keys [][]byte, names [][]byte, tagsS
}
}
}
i.tagValueCache.mu.RUnlock()
i.tagValueCache.RUnlock()
errC <- err
}
@ -748,7 +748,7 @@ func (i *Index) CreateSeriesIfNotExists(key, name []byte, tags models.Tags) erro
// If there are cached sets for any of the tag pairs, they will need to be
// updated with the series id.
i.tagValueCache.mu.RLock()
i.tagValueCache.RLock()
if i.tagValueCache.measurementContainsSets(name) {
for _, pair := range tags {
// TODO(edd): It's not clear to me yet whether it will be better to take a lock
@ -765,7 +765,7 @@ func (i *Index) CreateSeriesIfNotExists(key, name []byte, tags models.Tags) erro
i.tagValueCache.addToSet(name, pair.Key, pair.Value, ids[0]) // Takes a lock on the series id set
}
}
i.tagValueCache.mu.RUnlock()
i.tagValueCache.RUnlock()
return nil
}