mirror of
https://github.com/containerd/containerd.git
synced 2026-06-24 08:48:48 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user