Add a warning when re-hash occurs during blob commit

(but only if the re-hash takes a "non-trivial" amount of time; currently hard-coded to 250ms)

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
This commit is contained in:
Tianon Gravi
2026-04-02 14:12:13 -07:00
parent 71191c7e27
commit c5abec030a

View File

@@ -115,6 +115,7 @@ func (w *writer) Commit(ctx context.Context, size int64, expected digest.Digest,
dgst := w.digester.Digest()
if expected != "" && expected.Algorithm() != dgst.Algorithm() && expected.Algorithm().Available() {
// Writer was opened without a descriptor specifying the digest algorithm (but we got a non-canonical one here in commit), so we have to re-hash our now completed and closed content to compare
start := time.Now()
f, err := os.Open(filepath.Join(w.path, "data"))
if err != nil {
return fmt.Errorf("failed to open ingest data for re-hashing to %s: %w", expected.Algorithm().String(), err)
@@ -126,6 +127,9 @@ func (w *writer) Commit(ctx context.Context, size int64, expected digest.Digest,
return fmt.Errorf("failed to re-hash ingest data to %s: %w", expected.Algorithm().String(), err)
}
dgst = w.digester.Digest()
if duration := time.Since(start); duration > 250*time.Millisecond {
log.G(ctx).WithField("digest", dgst).WithField("duration", duration).Warnf("commit for blob required expensive re-hash")
}
}
if expected != "" && expected != dgst {
return fmt.Errorf("unexpected commit digest %s, expected %s: %w", dgst, expected, errdefs.ErrFailedPrecondition)