-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
metamorphic: add testing for synthetic suffix #3305
Merged
RaduBerinde
merged 2 commits into
cockroachdb:master
from
RaduBerinde:meta-suffix-replacement
Feb 17, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1292,7 +1292,7 @@ func (g *generator) writerIngestExternalFiles() { | |
} | ||
if !b.largestExcl { | ||
// Move up the end key a bit by appending a few letters to the prefix. | ||
kr.End = append(g.keyGenerator.prefix(kr.End), randBytes(g.rng, 1, 3)...) | ||
kr.End = append(g.prefix(kr.End), randBytes(g.rng, 1, 3)...) | ||
} | ||
|
||
objs[i] = externalObjWithBounds{ | ||
|
@@ -1323,6 +1323,11 @@ func (g *generator) writerIngestExternalFiles() { | |
if g.cmp(overall.Start, overall.End) >= 0 { | ||
panic(fmt.Sprintf("invalid bounds [%q, %q)", overall.Start, overall.End)) | ||
} | ||
// If the bounds have the same prefix, we might not be able to generate enough unique keys. | ||
if g.cmp(g.prefix(overall.Start), g.prefix(overall.End)) == 0 { | ||
// Append some bytes to move up the end bound. | ||
overall.End = append(g.prefix(overall.End), randBytes(g.rng, 1, 3)...) | ||
} | ||
// Generate 2*numFiles distinct keys and sort them. These will form the ingest | ||
// bounds for each file. | ||
keys := g.keyGenerator.UniqueKeys(2*numFiles, func() []byte { | ||
|
@@ -1337,6 +1342,22 @@ func (g *generator) writerIngestExternalFiles() { | |
o.bounds.Start = keys[2*i] | ||
} | ||
o.bounds.End = keys[2*i+1] | ||
|
||
if g.rng.Intn(2) == 0 { | ||
// Try to set a synthetic suffix. We can only do so if the bounds don't | ||
// have suffixes, so try to trim them. | ||
start := g.prefix(o.bounds.Start) | ||
end := g.prefix(o.bounds.End) | ||
// If the trimmed bounds overlap with adjacent file bounds, we just don't | ||
// set the suffix. | ||
if g.cmp(start, end) < 0 && | ||
(i == 0 || g.cmp(sorted[i-1].bounds.End, start) <= 0) && | ||
(i == len(sorted)-1 || g.cmp(end, sorted[i+1].bounds.Start) <= 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a comment along the lines of: "if the trimmed bounds overlap with adjacent file bounds, don't bother creating an external object with a syntheticSuffix, as its an unrealistic use case" |
||
o.bounds.Start = start | ||
o.bounds.End = end | ||
o.syntheticSuffix = g.keyGenerator.SkewedSuffix(0.1) | ||
} | ||
} | ||
} | ||
// The batches we're ingesting may contain single delete tombstones that | ||
// when applied to the writer result in nondeterminism in the deleted key. | ||
|
@@ -1481,6 +1502,11 @@ func (g *generator) cmp(a, b []byte) int { | |
return g.keyManager.comparer.Compare(a, b) | ||
} | ||
|
||
func (g *generator) prefix(a []byte) []byte { | ||
n := g.keyManager.comparer.Split(a) | ||
return a[:n:n] | ||
} | ||
|
||
func (g *generator) String() string { | ||
var buf bytes.Buffer | ||
for _, op := range g.ops { | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a quick test for this over here? https://github.com/cockroachdb/pebble/blob/master/testdata/ingest_external#L227
I think all you have to do is add a case where the bounds have suffixes