From f3d164d88d03ee586f5f8134e3740b6f6e3268e6 Mon Sep 17 00:00:00 2001 From: Nick Travers Date: Thu, 20 Jan 2022 10:13:24 -0800 Subject: [PATCH] db: save level iter debug output before closing 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() // 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. --- level_checker.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/level_checker.go b/level_checker.go index f717760bb1..79a9cbb6bc 100644 --- a/level_checker.go +++ b/level_checker.go @@ -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. @@ -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 @@ -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 { @@ -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 }