Created
January 5, 2023 16:30
-
-
Save tbg/9e21484b32c426eaeac45f21c8651e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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