From 00b2454c53b1b9dc0f6a4645e2616192d3c3633b Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 27 Oct 2015 11:57:21 -0700 Subject: [PATCH] Exit if invalid engine is selected Fix #4584, related to #4583 --- CHANGELOG.md | 1 + cmd/influxd/run/config.go | 8 ++++---- tsdb/config.go | 23 +++++++++++++++++++++++ tsdb/engine.go | 10 ++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4961c0ef055..5d0d266b7d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - [#4124](https://github.com/influxdb/influxdb/issues/4124): Missing defer/recover/panic idiom in HTTPD service - [#4238](https://github.com/influxdb/influxdb/pull/4238): Fully disable hinted-handoff service if so requested. - [#4165](https://github.com/influxdb/influxdb/pull/4165): Tag all Go runtime stats when writing to internal database. +- [#4586](https://github.com/influxdb/influxdb/pull/4586): Exit when invalid engine is selected - [#4118](https://github.com/influxdb/influxdb/issues/4118): Return consistent, correct result for SHOW MEASUREMENTS with multiple AND conditions - [#4191](https://github.com/influxdb/influxdb/pull/4191): Correctly marshal remote mapper responses. Fixes [#4170](https://github.com/influxdb/influxdb/issues/4170) - [#4222](https://github.com/influxdb/influxdb/pull/4222): Graphite TCP connections should not block shutdown diff --git a/cmd/influxd/run/config.go b/cmd/influxd/run/config.go index 39558be6d11..2a3d4e66e34 100644 --- a/cmd/influxd/run/config.go +++ b/cmd/influxd/run/config.go @@ -108,12 +108,12 @@ func NewDemoConfig() (*Config, error) { func (c *Config) Validate() error { if c.Meta.Dir == "" { return errors.New("Meta.Dir must be specified") - } else if c.Data.Dir == "" { - return errors.New("Data.Dir must be specified") } else if c.HintedHandoff.Dir == "" { return errors.New("HintedHandoff.Dir must be specified") - } else if c.Data.WALDir == "" { - return errors.New("Data.WALDir must be specified") + } + + if err := c.Data.Validate(); err != nil { + return err } for _, g := range c.Graphites { diff --git a/tsdb/config.go b/tsdb/config.go index c7c7441de29..df3141842f4 100644 --- a/tsdb/config.go +++ b/tsdb/config.go @@ -1,6 +1,8 @@ package tsdb import ( + "errors" + "fmt" "log" "os" "time" @@ -128,3 +130,24 @@ func NewConfig() Config { QueryLogEnabled: true, } } + +func (c *Config) Validate() error { + if c.Dir == "" { + return errors.New("Data.Dir must be specified") + } else if c.WALDir == "" { + return errors.New("Data.WALDir must be specified") + } + + valid := false + for _, e := range RegisteredEngines() { + if e == c.Engine { + valid = true + break + } + } + if !valid { + return fmt.Errorf("unrecognized engine %s", c.Engine) + } + + return nil +} diff --git a/tsdb/engine.go b/tsdb/engine.go index fb1b2108c5c..946079028b1 100644 --- a/tsdb/engine.go +++ b/tsdb/engine.go @@ -63,6 +63,16 @@ func RegisterEngine(name string, fn NewEngineFunc) { newEngineFuncs[name] = fn } +// RegisteredEngines returns the slice of currently registered engines. +func RegisteredEngines() []string { + a := make([]string, 0, len(newEngineFuncs)) + for k, _ := range newEngineFuncs { + a = append(a, k) + } + sort.Strings(a) + return a +} + // NewEngine returns an instance of an engine based on its format. // If the path does not exist then the DefaultFormat is used. func NewEngine(path string, walPath string, options EngineOptions) (Engine, error) {