Skip to content

Commit

Permalink
fix(storage): check engine closed before collecting index metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Marble committed Jan 23, 2020
1 parent ee85eec commit 3830102
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions storage/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Engine struct {
nodeID *int // Not used by default.

mu sync.RWMutex
closing chan struct{} //closing returns the zero value when the engine is shutting down.
closing chan struct{} // closing returns the zero value when the engine is shutting down.
index *tsi1.Index
sfile *tsdb.SeriesFile
engine *tsm1.Engine
Expand Down Expand Up @@ -703,7 +703,7 @@ func (e *Engine) CreateBackup(ctx context.Context) (int, []string, error) {
// FetchBackupFile writes a given backup file to the provided writer.
// After a successful write, the internal copy is removed.
func (e *Engine) FetchBackupFile(ctx context.Context, backupID int, backupFile string, w io.Writer) error {
span, _ := tracing.StartSpanFromContext(ctx)
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()

e.mu.RLock()
Expand Down Expand Up @@ -762,6 +762,11 @@ func (e *Engine) fetchBackup(ctx context.Context, backupID int, backupFile strin
// InternalBackupPath provides the internal, full path directory name of the backup.
// This should not be exposed via API.
func (e *Engine) InternalBackupPath(backupID int) string {
e.mu.RLock()
defer e.mu.RUnlock()
if e.closing == nil {
return ""
}
return e.engine.FileStore.InternalBackupPath(backupID)
}

Expand Down Expand Up @@ -793,10 +798,20 @@ func (e *Engine) ApplyFnToSeriesIDSet(fn func(*tsdb.SeriesIDSet)) {

// MeasurementCardinalityStats returns cardinality stats for all measurements.
func (e *Engine) MeasurementCardinalityStats() (tsi1.MeasurementCardinalityStats, error) {
e.mu.RLock()
defer e.mu.RUnlock()
if e.closing == nil {
return nil, ErrEngineClosed
}
return e.index.MeasurementCardinalityStats()
}

// MeasurementStats returns the current measurement stats for the engine.
func (e *Engine) MeasurementStats() (tsm1.MeasurementStats, error) {
e.mu.RLock()
defer e.mu.RUnlock()
if e.closing == nil {
return nil, ErrEngineClosed
}
return e.engine.MeasurementStats()
}

0 comments on commit 3830102

Please sign in to comment.