Skip to content
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: special handling of assertion errors #3318

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,22 +491,22 @@ func ingestSortAndVerify(cmp Compare, lr ingestLoadResult, exciseSpan KeyRange)
// fit within the exciseSpan.
for _, f := range lr.shared {
if !exciseSpan.Contains(cmp, f.Smallest) || !exciseSpan.Contains(cmp, f.Largest) {
return errors.AssertionFailedf("pebble: shared file outside of excise span, span [%s-%s), file = %s", exciseSpan.Start, exciseSpan.End, f.String())
return errors.Newf("pebble: shared file outside of excise span, span [%s-%s), file = %s", exciseSpan.Start, exciseSpan.End, f.String())
}
}
if len(lr.external) > 0 {
if len(lr.local) > 0 || len(lr.shared) > 0 {
// Currently we only support external ingests on their own. If external
// files are present alongside local/shared files, return an error.
return errors.AssertionFailedf("pebble: external files cannot be ingested atomically alongside other types of files")
return errors.Newf("pebble: external files cannot be ingested atomically alongside other types of files")
}
// Sort according to the smallest key.
slices.SortFunc(lr.external, func(a, b ingestExternalMeta) int {
return cmp(a.Smallest.UserKey, b.Smallest.UserKey)
})
for i := 1; i < len(lr.external); i++ {
if sstableKeyCompare(cmp, lr.external[i-1].Largest, lr.external[i].Smallest) >= 0 {
return errors.AssertionFailedf("pebble: external sstables have overlapping ranges")
return errors.Newf("pebble: external sstables have overlapping ranges")
}
}
return nil
Expand All @@ -522,7 +522,7 @@ func ingestSortAndVerify(cmp Compare, lr ingestLoadResult, exciseSpan KeyRange)

for i := 1; i < len(lr.local); i++ {
if sstableKeyCompare(cmp, lr.local[i-1].Largest, lr.local[i].Smallest) >= 0 {
return errors.AssertionFailedf("pebble: local ingestion sstables have overlapping ranges")
return errors.Newf("pebble: local ingestion sstables have overlapping ranges")
}
}
if len(lr.shared) == 0 {
Expand Down
7 changes: 7 additions & 0 deletions metamorphic/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ type historyRecorder struct {

// Recordf records the results of a single operation.
func (h historyRecorder) Recordf(format string, args ...interface{}) {
// Check for assertion errors.
for _, a := range args {
if err, ok := a.(error); ok && errors.IsAssertionFailure(err) {
fmt.Fprintf(os.Stderr, "%+v", err)
panic(err)
}
}
h.history.Recordf(h.op, format, args...)
// If the history recorder was configured with an additional record func,
// invoke it. This can be used to collect the per-operation output when
Expand Down
15 changes: 10 additions & 5 deletions sstable/prefix_replacing_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ type prefixReplacingIterator struct {
empty bool
}

var errInputPrefixMismatch = errors.New("key argument does not have prefix required for replacement")
var errOutputPrefixMismatch = errors.New("key returned does not have prefix required for replacement")
func errInputPrefixMismatch() error {
return errors.AssertionFailedf("key argument does not have prefix required for replacement")
}

func errOutputPrefixMismatch() error {
return errors.AssertionFailedf("key returned does not have prefix required for replacement")
}

var _ Iterator = (*prefixReplacingIterator)(nil)

Expand Down Expand Up @@ -101,7 +106,7 @@ func (p *prefixReplacingIterator) rewriteResult(
return k, v
}
if !bytes.HasPrefix(k.UserKey, p.contentPrefix) {
p.err = errOutputPrefixMismatch
p.err = errOutputPrefixMismatch()
if invariants.Enabled {
panic(p.err)
}
Expand Down Expand Up @@ -280,7 +285,7 @@ func newPrefixReplacingFragmentIterator(

func (p *prefixReplacingFragmentIterator) rewriteArg(key []byte) ([]byte, error) {
if !bytes.HasPrefix(key, p.syntheticPrefix) {
return nil, errInputPrefixMismatch
return nil, errInputPrefixMismatch()
}
p.arg = append(p.arg[:len(p.contentPrefix)], key[len(p.syntheticPrefix):]...)
return p.arg, nil
Expand All @@ -293,7 +298,7 @@ func (p *prefixReplacingFragmentIterator) rewriteSpan(
return sp, err
}
if !bytes.HasPrefix(sp.Start, p.contentPrefix) || !bytes.HasPrefix(sp.End, p.contentPrefix) {
return nil, errOutputPrefixMismatch
return nil, errOutputPrefixMismatch()
}
sp.Start = append(p.out1[:len(p.syntheticPrefix)], sp.Start[len(p.contentPrefix):]...)
sp.End = append(p.out2[:len(p.syntheticPrefix)], sp.End[len(p.contentPrefix):]...)
Expand Down
Loading