Fix data race in *tsdb.Shard write path.

Ensure that the Shard's Index is read-locked before calculating the
count of its constituent series.
pull/7364/head
rw 2016-09-26 12:42:35 -07:00
parent 611e413791
commit bea010b5f3
1 changed files with 6 additions and 1 deletions

View File

@ -490,7 +490,12 @@ func (s *Shard) validateSeriesAndFields(points []models.Point) ([]*FieldCreate,
ss := s.index.SeriesBytes(p.Key())
if ss == nil {
key := string(p.Key())
if s.options.Config.MaxSeriesPerDatabase > 0 && len(s.index.series)+1 > s.options.Config.MaxSeriesPerDatabase {
s.index.mu.RLock()
indexSeriesLen := len(s.index.series)
s.index.mu.RUnlock()
if s.options.Config.MaxSeriesPerDatabase > 0 && indexSeriesLen+1 > s.options.Config.MaxSeriesPerDatabase {
return nil, fmt.Errorf("max series per database exceeded: %s", key)
}