From 32e195860b06585c42a516734c16f33c048c5416 Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Wed, 25 Apr 2018 13:02:09 +0100 Subject: [PATCH 1/2] Log index type when opening shard --- tsdb/shard.go | 9 ++++++--- tsdb/store.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tsdb/shard.go b/tsdb/shard.go index 99369506d1..689a6e7dc6 100644 --- a/tsdb/shard.go +++ b/tsdb/shard.go @@ -366,18 +366,21 @@ func (s *Shard) close() error { return err } +// IndexType returns the index version being used for this shard. +// +// IndexType returns the empty string if it is called before the shard is opened, +// since it is only that point that the underlying index type is known. func (s *Shard) IndexType() string { s.mu.RLock() defer s.mu.RUnlock() - if err := s.ready(); err != nil { + if s._engine == nil || s.index == nil { // Shard not open yet. return "" } - return s.index.Type() } // ready determines if the Shard is ready for queries or writes. -// It returns nil if ready, otherwise ErrShardClosed or ErrShardDiabled +// It returns nil if ready, otherwise ErrShardClosed or ErrShardDisabled func (s *Shard) ready() error { var err error if s._engine == nil { diff --git a/tsdb/store.go b/tsdb/store.go index aecfa18e9e..948e940e22 100644 --- a/tsdb/store.go +++ b/tsdb/store.go @@ -322,7 +322,7 @@ func (s *Store) loadShards() error { } resC <- &res{s: shard} - log.Info("Opened shard", zap.String("path", path), zap.Duration("duration", time.Since(start))) + log.Info("Opened shard", zap.String("index_version", shard.IndexType()), zap.String("path", path), zap.Duration("duration", time.Since(start))) }(db.Name(), rp.Name(), sh.Name()) } } From 0b4a403679ddeaf79855614d7f74580fbbbd3644 Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Wed, 25 Apr 2018 13:47:41 +0100 Subject: [PATCH 2/2] Provide warning when mixed index used on db --- tsdb/store.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tsdb/store.go b/tsdb/store.go index 948e940e22..57de371608 100644 --- a/tsdb/store.go +++ b/tsdb/store.go @@ -23,6 +23,7 @@ import ( "github.com/influxdata/influxdb/query" "github.com/influxdata/influxql" "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) var ( @@ -328,6 +329,10 @@ func (s *Store) loadShards() error { } } + // indexVersions tracks counts of the number of different types of index + // being used within each database. + indexVersions := make(map[string]map[string]int) + // Gather results of opening shards concurrently, keeping track of how // many databases we are managing. for i := 0; i < n; i++ { @@ -337,9 +342,25 @@ func (s *Store) loadShards() error { } s.shards[res.s.id] = res.s s.databases[res.s.database] = struct{}{} + + if _, ok := indexVersions[res.s.database]; !ok { + indexVersions[res.s.database] = make(map[string]int, 2) + } + indexVersions[res.s.database][res.s.IndexType()]++ } close(resC) + // Check if any databases are running multiple index types. + for db, idxVersions := range indexVersions { + if len(idxVersions) > 1 { + var fields []zapcore.Field + for idx, cnt := range idxVersions { + fields = append(fields, zap.Int(fmt.Sprintf("%s_count", idx), cnt)) + } + s.Logger.Warn("Mixed shard index types", append(fields, logger.Database(db))...) + } + } + // Enable all shards for _, sh := range s.shards { sh.SetEnabled(true)