From 102e9d4f4ea7b421b082740c6f3ba0402eee1f84 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 30 Oct 2024 13:37:27 +0100 Subject: [PATCH] lib/logstorage: make sure that the number of output (bloom, values) shards is bigger than zero. If the number of output (bloom, values) shards is zero, then this may lead to panic as shown at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7391 . This panic may happen when parts with only constant fields with distinct values are merged into output part with non-constant fields, which should be written to (bloom, values) shards. --- docs/VictoriaLogs/CHANGELOG.md | 2 ++ lib/logstorage/block_stream_writer.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index d6474b93f..8e2037265 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -15,6 +15,8 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta ## tip +* BUGFIX: fix `runtime error: index out of range [0] with length 0` panic during low-rate data ingestion. The panic has been introduced in [v0.38.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.38.0-victorialogs). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7391). + ## [v0.38.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.38.0-victorialogs) Released at 2024-10-29 diff --git a/lib/logstorage/block_stream_writer.go b/lib/logstorage/block_stream_writer.go index 3d3a54382..fcffb3eab 100644 --- a/lib/logstorage/block_stream_writer.go +++ b/lib/logstorage/block_stream_writer.go @@ -312,7 +312,10 @@ func (bsw *blockStreamWriter) MustInitForFilePart(path string, nocache bool, blo func adjustBloomValuesShardsCount(n uint64) uint64 { if n == 0 { - return n + // At least a single shard is needed for writing potential non-const fields, + // which can appear after merging of const fields. + // This fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7391 + return 1 } n = 1 << bits.Len64(n-1)