Skip to content

Instantly share code, notes, and snippets.

@tbg
Created January 5, 2023 16:30
Show Gist options
  • Save tbg/9e21484b32c426eaeac45f21c8651e7c to your computer and use it in GitHub Desktop.
Save tbg/9e21484b32c426eaeac45f21c8651e7c to your computer and use it in GitHub Desktop.
// DumpMemSST iterates through the SST represented by the input bytes and returns
// all MVCC point and range key values in it.
//
// Not optimized.
// For testing only.
func DumpMemSST(sst []byte) (ps []MVCCKeyValue, rs []MVCCRangeKeyValue, _ error) {
it, err := NewMemSSTIterator(sst, false, IterOptions{
LowerBound: keys.MinKey,
UpperBound: keys.MaxKey,
KeyTypes: IterKeyTypePointsAndRanges,
})
if err != nil {
return nil, nil, err
}
defer it.Close()
for it.SeekGE(MVCCKey{Key: []byte{}}); ; {
ok, err := it.Valid()
if err != nil {
return nil, nil, err
}
if !ok {
break
}
hasPoint, _ := it.HasPointAndRange()
if hasPoint {
val, err := it.Value()
if err != nil {
return nil, nil, err
}
ps = append(ps, MVCCKeyValue{
Key: it.Key(),
Value: val,
})
}
if it.RangeKeyChanged() {
stack := it.RangeKeys().Clone()
rs = append(rs, MVCCRangeKeyValue{
RangeKey: MVCCRangeKey{
StartKey: stack.Bounds.Key,
EndKey: stack.Bounds.EndKey,
Timestamp: stack.Versions[0].Timestamp,
},
Value: stack.Versions[0].Value,
})
}
it.Next()
}
return ps, rs, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment