Merge pull request #365 from tonistiigi/content-writer-race

containerd: avoid contentstore race
docker-18.09
Akihiro Suda 2018-05-08 14:50:24 +09:00 committed by GitHub
commit 587edf5a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
) )
@ -70,8 +71,26 @@ func (c *nsContent) ReaderAt(ctx context.Context, dgst digest.Digest) (content.R
} }
func (c *nsContent) Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (content.Writer, error) { func (c *nsContent) Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (content.Writer, error) {
return c.writer(ctx, ref, size, expected, 3)
}
func (c *nsContent) writer(ctx context.Context, ref string, size int64, expected digest.Digest, retries int) (content.Writer, error) {
ctx = namespaces.WithNamespace(ctx, c.ns) ctx = namespaces.WithNamespace(ctx, c.ns)
return c.Store.Writer(ctx, ref, size, expected) w, err := c.Store.Writer(ctx, ref, size, expected)
if err != nil {
if errdefs.IsAlreadyExists(err) && expected != "" && retries > 0 {
_, err2 := c.Update(ctx, content.Info{
Digest: expected,
Labels: map[string]string{
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339Nano),
},
}, "labels.containerd.io/gc.root")
if err2 != nil {
return c.writer(ctx, ref, size, expected, retries-1)
}
}
}
return w, err
} }
type noGCContentStore struct { type noGCContentStore struct {