Reduce lock content in AssignShard

The lock shows up under write load.  It only needs to be assigned
once so a read lock eliminates the contention.
pull/8302/head
Jason Wilder 2017-04-13 23:21:04 -06:00
parent eeaad877bc
commit 883b3dcbbb
1 changed files with 10 additions and 0 deletions

View File

@ -1121,7 +1121,17 @@ func NewSeries(key []byte, tags models.Tags) *Series {
}
func (s *Series) AssignShard(shardID uint64) {
s.mu.RLock()
_, ok := s.shardIDs[shardID]
s.mu.RUnlock()
if ok {
return
}
s.mu.Lock()
// Skip the existence check under the write lock because we're just storing
// and empty struct.
s.shardIDs[shardID] = struct{}{}
s.mu.Unlock()
}