Skip to content

Commit

Permalink
fix: Fix incorrect sorting of chunks in bloom-filtered response since…
Browse files Browse the repository at this point in the history
… `ChunkRef.Cmp` method is used in reverse (#12999)

The `v1.ChunkRef.Cmp()` method is used in reverse, and this can lead to chunks in bloom filtered result be sorted in descending but not ascending.
  • Loading branch information
honganan committed May 29, 2024
1 parent ab7af05 commit 670cd89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/storage/bloom/v1/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,14 @@ func (r *ChunkRef) Less(other ChunkRef) bool {

func (r *ChunkRef) Cmp(other ChunkRef) int {
if r.From != other.From {
return int(other.From) - int(r.From)
return int(r.From) - int(other.From)
}

if r.Through != other.Through {
return int(other.Through) - int(r.Through)
return int(r.Through) - int(other.Through)
}

return int(other.Checksum) - int(r.Checksum)
return int(r.Checksum) - int(other.Checksum)
}

func (r *ChunkRef) Encode(enc *encoding.Encbuf, previousEnd model.Time) model.Time {
Expand Down
12 changes: 6 additions & 6 deletions pkg/storage/bloom/v1/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,42 @@ func TestChunkRefCmpLess(t *testing.T) {
desc: "From is before",
left: ChunkRef{0, 1, 0},
right: ChunkRef{1, 1, 0},
expCmp: 1,
expCmp: -1,
expLess: true,
},
{
desc: "From is after",
left: ChunkRef{1, 1, 0},
right: ChunkRef{0, 1, 0},
expCmp: -1,
expCmp: 1,
expLess: false,
},
{
desc: "Through is before",
left: ChunkRef{0, 1, 0},
right: ChunkRef{0, 2, 0},
expCmp: 1,
expCmp: -1,
expLess: true,
},
{
desc: "Through is after",
left: ChunkRef{0, 2, 0},
right: ChunkRef{0, 1, 0},
expCmp: -1,
expCmp: 1,
expLess: false,
},
{
desc: "Checksum is smaller",
left: ChunkRef{0, 1, 0},
right: ChunkRef{0, 1, 1},
expCmp: 1,
expCmp: -1,
expLess: true,
},
{
desc: "Checksum is bigger",
left: ChunkRef{0, 0, 1},
right: ChunkRef{0, 0, 0},
expCmp: -1,
expCmp: 1,
expLess: false,
},
} {
Expand Down

0 comments on commit 670cd89

Please sign in to comment.