Skip to content

Commit

Permalink
[dbnode] Decoder: fix handling of values requiring 64bit precision (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis authored Apr 6, 2021
1 parent 9a43066 commit 3d5cb21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/dbnode/encoding/m3tsz/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func (it *readerIterator) readNextValue() {
}

// inlined readIntValDiff()
if it.sig == 64 {
it.readIntValDiffSlow()
return
}
bits := it.readBits(it.sig + 1)
sign := -1.0
if (bits >> it.sig) == opcodeNegative {
Expand Down Expand Up @@ -181,6 +185,11 @@ func (it *readerIterator) readIntSigMult() {
}

func (it *readerIterator) readIntValDiff() {
// check if we can read both sign bit and digits in one read
if it.sig == 64 {
it.readIntValDiffSlow()
return
}
// read both sign bit and digits in one read
bits := it.readBits(it.sig + 1)
sign := -1.0
Expand All @@ -192,6 +201,15 @@ func (it *readerIterator) readIntValDiff() {
it.intVal += sign * float64(bits)
}

func (it *readerIterator) readIntValDiffSlow() {
sign := -1.0
if it.readBits(1) == opcodeNegative {
sign = 1.0
}

it.intVal += sign * float64(it.readBits(it.sig))
}

func (it *readerIterator) readBits(numBits uint8) (res uint64) {
res, it.err = it.is.ReadBits(numBits)
return
Expand Down
1 change: 0 additions & 1 deletion src/dbnode/encoding/m3tsz/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ func TestReaderIteratorNextWithUnexpectedTimeUnit(t *testing.T) {
}

func TestReaderIteratorDecodingRegression(t *testing.T) {
t.Skip("to be removed in a follow-up PR")
// This reproduces the regression that was introduced in
// https://github.com/m3db/m3/commit/abad1bb2e9a4de18afcb9a29e87fa3a39a694ef4
// by failing decoding (returns unexpected EOF error after the first call to Next()).
Expand Down

0 comments on commit 3d5cb21

Please sign in to comment.