From a56e0226e61bbcfca88b1e0012e27463d10c0fe4 Mon Sep 17 00:00:00 2001 From: Jacob Marble Date: Thu, 23 Jan 2020 15:27:25 -0800 Subject: [PATCH] fix(storage): check engine closed before collecting index metrics (#16656) --- CHANGELOG.md | 3 +++ storage/engine.go | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6791d0cfbb6..81035821554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ 1. [16504](https://github.com/influxdata/influxdb/pull/16504): Add backup and restore 1. [16522](https://github.com/influxdata/influxdb/pull/16522): Introduce resource logger to tasks, buckets and organizations +### Bug Fixes +1. [16656](https://github.com/influxdata/influxdb/pull/16656): Check engine closed before collecting index metrics + ### UI Improvements 1. [16575](https://github.com/influxdata/influxdb/pull/16575): Swap billingURL with checkoutURL diff --git a/storage/engine.go b/storage/engine.go index 32150c9570f..4ec0660944c 100644 --- a/storage/engine.go +++ b/storage/engine.go @@ -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 @@ -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() @@ -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) } @@ -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() }