From cef7a39ba38c55f02b408bc548f3cd71efddba66 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 13 Nov 2023 23:10:43 +0100 Subject: [PATCH] lib/logstorage: always check the previous indexBlockHeader for blocks with matching tenantID and/or streamID The previous indexBlockHeader may contain blocks for the matching tenantID and/or streamID, so it must be scanned unconditionally during the search. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5295 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4856 This is a follow-up for 89dcbc2fe75f5f563b042e605ffce1dc6bc7be07 --- docs/VictoriaLogs/CHANGELOG.md | 1 + lib/logstorage/storage_search.go | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index 54b233739..208095f5b 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -18,6 +18,7 @@ according to [these docs](https://docs.victoriametrics.com/VictoriaLogs/QuickSta ## tip +* BUGFIX: properly locate logs for the [requested streams](https://docs.victoriametrics.com/VictoriaLogs/LogsQL.html#stream-filter). Previously logs for some streams may be missing in query results. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4856). Thanks to @XLONG96 for [the fix](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5295)! * BUGFIX: [web UI](https://docs.victoriametrics.com/VictoriaLogs/querying/#web-ui): properly sort found logs by time. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5300). diff --git a/lib/logstorage/storage_search.go b/lib/logstorage/storage_search.go index a9fa20cfe..ea2d5a8ab 100644 --- a/lib/logstorage/storage_search.go +++ b/lib/logstorage/storage_search.go @@ -382,10 +382,8 @@ func (p *part) searchByTenantIDs(so *searchOptions, bhss *blockHeaders, workCh c n = sort.Search(len(ibhs), func(i int) bool { return !ibhs[i].streamID.tenantID.less(tenantID) }) - if n == len(ibhs) || n > 0 && !ibhs[n].streamID.tenantID.equal(tenantID) { - // The end of ibhs[n-1] may contain blocks for the given tenantID, so move it backwards - n-- - } + // The end of ibhs[n-1] may contain blocks for the given tenantID, so move it backwards + n-- } ibh := &ibhs[n] ibhs = ibhs[n+1:] @@ -493,10 +491,8 @@ func (p *part) searchByStreamIDs(so *searchOptions, bhss *blockHeaders, workCh c n = sort.Search(len(ibhs), func(i int) bool { return !ibhs[i].streamID.less(streamID) }) - if n == len(ibhs) || n > 0 && !ibhs[n].streamID.equal(streamID) { - // The end of ibhs[n-1] may contain blocks for the given streamID, so move it backwards - n-- - } + // The end of ibhs[n-1] may contain blocks for the given streamID, so move it backwards. + n-- } ibh := &ibhs[n] ibhs = ibhs[n+1:]