lib/storage: fix reuse pendingMetricRow (#4049)

This commit is contained in:
faceair 2023-04-03 12:28:43 +08:00 committed by Aliaksandr Valialkin
parent 55b5276b70
commit 38fc55976e
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -1851,7 +1851,8 @@ type pendingMetricRows struct {
}
func (pmrs *pendingMetricRows) reset() {
for _, pmr := range pmrs.pmrs {
for i := range pmrs.pmrs {
pmr := &pmrs.pmrs[i]
pmr.MetricName = nil
pmr.mr = nil
}
@ -1875,10 +1876,14 @@ func (pmrs *pendingMetricRows) addRow(mr *MetricRow) error {
pmrs.lastMetricName = pmrs.metricNamesBuf[metricNamesBufLen:]
pmrs.lastMetricNameRaw = mr.MetricNameRaw
}
pmrs.pmrs = append(pmrs.pmrs, pendingMetricRow{
MetricName: pmrs.lastMetricName,
mr: mr,
})
if cap(pmrs.pmrs) > len(pmrs.pmrs) {
pmrs.pmrs = pmrs.pmrs[:len(pmrs.pmrs)+1]
} else {
pmrs.pmrs = append(pmrs.pmrs, pendingMetricRow{})
}
pmr := &pmrs.pmrs[len(pmrs.pmrs)-1]
pmr.MetricName = pmrs.lastMetricName
pmr.mr = mr
return nil
}