Merge pull request #2388 from ktock/containerd-overlaydiff-bufcopy

Differ: write diff to the content store over bufio writer
master
Akihiro Suda 2021-10-04 17:05:49 +09:00 committed by GitHub
commit 10947b040c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,7 @@
package cache
import (
"bufio"
"bytes"
"context"
"fmt"
@ -71,10 +72,11 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
}
}()
bufW := bufio.NewWriterSize(cw, 128*1024)
var labels map[string]string
if compressorFunc != nil {
dgstr := digest.SHA256.Digester()
compressed, err := compressorFunc(cw, mediaType)
compressed, err := compressorFunc(bufW, mediaType)
if err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to get compressed stream")
}
@ -88,11 +90,14 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
}
labels[containerdUncompressed] = dgstr.Digest().String()
} else {
if err = writeOverlayUpperdir(ctx, cw, upperdir, lower); err != nil {
if err = writeOverlayUpperdir(ctx, bufW, upperdir, lower); err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to write diff")
}
}
if err := bufW.Flush(); err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to flush diff")
}
var commitopts []content.Opt
if labels != nil {
commitopts = append(commitopts, content.WithLabels(labels))