Skip to content

Commit

Permalink
fixup! Fix panic in chunk removal
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Jan 24, 2024
1 parent adc3ab6 commit 8619e11
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions pkg/bloomgateway/bloomgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,14 @@ func removeNotMatchingChunks(req *logproto.FilterChunkRefRequest, res v1.Output,
return
}

toRemove := make(map[uint32]any, res.Removals.Len())
for _, chk := range res.Removals {
toRemove[chk.Checksum] = struct{}{}
}

filteredChunks := make([]*logproto.ShortRef, 0, len(req.Refs[idx].Refs))
for _, chk := range req.Refs[idx].Refs {
if _, exists := toRemove[chk.Checksum]; !exists {
filteredChunks = append(filteredChunks, chk)
for i := range res.Removals {
toRemove := res.Removals[i]
for j := 0; j < len(req.Refs[idx].Refs); j++ {
if toRemove.Checksum == req.Refs[idx].Refs[j].Checksum {
req.Refs[idx].Refs[j] = nil // avoid leaking pointer
req.Refs[idx].Refs = append(req.Refs[idx].Refs[:j], req.Refs[idx].Refs[j+1:]...)
j-- // since we removed the current item at index, we have to redo the same index
}
}
}

req.Refs[idx].Refs = filteredChunks
}

0 comments on commit 8619e11

Please sign in to comment.