e3: ots underflow fixes (#860)

This commit is contained in:
Alex Sharov 2023-01-27 14:40:29 +07:00 committed by GitHub
parent 3f234f90d0
commit 040fefda7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -558,35 +558,23 @@ func (it *InvertedIterator) advanceInDb() {
//Asc: [from, to) AND from > to
//Desc: [from, to) AND from < to
var keyBytes [8]byte
if it.startTxNum < 0 {
if it.orderAscend {
_, v, err = it.cursor.First()
if err != nil {
// TODO pass error properly around
panic(err)
}
} else {
_, v, err = it.cursor.Last()
if err != nil {
panic(err)
}
}
} else {
if it.startTxNum > 0 {
binary.BigEndian.PutUint64(keyBytes[:], uint64(it.startTxNum))
if v, err = it.cursor.SeekBothRange(it.key, keyBytes[:]); err != nil {
panic(err)
}
k, v, err = it.cursor.SeekExact(it.key)
if v, err = it.cursor.SeekBothRange(it.key, keyBytes[:]); err != nil {
panic(err)
}
if v == nil {
if !it.orderAscend {
_, v, _ = it.cursor.PrevDup()
if err != nil {
panic(err)
}
}
if v == nil {
if !it.orderAscend {
_, v, _ = it.cursor.PrevDup()
if err != nil {
panic(err)
}
}
if v == nil {
it.hasNextInDb = false
return
}
it.hasNextInDb = false
return
}
}
} else {