From eb4a8d4f4ae38106ae26eb9c73054916dbc24955 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 28 Aug 2015 12:59:38 -0600 Subject: [PATCH 1/3] Fix panic when logging error in WAL If LoadMetadataIndex() tries to log an error, it causes a panic because the logger is not set until Open() is called, which is after LoadMetaDataIndex() returns. Instead, just set the logger up when the WAL is created. --- tsdb/engine/wal/wal.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tsdb/engine/wal/wal.go b/tsdb/engine/wal/wal.go index e6fa4b8c32..f6f5b3f97e 100644 --- a/tsdb/engine/wal/wal.go +++ b/tsdb/engine/wal/wal.go @@ -177,12 +177,12 @@ func NewLog(path string) *Log { ReadySeriesSize: tsdb.DefaultReadySeriesSize, partitionCount: PartitionCount, flushCheckInterval: defaultFlushCheckInterval, + logger: log.New(os.Stderr, "[wal] ", log.LstdFlags), } } // Open opens and initializes the Log. Will recover from previous unclosed shutdowns func (l *Log) Open() error { - l.logger = log.New(l.LogOutput, "[wal] ", log.LstdFlags) if l.EnableLogging { l.logger.Printf("WAL starting with %d ready series size, %0.2f compaction threshold, and %d partition size threshold\n", l.ReadySeriesSize, l.CompactionThreshold, l.PartitionSizeThreshold) @@ -375,7 +375,7 @@ func (l *Log) readMetadataFile(fileName string) ([]*seriesAndFields, error) { break } else if err != nil { // print the error and move on since we can't recover the file - l.logger.Println("error reading lenght of metadata:", err.Error()) + l.logger.Println("error reading length of metadata:", err.Error()) break } From f5f8f0411621a2f01cac7a8a98d81e6930413157 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 28 Aug 2015 13:01:17 -0600 Subject: [PATCH 2/3] Fix panic in addToCache addToCache is called in a goroutine and can panic if the server is closed while opening. If part of the open func errors, it returns an error and immediately calls close. close sets p.cache to nil which causes the goroutine trying to initialized the cache to panic as well. The goroutine should run under a write lock to avoid this race/panic. --- tsdb/engine/wal/wal.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tsdb/engine/wal/wal.go b/tsdb/engine/wal/wal.go index f6f5b3f97e..1ba017354b 100644 --- a/tsdb/engine/wal/wal.go +++ b/tsdb/engine/wal/wal.go @@ -500,6 +500,9 @@ func (l *Log) openPartitionFiles() error { for _, p := range l.partitions { go func(p *Partition) { + p.mu.Lock() + defer p.mu.Unlock() + // Recover from a partial compaction. if err := p.recoverCompactionFile(); err != nil { results <- fmt.Errorf("recover compaction files: %s", err) From 87f0e15560d9f4bbf999a003406d3639b0606382 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 28 Aug 2015 13:41:37 -0600 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abbdcd0275..c5879d71fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ With this release InfluxDB is moving to Go 1.5. - [#3823](https://github.com/influxdb/influxdb/pull/3823): Deterministic ordering for first() and last() - [#3869](https://github.com/influxdb/influxdb/issues/3869): Seemingly deadlocked when ingesting metrics via graphite plugin - [#3856](https://github.com/influxdb/influxdb/pull/3856): Minor changes to retention enforcement. +- [#3884](https://github.com/influxdb/influxdb/pull/3884): Fix two panics in WAL that can happen at server startup ## v0.9.3 [2015-08-26]