app/vmselect/promql: make a copy of per-series timestamps before their modification

The per-series timestamps are usually shared among series, so it is unsafe modifying them.

The issue has been appeared after the optimization at 2f3ddd4884
This commit is contained in:
Aliaksandr Valialkin 2023-01-11 00:11:07 -08:00
parent 8a35377cf3
commit 3d22532bb8
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 11 additions and 2 deletions

View file

@ -864,10 +864,14 @@ func QueryHandler(qt *querytracer.Tracer, startTime time.Time, at *auth.Token, w
}
if queryOffset > 0 {
for i := range result {
timestamps := result[i].Timestamps
r := &result[i]
// Do not modify r.Timestamps, since they may be shared among multiple series.
// Make a copy instead.
timestamps := append([]int64{}, r.Timestamps...)
for j := range timestamps {
timestamps[j] += queryOffset
}
r.Timestamps = timestamps
}
}
@ -1011,7 +1015,9 @@ func removeEmptyValuesAndTimeseries(tss []netstorage.Result) []netstorage.Result
// Slow path: remove NaNs.
srcTimestamps := ts.Timestamps
dstValues := ts.Values[:0]
dstTimestamps := ts.Timestamps[:0]
// Do not re-use ts.Timestamps for dstTimestamps, since ts.Timestamps
// may be shared among multiple time series.
dstTimestamps := make([]int64{}, 0, len(ts.Timestamps))
for j, v := range ts.Values {
if math.IsNaN(v) {
continue

View file

@ -16,6 +16,9 @@ The following tip changes can be tested by building VictoriaMetrics components f
## tip
* BUGFIX: return correct query results over time series with gaps. The issue has been introduced in [v1.86.0](https://docs.victoriametrics.com/CHANGELOG.html#v1860).
## [v1.86.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.86.0)
Released at 2023-01-10