Reduce index lock contention

Series and Measurment have their own locks and we do not need to
hold locks on the index while using those types.
pull/8302/head
Jason Wilder 2017-04-13 23:23:46 -06:00
parent 883b3dcbbb
commit a19ce9c10f
1 changed files with 5 additions and 5 deletions

View File

@ -136,12 +136,12 @@ func (i *Index) CreateSeriesIfNotExists(shardID uint64, key, name []byte, tags m
i.mu.RLock() i.mu.RLock()
// if there is a series for this id, it's already been added // if there is a series for this id, it's already been added
ss := i.series[string(key)] ss := i.series[string(key)]
i.mu.RUnlock()
if ss != nil { if ss != nil {
ss.AssignShard(shardID) ss.AssignShard(shardID)
i.mu.RUnlock()
return nil return nil
} }
i.mu.RUnlock()
// get or create the measurement index // get or create the measurement index
m := i.CreateMeasurementIndexIfNotExists(string(name)) m := i.CreateMeasurementIndexIfNotExists(string(name))
@ -150,8 +150,8 @@ func (i *Index) CreateSeriesIfNotExists(shardID uint64, key, name []byte, tags m
// Check for the series again under a write lock // Check for the series again under a write lock
ss = i.series[string(key)] ss = i.series[string(key)]
if ss != nil { if ss != nil {
ss.AssignShard(shardID)
i.mu.Unlock() i.mu.Unlock()
ss.AssignShard(shardID)
return nil return nil
} }
@ -228,9 +228,9 @@ func (i *Index) HasTagKey(name, key []byte) (bool, error) {
// HasTagValue returns true if tag value exists. // HasTagValue returns true if tag value exists.
func (i *Index) HasTagValue(name, key, value []byte) bool { func (i *Index) HasTagValue(name, key, value []byte) bool {
i.mu.RLock() i.mu.RLock()
defer i.mu.RUnlock()
mm := i.measurements[string(name)] mm := i.measurements[string(name)]
i.mu.RUnlock()
if mm == nil { if mm == nil {
return false return false
} }