From 65683bf166576a1e9fe40a7d32c71722a481aa59 Mon Sep 17 00:00:00 2001 From: Geoffrey Wossum Date: Tue, 12 Nov 2024 09:34:05 -0600 Subject: [PATCH] chore: fix logging issues in Store.loadShards (#25529) Fix reporting shards not opening correctly when they actually did. Fix race condition with logging in loadShards. --- tsdb/store.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tsdb/store.go b/tsdb/store.go index 82e72c52299..c5073b785be 100644 --- a/tsdb/store.go +++ b/tsdb/store.go @@ -567,14 +567,13 @@ func (s *Store) loadShards() error { loader := s.newShardLoader(sh.id, sh.db, sh.rp, false, withIndexVersion(indexVersion)) // Now perform the actual loading in parallel in separate goroutines. - go func() { + go func(log *zap.Logger) { t.Take() defer t.Release() - log := log.With(logger.Shard(sh.id), zap.String("path", loader.path)) start := time.Now() res := loader.Load() - if res.err != nil { + if res.err == nil { log.Info("Opened shard", zap.String("index_version", res.s.IndexType()), zap.Duration("duration", time.Since(start))) } else { log.Error("Failed to open shard", zap.Error(res.err)) @@ -584,7 +583,7 @@ func (s *Store) loadShards() error { if s.startupProgressMetrics != nil { s.startupProgressMetrics.CompletedShard() } - }() + }(log.With(logger.Shard(sh.id), zap.String("path", loader.path))) } // Register shards serially as the parallel goroutines finish opening them.