From 1bcb1d033f09814bee3b06eaf760b3340628d0af Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Tue, 2 Feb 2016 19:16:30 +0000 Subject: [PATCH] Allow Close to be called multiple times safely --- CHANGELOG.md | 2 +- tsdb/engine/tsm1/engine.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 347b872659..6d0d2126e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ - [#5478](https://github.com/influxdata/influxdb/issues/5478): panic: interface conversion: interface is float64, not int64 - [#5475](https://github.com/influxdata/influxdb/issues/5475): Ensure appropriate exit code returned for non-interactive use of CLI. - [#5479](https://github.com/influxdata/influxdb/issues/5479): Bringing up a node as a meta only node causes panic -- [#5504](https://github.com/influxdata/influxdb/issues/5475): create retention policy on unexistant DB crash InfluxDB +- [#5504](https://github.com/influxdata/influxdb/issues/5504): create retention policy on unexistant DB crash InfluxDB - [#5505](https://github.com/influxdata/influxdb/issues/5505): Clear authCache in meta.Client when password changes. - [#5244](https://github.com/influxdata/influxdb/issues/5244): panic: ensure it's safe to close engine multiple times. diff --git a/tsdb/engine/tsm1/engine.go b/tsdb/engine/tsm1/engine.go index 77d0c1a62e..3e174a2a07 100644 --- a/tsdb/engine/tsm1/engine.go +++ b/tsdb/engine/tsm1/engine.go @@ -141,8 +141,15 @@ func (e *Engine) Open() error { return nil } -// Close closes the engine. +// Close closes the engine. Subsequent calls to Close are a nop. func (e *Engine) Close() error { + e.mu.RLock() + if e.done == nil { + e.mu.RUnlock() + return nil + } + e.mu.RUnlock() + // Shutdown goroutines and wait. close(e.done) e.wg.Wait() @@ -150,6 +157,7 @@ func (e *Engine) Close() error { // Lock now and close everything else down. e.mu.Lock() defer e.mu.Unlock() + e.done = nil // Ensures that the channel will not be closed again. if err := e.FileStore.Close(); err != nil { return err