-
Notifications
You must be signed in to change notification settings - Fork 3.9k
content: change Writer/ReaderAt to take OCI descriptor #2135
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ import ( | |
| "github.com/containerd/containerd/filters" | ||
| "github.com/containerd/containerd/log" | ||
| digest "github.com/opencontainers/go-digest" | ||
| ocispec "github.com/opencontainers/image-spec/specs-go/v1" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
|
|
@@ -119,15 +120,15 @@ func (s *store) info(dgst digest.Digest, fi os.FileInfo, labels map[string]strin | |
| } | ||
|
|
||
| // ReaderAt returns an io.ReaderAt for the blob. | ||
| func (s *store) ReaderAt(ctx context.Context, dgst digest.Digest) (content.ReaderAt, error) { | ||
| p := s.blobPath(dgst) | ||
| func (s *store) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) { | ||
| p := s.blobPath(desc.Digest) | ||
| fi, err := os.Stat(p) | ||
| if err != nil { | ||
| if !os.IsNotExist(err) { | ||
| return nil, err | ||
| } | ||
|
|
||
| return nil, errors.Wrapf(errdefs.ErrNotFound, "blob %s expected at %s", dgst, p) | ||
| return nil, errors.Wrapf(errdefs.ErrNotFound, "blob %s expected at %s", desc.Digest, p) | ||
| } | ||
|
|
||
| fp, err := os.Open(p) | ||
|
|
@@ -136,7 +137,7 @@ func (s *store) ReaderAt(ctx context.Context, dgst digest.Digest) (content.Reade | |
| return nil, err | ||
| } | ||
|
|
||
| return nil, errors.Wrapf(errdefs.ErrNotFound, "blob %s expected at %s", dgst, p) | ||
| return nil, errors.Wrapf(errdefs.ErrNotFound, "blob %s expected at %s", desc.Digest, p) | ||
| } | ||
|
|
||
| return sizeReaderAt{size: fi.Size(), fp: fp}, nil | ||
|
|
@@ -400,11 +401,22 @@ func (s *store) total(ingestPath string) int64 { | |
| // ref at a time. | ||
| // | ||
| // The argument `ref` is used to uniquely identify a long-lived writer transaction. | ||
| func (s *store) Writer(ctx context.Context, ref string, total int64, expected digest.Digest) (content.Writer, error) { | ||
| func (s *store) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) { | ||
| var wOpts content.WriterOpts | ||
| for _, opt := range opts { | ||
| if err := opt(&wOpts); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| // TODO(AkihiroSuda): we could create a random string or one calculated based on the context | ||
| // https://github.com/containerd/containerd/issues/2129#issuecomment-380255019 | ||
| if wOpts.Ref == "" { | ||
| return nil, errors.Wrap(errdefs.ErrInvalidArgument, "ref must not be empty") | ||
| } | ||
| var lockErr error | ||
| for count := uint64(0); count < 10; count++ { | ||
| time.Sleep(time.Millisecond * time.Duration(rand.Intn(1<<count))) | ||
| if err := tryLock(ref); err != nil { | ||
| if err := tryLock(wOpts.Ref); err != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we handle the empty ref case now? This looks dangerous with an empty ref and could easily be omitted now.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to require non-empty ref |
||
| if !errdefs.IsUnavailable(err) { | ||
| return nil, err | ||
| } | ||
|
|
@@ -420,9 +432,9 @@ func (s *store) Writer(ctx context.Context, ref string, total int64, expected di | |
| return nil, lockErr | ||
| } | ||
|
|
||
| w, err := s.writer(ctx, ref, total, expected) | ||
| w, err := s.writer(ctx, wOpts.Ref, wOpts.Desc.Size, wOpts.Desc.Digest) | ||
| if err != nil { | ||
| unlock(ref) | ||
| unlock(wOpts.Ref) | ||
| return nil, err | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, no oci descriptor on write.