Skip to content

Commit

Permalink
db: save level iter debug output before closing
Browse files Browse the repository at this point in the history
Currently, if the level checker encounters a violation an the iterator
for the last level has been closed, the debug string providing
information on the level and the file is lost.

Save the debug string for potential use after the iterator is closed.

```
// Before
checker failed with error: found InternalKey zzqwavxgrec@12#4092,SINGLEDEL in L0.2: fileNum=000830 and InternalKey zzqwavxgrec@12#4627,DEL in %!s(<nil>)

// After
checker failed with error: found InternalKey zzqwavxgrec@12#4092,SINGLEDEL in L0.2: fileNum=000830 and InternalKey zzqwavxgrec@12#4627,DEL in L6: fileNum=000997
```

Related to #1459.
  • Loading branch information
nicktrav committed Jan 20, 2022
1 parent 7f1a70d commit f3d164d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions level_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ type simpleMergingIter struct {
snapshot uint64
heap mergingIterHeap
// The last point's key and level. For validation.
lastKey InternalKey
lastLevel int
lastKey InternalKey
lastLevel int
lastIterMsg string
// A non-nil valueMerger means MERGE record processing is ongoing.
valueMerger base.ValueMerger
// The first error will cause step() to return false.
Expand Down Expand Up @@ -135,10 +136,9 @@ func (m *simpleMergingIter) step() bool {
// At the same user key. We will see them in decreasing seqnum
// order so the lastLevel must not be lower.
if m.lastLevel > item.index {
lastLevel := m.levels[m.lastLevel]
m.err = errors.Errorf("found InternalKey %s in %s and InternalKey %s in %s",
item.key.Pretty(m.formatKey), l.iter, m.lastKey.Pretty(m.formatKey),
lastLevel.iter)
m.lastIterMsg)
return false
}
m.lastLevel = item.index
Expand Down Expand Up @@ -216,11 +216,11 @@ func (m *simpleMergingIter) step() bool {
}
}
}
// If the current record is the last record in the DB and it happens to be on
// L1 or higher, the l.iter.Next() below will cause the underlying levelIter
// to be become invalid thereby losing the fileNum where the last
// record came from. Hence we save it before calling next.
lastRecordMsg := l.iter.String()

// The iterator for the current level may be closed in the following call to
// Next(). We save its debug string for potential use after it is closed -
// either in this current step() invocation or on the next invocation.
m.lastIterMsg = l.iter.String()

// Step to the next point.
if l.iterKey, l.iterValue = l.iter.Next(); l.iterKey != nil {
Expand Down Expand Up @@ -258,7 +258,7 @@ func (m *simpleMergingIter) step() bool {
}
if m.err != nil {
m.err = errors.Wrapf(m.err, "merge processing error on key %s in %s",
item.key.Pretty(m.formatKey), lastRecordMsg)
item.key.Pretty(m.formatKey), m.lastIterMsg)
}
m.valueMerger = nil
}
Expand Down

0 comments on commit f3d164d

Please sign in to comment.