Skip to content

Commit

Permalink
Fix chunk dedupe iterator
Browse files Browse the repository at this point in the history
for the case when chunks have same from/through time, but different
checksums

Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Apr 26, 2024
1 parent b6905ce commit 2a084f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/bloomgateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func mergeChunks(inputs ...[]*logproto.ShortRef) []*logproto.ShortRef {
v1.NewPeekingIter[*logproto.ShortRef](
v1.NewHeapIterator[*logproto.ShortRef](
func(a, b *logproto.ShortRef) bool {
return a.From.Before(b.From) || (a.From.Equal(b.From) && a.Through.Before(b.Through))
return a.From.Before(b.From) || (a.From.Equal(b.From) && a.Through.Before(b.Through)) || a.Checksum < b.Checksum
},
iters...,
),
Expand Down
17 changes: 17 additions & 0 deletions pkg/bloomgateway/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,20 @@ func TestGatewayClient_MergeSeries(t *testing.T) {
result, _ := mergeSeries(inputs, nil)
require.Equal(t, expected, result)
}

func TestGatewayClient_MergeChunks(t *testing.T) {
inputs := [][]*logproto.ShortRef{
{shortRef(0, 1, 1), shortRef(1, 2, 2)},
{shortRef(0, 1, 1), shortRef(1, 2, 3)},
{shortRef(0, 1, 1), shortRef(1, 2, 2)},
}

expected := []*logproto.ShortRef{
shortRef(0, 1, 1),
shortRef(1, 2, 2),
shortRef(1, 2, 3),
}

result := mergeChunks(inputs...)
require.Equal(t, expected, result)
}

0 comments on commit 2a084f3

Please sign in to comment.