Skip to content

Commit 670cd89

Browse files
authored
fix: Fix incorrect sorting of chunks in bloom-filtered response since 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.
1 parent ab7af05 commit 670cd89

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

‎pkg/storage/bloom/v1/index.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,14 @@ func (r *ChunkRef) Less(other ChunkRef) bool {
427427

428428
func (r *ChunkRef) Cmp(other ChunkRef) int {
429429
if r.From != other.From {
430-
return int(other.From) - int(r.From)
430+
return int(r.From) - int(other.From)
431431
}
432432

433433
if r.Through != other.Through {
434-
return int(other.Through) - int(r.Through)
434+
return int(r.Through) - int(other.Through)
435435
}
436436

437-
return int(other.Checksum) - int(r.Checksum)
437+
return int(r.Checksum) - int(other.Checksum)
438438
}
439439

440440
func (r *ChunkRef) Encode(enc *encoding.Encbuf, previousEnd model.Time) model.Time {

‎pkg/storage/bloom/v1/index_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,42 +74,42 @@ func TestChunkRefCmpLess(t *testing.T) {
7474
desc: "From is before",
7575
left: ChunkRef{0, 1, 0},
7676
right: ChunkRef{1, 1, 0},
77-
expCmp: 1,
77+
expCmp: -1,
7878
expLess: true,
7979
},
8080
{
8181
desc: "From is after",
8282
left: ChunkRef{1, 1, 0},
8383
right: ChunkRef{0, 1, 0},
84-
expCmp: -1,
84+
expCmp: 1,
8585
expLess: false,
8686
},
8787
{
8888
desc: "Through is before",
8989
left: ChunkRef{0, 1, 0},
9090
right: ChunkRef{0, 2, 0},
91-
expCmp: 1,
91+
expCmp: -1,
9292
expLess: true,
9393
},
9494
{
9595
desc: "Through is after",
9696
left: ChunkRef{0, 2, 0},
9797
right: ChunkRef{0, 1, 0},
98-
expCmp: -1,
98+
expCmp: 1,
9999
expLess: false,
100100
},
101101
{
102102
desc: "Checksum is smaller",
103103
left: ChunkRef{0, 1, 0},
104104
right: ChunkRef{0, 1, 1},
105-
expCmp: 1,
105+
expCmp: -1,
106106
expLess: true,
107107
},
108108
{
109109
desc: "Checksum is bigger",
110110
left: ChunkRef{0, 0, 1},
111111
right: ChunkRef{0, 0, 0},
112-
expCmp: -1,
112+
expCmp: 1,
113113
expLess: false,
114114
},
115115
} {

0 commit comments

Comments
 (0)