Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open() is called in the pullthrough code path and needs retry #8612

Merged
merged 1 commit into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/image/importer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,13 @@ func (r retryBlobStore) ServeBlob(ctx context.Context, w http.ResponseWriter, re
}
}
}

func (r retryBlobStore) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) {
for {
if rsc, err := r.BlobStore.Open(ctx, dgst); r.repo.shouldRetry(err) {
continue
} else {
return rsc, err
}
}
}
11 changes: 10 additions & 1 deletion pkg/image/importer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *mockRepository) GetByTag(tag string, options ...distribution.ManifestSe
type mockBlobStore struct {
distribution.BlobStore

statErr, serveErr error
statErr, serveErr, openErr error
}

func (r *mockBlobStore) Stat(ctx context.Context, dgst digest.Digest) (distribution.Descriptor, error) {
Expand All @@ -86,6 +86,10 @@ func (r *mockBlobStore) ServeBlob(ctx context.Context, w http.ResponseWriter, re
return r.serveErr
}

func (r *mockBlobStore) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) {
return nil, r.openErr
}

func TestSchema1ToImage(t *testing.T) {
m := &schema1.SignedManifest{}
if err := json.Unmarshal([]byte(etcdManifest), m); err != nil {
Expand Down Expand Up @@ -284,6 +288,7 @@ func TestRetryFailure(t *testing.T) {
blobs: &mockBlobStore{
serveErr: errcode.ErrorCodeUnauthorized,
statErr: errcode.ErrorCodeUnauthorized,
openErr: errcode.ErrorCodeUnauthorized,
},
}
r = NewRetryRepository(repo, 4, 0).(*retryRepository)
Expand Down Expand Up @@ -326,4 +331,8 @@ func TestRetryFailure(t *testing.T) {
if err := b.ServeBlob(nil, nil, nil, digest.Digest("foo")); err != repo.getErr || r.retries != 0 {
t.Fatalf("unexpected: %v %v %#v", m, err, r)
}
r.retries = 2
if _, err := b.Open(nil, digest.Digest("foo")); err != repo.getErr || r.retries != 0 {
t.Fatalf("unexpected: %v %v %#v", m, err, r)
}
}