Skip to content

Commit

Permalink
fix: logical error in nilKeyHandler
Browse files Browse the repository at this point in the history
Prior to this, the else was always defaulted to at the end of the conditional branch, which causes unexpected behaviour and a failure of a bunch of tests.
  • Loading branch information
jdockerty committed Jan 17, 2024
1 parent 39821d6 commit 74b3f3a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tsdb/series_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,26 +439,28 @@ func parseSeriesKey(data []byte, dst models.Tags) ([]byte, models.Tags) {

func CompareSeriesKeys(a, b []byte) int {
// Handle 'nil' keys.
// Values below and equal to 1 are considered invalid for key comparisons.
nilKeyHandler := func(a, b int) int {
if a == 0 && b == 0 {
return 0
} else if a == 0 {
return -1
} else {
} else if b == 0 {
return 1
}
return a + b
}

keyValidity := nilKeyHandler(len(a), len(b))
if keyValidity <= 0 || keyValidity == 1 {
if keyValidity <= 1 {
return keyValidity
}

// Read total size.
szA, a := ReadSeriesKeyLen(a)
szB, b := ReadSeriesKeyLen(b)
keySizeValidity := nilKeyHandler(szA, szB)
if keySizeValidity <= 0 || keySizeValidity == 1 {
if keySizeValidity <= 1 {
return keySizeValidity
}

Expand Down

0 comments on commit 74b3f3a

Please sign in to comment.