Skip to content

Commit 345c33f

Browse files
committed
storage: remove seekVersion's next-before-seek optimization
The pebble.Iterator has its own try-seek-using-next optimization that happens automatically when performing successive seeks with increasing keys. This obviates the need for the pebbleMVCCScanner performing its own next-before-seek optimization. Simplify the code through removing the optimization from seekVersion. ``` goos: linux goarch: amd64 cpu: Intel(R) Xeon(R) CPU @ 2.80GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ MVCCGet/batch=false/versions=1/valueSize=8/numRangeKeys=0 4.803µ ± 1% 4.841µ ± 2% ~ (p=0.394 n=6) MVCCGet/batch=false/versions=1/valueSize=8/numRangeKeys=1 8.157µ ± 2% 8.293µ ± 1% ~ (p=0.165 n=6) MVCCGet/batch=false/versions=1/valueSize=8/numRangeKeys=100 22.36µ ± 1% 22.31µ ± 1% ~ (p=0.485 n=6) MVCCGet/batch=false/versions=10/valueSize=8/numRangeKeys=0 16.53µ ± 3% 15.47µ ± 1% -6.39% (p=0.002 n=6) MVCCGet/batch=false/versions=10/valueSize=8/numRangeKeys=1 20.32µ ± 2% 19.72µ ± 2% -2.99% (p=0.002 n=6) MVCCGet/batch=false/versions=10/valueSize=8/numRangeKeys=100 34.39µ ± 4% 32.81µ ± 2% -4.58% (p=0.002 n=6) MVCCGet/batch=false/versions=100/valueSize=8/numRangeKeys=0 50.68µ ± 2% 47.36µ ± 2% -6.54% (p=0.002 n=6) MVCCGet/batch=false/versions=100/valueSize=8/numRangeKeys=1 56.52µ ± 1% 52.67µ ± 1% -6.82% (p=0.002 n=6) MVCCGet/batch=false/versions=100/valueSize=8/numRangeKeys=100 79.00µ ± 1% 75.10µ ± 3% -4.94% (p=0.002 n=6) MVCCGet/batch=true/versions=1/valueSize=8/numRangeKeys=0 2.447µ ± 1% 2.485µ ± 1% +1.53% (p=0.009 n=6) MVCCGet/batch=true/versions=1/valueSize=8/numRangeKeys=1 3.812µ ± 2% 3.791µ ± 1% ~ (p=0.485 n=6) MVCCGet/batch=true/versions=1/valueSize=8/numRangeKeys=100 9.370µ ± 3% 9.179µ ± 4% ~ (p=0.180 n=6) MVCCGet/batch=true/versions=10/valueSize=8/numRangeKeys=0 14.04µ ± 2% 13.47µ ± 1% -4.02% (p=0.002 n=6) MVCCGet/batch=true/versions=10/valueSize=8/numRangeKeys=1 16.50µ ± 1% 15.75µ ± 2% -4.53% (p=0.002 n=6) MVCCGet/batch=true/versions=10/valueSize=8/numRangeKeys=100 24.84µ ± 3% 24.39µ ± 2% ~ (p=0.061 n=6) MVCCGet/batch=true/versions=100/valueSize=8/numRangeKeys=0 48.35µ ± 1% 45.72µ ± 1% -5.44% (p=0.002 n=6) MVCCGet/batch=true/versions=100/valueSize=8/numRangeKeys=1 51.77µ ± 2% 49.16µ ± 1% -5.04% (p=0.002 n=6) MVCCGet/batch=true/versions=100/valueSize=8/numRangeKeys=100 68.89µ ± 1% 66.10µ ± 1% -4.05% (p=0.002 n=6) geomean 19.69µ 19.07µ -3.15% ``` Epic: none Release note: none
1 parent c994ab7 commit 345c33f

File tree

1 file changed

+9
-61
lines changed

1 file changed

+9
-61
lines changed

pkg/storage/pebble_mvcc_scanner.go

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,72 +1394,20 @@ func (p *pebbleMVCCScanner) seekVersion(
13941394
return true /* ok */, false
13951395
}
13961396

1397-
seekKey := MVCCKey{Key: p.curUnsafeKey.Key, Timestamp: seekTS}
1398-
p.keyBuf = EncodeMVCCKeyToBuf(p.keyBuf[:0], seekKey)
1399-
origKey := p.keyBuf[:len(p.curUnsafeKey.Key)]
1400-
// We will need seekKey below, if the next's don't suffice. Even though the
1401-
// MVCCIterator will be at a different version of the same key, it is free
1402-
// to mutate the backing for p.curUnsafeKey.Key in an arbitrary manner. So
1403-
// assign to this copy, to make it stable.
1404-
seekKey.Key = origKey
1405-
1406-
for i := 0; i < p.itersBeforeSeek; i++ {
1407-
if !p.iterNext() {
1408-
p.setAdvanceKeyAtEnd()
1409-
return true /* ok */, false
1410-
}
1411-
if !bytes.Equal(p.curUnsafeKey.Key, origKey) {
1412-
p.incrementItersBeforeSeek()
1413-
p.setAdvanceKeyAtNewKey(origKey)
1414-
return true /* ok */, false
1415-
}
1416-
if p.curUnsafeKey.Timestamp.LessEq(seekTS) {
1417-
p.incrementItersBeforeSeek()
1418-
v, valid := p.getFromLazyValue()
1419-
if !valid {
1420-
return false, false
1421-
}
1422-
uncertaintyCheckRequired := uncertaintyCheck && !p.curUnsafeKey.Timestamp.LessEq(p.ts)
1423-
if !p.mvccHeaderRequired(uncertaintyCheckRequired) {
1424-
if !p.decodeCurrentValueIgnoringHeader(v) {
1425-
return false, false
1426-
}
1427-
} else if extended, valid := p.tryDecodeCurrentValueSimple(v); !valid {
1428-
return false, false
1429-
} else if extended {
1430-
if !p.decodeCurrentValueExtended(v) {
1431-
return false, false
1432-
}
1433-
}
1434-
if !uncertaintyCheckRequired {
1435-
if rkv, ok := p.coveredByRangeKey(p.curUnsafeKey.Timestamp); ok {
1436-
return p.addSynthetic(ctx, p.curUnsafeKey.Key, rkv)
1437-
}
1438-
return p.add(ctx, p.curUnsafeKey.Key, p.curRawKey, p.curUnsafeValue.Value.RawBytes, v)
1439-
}
1440-
// Iterate through uncertainty interval. Though we found a value in
1441-
// the interval, it may not be uncertainty. This is because seekTS
1442-
// is set to the transaction's global uncertainty limit, so we are
1443-
// seeking based on the worst-case uncertainty, but values with a
1444-
// time in the range (uncertainty.LocalLimit, uncertainty.GlobalLimit]
1445-
// are only uncertain if they have an earlier local timestamp that is
1446-
// before uncertainty.LocalLimit. Meanwhile, any value with a time in
1447-
// the range (ts, uncertainty.LocalLimit] is uncertain.
1448-
localTS := p.curUnsafeValue.GetLocalTimestamp(p.curUnsafeKey.Timestamp)
1449-
if p.uncertainty.IsUncertain(p.curUnsafeKey.Timestamp, localTS) {
1450-
return p.uncertaintyError(p.curUnsafeKey.Timestamp, localTS), false
1451-
}
1452-
}
1453-
}
1454-
1455-
p.decrementItersBeforeSeek()
1397+
p.keyBuf = append(p.keyBuf[:0], p.curUnsafeKey.Key...)
1398+
originalUserKey := p.keyBuf
1399+
seekKey := MVCCKey{Key: originalUserKey, Timestamp: seekTS}
1400+
// NB: We do not use a the p.itersBeforeSeek optimization here, because the
1401+
// Pebble iterator is already equipped to detect successive SeekGEs to
1402+
// increasing keys and optimize the seek using its own 'TrySeekUsingNext'
1403+
// optimization.
14561404
if !p.iterSeek(seekKey) {
14571405
p.setAdvanceKeyAtEnd()
14581406
return true /* ok */, false
14591407
}
14601408
for {
1461-
if !bytes.Equal(p.curUnsafeKey.Key, origKey) {
1462-
p.setAdvanceKeyAtNewKey(origKey)
1409+
if !bytes.Equal(p.curUnsafeKey.Key, originalUserKey) {
1410+
p.setAdvanceKeyAtNewKey(originalUserKey)
14631411
return true /* ok */, false
14641412
}
14651413
v, valid := p.getFromLazyValue()

0 commit comments

Comments
 (0)