Skip to content

Commit

Permalink
metamorphic: consolidate key manager per-object structures
Browse files Browse the repository at this point in the history
This commit merges the `byObj`, `byObjMap` and `bounds` maps into a
single map to a consolidated `*objKeyMeta`.

We no longer store keys in two structures; we only use a map.  We
simplify and improve `mergeKeysInto` to use the target map instead of
sorting and merging all keys; this should be much faster when the
target is the database.
  • Loading branch information
RaduBerinde committed Feb 1, 2024
1 parent 1d7852b commit e53e09a
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 193 deletions.
16 changes: 8 additions & 8 deletions metamorphic/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,14 +1009,14 @@ func (g *generator) iterSeekGEWithLimit(iterID objID) {
})
}

func (g *generator) randKeyToReadWithinBounds(lower, upper []byte, readerID objID) []*keyMeta {
// inRangeKeys returns all keys in the range [lower, upper) associated with the
// given object.
func (g *generator) inRangeKeys(lower, upper []byte, o objID) []*keyMeta {
var inRangeKeys []*keyMeta
for _, keyMeta := range g.keyManager.byObj[readerID] {
posKey := keyMeta.key
if g.cmp(posKey, lower) < 0 || g.cmp(posKey, upper) >= 0 {
continue
for _, keyMeta := range g.keyManager.sortedKeysForObj(o) {
if g.cmp(keyMeta.key, lower) >= 0 && g.cmp(keyMeta.key, upper) < 0 {
inRangeKeys = append(inRangeKeys, keyMeta)
}
inRangeKeys = append(inRangeKeys, keyMeta)
}
return inRangeKeys
}
Expand All @@ -1036,7 +1036,7 @@ func (g *generator) iterSeekPrefixGE(iterID objID) {
// random key.
if g.rng.Intn(10) >= 1 {
possibleKeys := make([][]byte, 0, 100)
inRangeKeys := g.randKeyToReadWithinBounds(lower, upper, g.objDB[iterID])
inRangeKeys := g.inRangeKeys(lower, upper, g.objDB[iterID])
for _, keyMeta := range inRangeKeys {
visibleHistory := keyMeta.history.before(iterCreationTimestamp)

Expand All @@ -1049,7 +1049,7 @@ func (g *generator) iterSeekPrefixGE(iterID objID) {
}

if len(possibleKeys) > 0 {
key = []byte(possibleKeys[g.rng.Int31n(int32(len(possibleKeys)))])
key = possibleKeys[g.rng.Int31n(int32(len(possibleKeys)))]
}
}

Expand Down
Loading

0 comments on commit e53e09a

Please sign in to comment.