Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: handle errors in pebbleMVCCScanner.enablePointSynthesis #90899

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions pkg/storage/pebble_mvcc_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ func (p *pebbleMVCCScanner) get(ctx context.Context) {
// HasPointAndRange() call.
if ok, _ := p.parent.Valid(); ok {
if _, hasRange := p.parent.HasPointAndRange(); hasRange {
p.enablePointSynthesis()
if !p.enablePointSynthesis() {
return
}
}
}

Expand Down Expand Up @@ -477,7 +479,9 @@ func (p *pebbleMVCCScanner) scan(
// HasPointAndRange() call.
if ok, _ := p.parent.Valid(); ok {
if _, hasRange := p.parent.HasPointAndRange(); hasRange {
p.enablePointSynthesis()
if !p.enablePointSynthesis() {
return nil, 0, 0, p.err
}
}
}

Expand Down Expand Up @@ -1199,8 +1203,8 @@ func (p *pebbleMVCCScanner) updateCurrent() bool {
// synthesizes MVCC point tombstones for MVCC range tombstones and never emits
// range keys itself. p.parent must be valid.
//
// gcassert:inline
func (p *pebbleMVCCScanner) enablePointSynthesis() {
// Returns true if the iterator is valid.
func (p *pebbleMVCCScanner) enablePointSynthesis() bool {
if util.RaceEnabled {
if ok, _ := p.parent.Valid(); !ok {
panic(errors.AssertionFailedf("enablePointSynthesis called with invalid iter"))
Expand All @@ -1213,13 +1217,18 @@ func (p *pebbleMVCCScanner) enablePointSynthesis() {
p.parent.UnsafeKey()))
}
}
p.pointIter = NewPointSynthesizingIterAtParent(p.parent)
p.parent = p.pointIter
pointIter, err := NewPointSynthesizingIterAtParent(p.parent)
if err != nil {
p.err = err
return false
}
if util.RaceEnabled {
if ok, _ := p.parent.Valid(); !ok {
if ok, _ := pointIter.Valid(); !ok {
panic(errors.AssertionFailedf("invalid pointSynthesizingIter with valid iter"))
}
}
p.pointIter, p.parent = pointIter, pointIter
return true
}

func (p *pebbleMVCCScanner) decodeCurrentMetadata() bool {
Expand Down Expand Up @@ -1260,7 +1269,9 @@ func (p *pebbleMVCCScanner) iterValid() bool {
// Since iterValid() is called after every iterator positioning operation, it
// is convenient to check for any range keys and enable point synthesis here.
if p.parent.RangeKeyChanged() {
p.enablePointSynthesis()
if !p.enablePointSynthesis() {
return false
}
}
if util.RaceEnabled && p.pointIter == nil {
if _, hasRange := p.parent.HasPointAndRange(); hasRange {
Expand Down
10 changes: 7 additions & 3 deletions pkg/storage/point_synthesizing_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,22 @@ func NewPointSynthesizingIter(parent MVCCIterator) *PointSynthesizingIter {

// NewPointSynthesizingIterAtParent creates a new pointSynthesizingIter and
// loads the position from the parent iterator.
func NewPointSynthesizingIterAtParent(parent MVCCIterator) *PointSynthesizingIter {
func NewPointSynthesizingIterAtParent(parent MVCCIterator) (*PointSynthesizingIter, error) {
iter := NewPointSynthesizingIter(parent)
iter.rangeKeyChanged = true // force range key detection
if ok, err := iter.updateIter(); ok && err == nil {
if ok, _ := iter.updateIter(); ok {
// updateSeekGEPosition may step parent and then compare against seekKey, so
// we need to clone it.
seekKey := parent.UnsafeKey()
iter.seekKeyBuf = append(iter.seekKeyBuf[:0], seekKey.Key...)
seekKey.Key = iter.seekKeyBuf
iter.updateSeekGEPosition(seekKey)
}
return iter
if iter.iterErr != nil {
iter.release()
return nil, iter.iterErr
}
return iter, nil
}

// Close implements MVCCIterator.
Expand Down