From b4b79a496194e5014950d9d89aaab2fc5c972341 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 13 Oct 2024 22:14:31 +0200 Subject: [PATCH] lib/logstorage: make a copy of s.partitions slice when performing queries over the selected partitions s.partitions can be changed when new partition is registered or when old partition is dropped. This could lead to data races and panics when s.partitions slice is accessed by concurrently executed queries. The fix is to make a copy of the selected partitions under s.partitionsLock before performing the query. --- docs/VictoriaLogs/CHANGELOG.md | 1 + lib/logstorage/storage_search.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index cece5d096..3a32b9bc2 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -15,6 +15,7 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta ## tip +* BUGFIX: avoid possible panic when logs for a new day are ingested during execution of concurrent queries. * BUGFIX: avoid panic at `lib/logstorage.(*blockResultColumn).forEachDictValue()` when [stats with additional filters](https://docs.victoriametrics.com/victorialogs/logsql/#stats-with-additional-filters). The panic has been introduced in [v0.33.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.33.0-victorialogs) in [this commit](https://github.com/VictoriaMetrics/VictoriaMetrics/commit/a350be48b68330ee1a487e1fb09b002d3be45163). diff --git a/lib/logstorage/storage_search.go b/lib/logstorage/storage_search.go index 941c195c8..2e269f85e 100644 --- a/lib/logstorage/storage_search.go +++ b/lib/logstorage/storage_search.go @@ -685,6 +685,10 @@ func (s *Storage) search(workersCount int, so *genericSearchOptions, stopCh <-ch return ptws[i].day > maxDay }) ptws = ptws[:n] + + // Copy the selected partitions, so they don't interfere with s.partitions. + ptws = append([]*partitionWrapper{}, ptws...) + for _, ptw := range ptws { ptw.incRef() }