From 6ea83b45b5e9f8e1d0f9d7e5574bb5b520ddfefd Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Wed, 10 Jul 2024 10:16:18 +0200 Subject: [PATCH] fix: Properly reset wal segment writer (#13468) --- pkg/storage/wal/segment.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/storage/wal/segment.go b/pkg/storage/wal/segment.go index e9fb2d51ea15b..c106aa1b27a81 100644 --- a/pkg/storage/wal/segment.go +++ b/pkg/storage/wal/segment.go @@ -62,6 +62,12 @@ type streamSegment struct { } func (s *streamSegment) Reset() { + for i := range s.entries { + s.entries[i] = nil + } + s.lbls = nil + s.tenantID = "" + s.maxt = 0 s.entries = s.entries[:0] } @@ -102,7 +108,6 @@ func (b *SegmentWriter) getOrCreateStream(id streamID, lbls labels.Labels) *stre lbls = labels.NewBuilder(lbls).Set(tenantLabel, id.tenant).Labels() } s = streamSegmentPool.Get().(*streamSegment) - s.Reset() s.lbls = lbls s.tenantID = id.tenant b.streams[id] = s @@ -265,6 +270,7 @@ func (b *SegmentWriter) WriteTo(w io.Writer) (int64, error) { func (b *SegmentWriter) Reset() { for _, s := range b.streams { s := s + s.Reset() streamSegmentPool.Put(s) } b.streams = make(map[streamID]*streamSegment, 64)