Reload series count stat at startup

pull/6665/head
Jason Wilder 2016-05-18 15:21:57 -06:00
parent bac08b7661
commit f1ab89561a
2 changed files with 18 additions and 0 deletions

View File

@ -105,6 +105,19 @@ func (d *DatabaseIndex) MeasurementSeriesCounts() (nMeasurements int, nSeries in
return
}
// SeriesShardN returns the series count for a shard.
func (d *DatabaseIndex) SeriesShardN(shardID uint64) int {
var n int
d.mu.RLock()
for _, s := range d.series {
if s.Assigned(shardID) {
n++
}
}
d.mu.RUnlock()
return n
}
// CreateSeriesIndexIfNotExists adds the series for the given measurement to the index and sets its ID or returns the existing series object
func (d *DatabaseIndex) CreateSeriesIndexIfNotExists(measurementName string, series *Series) *Series {
d.mu.RLock()
@ -192,6 +205,7 @@ func (d *DatabaseIndex) UnassignShard(k string, shardID uint64) {
if !ss.measurement.HasSeries() {
d.mu.Lock()
d.dropMeasurement(ss.measurement.Name)
d.statMap.Add(statDatabaseMeasurements, int64(-1))
d.mu.Unlock()
}

View File

@ -171,6 +171,10 @@ func (s *Shard) Open() error {
if err := s.engine.LoadMetadataIndex(s.id, s.index); err != nil {
return err
}
count := s.index.SeriesShardN(s.id)
s.statMap.Add(statSeriesCreate, int64(count))
s.logger.Printf("%s database index loaded in %s", s.path, time.Now().Sub(start))
return nil