Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix incorrect sorting of chunks in bloom-filtered response since ChunkRef.Cmp method is used in reverse #12999

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading