From 971aecd1aef426e15dc6025f46525e6ecd80cb5c Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Wed, 17 Apr 2024 11:58:09 +0400 Subject: [PATCH] app/vlselect/logsql: skip rows without _stream reference _stream field can be empty for the recently ingested rows because respective entry in indexdb is not yet searchable as it haven't been flushed to storage yet. This change just skips such items in the output response to make it more consistent. See: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6042 Signed-off-by: Zakhar Bessarab --- app/vlselect/logsql/logsql.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/vlselect/logsql/logsql.go b/app/vlselect/logsql/logsql.go index acdc927a1..78d43a425 100644 --- a/app/vlselect/logsql/logsql.go +++ b/app/vlselect/logsql/logsql.go @@ -48,8 +48,29 @@ func ProcessQueryRequest(w http.ResponseWriter, r *http.Request, stopCh <-chan s } rowsCount := len(columns[0].Values) + // skip entries with empty _stream column + // _stream is empty in case indexdb entry was not flushed to the storage yet + // skipping such entries makes the result more consistent + streamCol := 0 + + // fast path + // _stream column is a built-in column and it is always supposed to be at the same position + if len(columns) >= 2 && columns[1].Name == "_stream" { + streamCol = 1 + } else { + for i := 1; i < len(columns); i++ { + if columns[i].Name == "_stream" { + streamCol = i + break + } + } + } + bb := blockResultPool.Get() for rowIdx := 0; rowIdx < rowsCount; rowIdx++ { + if columns[streamCol].Values[rowIdx] == "" { + continue + } WriteJSONRow(bb, columns, rowIdx) }