Skip to content

Commit

Permalink
storage: fix invariant Value assertion
Browse files Browse the repository at this point in the history
Calling Iterator.Value is only permitted on a valid iterator positioned over a
point key. Previously the storage package assertions could attempt to read the
Value of an iterator positioned only at a range key start bound.

Epic: none
Fix cockroachdb#110771.
Release note: None
  • Loading branch information
jbowens committed Sep 19, 2023
1 parent 97e4549 commit 50cd55e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/storage/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1945,17 +1945,21 @@ func assertMVCCIteratorInvariants(iter MVCCIterator) error {
return errors.AssertionFailedf("unknown type for engine key %s", engineKey)
}

// Value must equal UnsafeValue.
u, err := iter.UnsafeValue()
if err != nil {
return err
}
v, err := iter.Value()
if err != nil {
return err
}
if !bytes.Equal(v, u) {
return errors.AssertionFailedf("Value %x does not match UnsafeValue %x at %s", v, u, key)
// If the iterator position has a point key, Value must equal UnsafeValue.
// NB: It's only valid to read an iterator's Value if the iterator is
// positioned at a point key.
if hasPoint, _ := iter.HasPointAndRange(); hasPoint {
u, err := iter.UnsafeValue()
if err != nil {
return err
}
v, err := iter.Value()
if err != nil {
return err
}
if !bytes.Equal(v, u) {
return errors.AssertionFailedf("Value %x does not match UnsafeValue %x at %s", v, u, key)
}
}

// For prefix iterators, any range keys must be point-sized. We've already
Expand Down

0 comments on commit 50cd55e

Please sign in to comment.