Skip to content

Commit

Permalink
db: return structured errors from checkConsistency
Browse files Browse the repository at this point in the history
During Open, Pebble verifies the consistency between the Version and the object
catalog. Previously if this function encountered an error or inconsistency, it
would return a new error that erased the type(s) of the original errors. This
commit modifies the function to use errors.Join and avoid the type erasure.
This is necessary for the metamorphic test's error injection, which must be
able to test an error to observe whether it is an errorfs.ErrInjected error.

Informs #1115.
  • Loading branch information
jbowens committed Oct 10, 2023
1 parent e3cbe65 commit 36b3f57
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions open.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,7 @@ func IsCorruptionError(err error) bool {
}

func checkConsistency(v *manifest.Version, dirname string, objProvider objstorage.Provider) error {
var buf bytes.Buffer
var args []interface{}

var errs []error
dedup := make(map[base.DiskFileNum]struct{})
for level, files := range v.Levels {
iter := files.Iter()
Expand All @@ -1153,22 +1151,18 @@ func checkConsistency(v *manifest.Version, dirname string, objProvider objstorag
size, err = objProvider.Size(meta)
}
if err != nil {
buf.WriteString("L%d: %s: %v\n")
args = append(args, errors.Safe(level), errors.Safe(fileNum), err)
errs = append(errs, errors.Wrapf(err, "L%d: %s", errors.Safe(level), fileNum))
continue
}

if size != int64(fileSize) {
buf.WriteString("L%d: %s: object size mismatch (%s): %d (disk) != %d (MANIFEST)\n")
args = append(args, errors.Safe(level), errors.Safe(fileNum), objProvider.Path(meta),
errors.Safe(size), errors.Safe(fileSize))
errs = append(errs, errors.Errorf(
"L%d: %s: object size mismatch (%s): %d (disk) != %d (MANIFEST)",
errors.Safe(level), fileNum, objProvider.Path(meta),
errors.Safe(size), errors.Safe(fileSize)))
continue
}
}
}

if buf.Len() == 0 {
return nil
}
return errors.Errorf(buf.String(), args...)
return errors.Join(errs...)
}

0 comments on commit 36b3f57

Please sign in to comment.