Propagate compression options to the inline cache export#2405
Propagate compression options to the inline cache export#2405tonistiigi merged 1 commit intomoby:masterfrom
Conversation
|
I'm not sure if From #2347, if it doesn't depend on this PR, maybe make sense to try to change the field to array before changing this logic as it will need to change with the datatype change anyway? |
|
In Why I introduced |
Yes, maybe with #2347 we don't need an array of compressions as every object already contains array. But we would still need
Yes, and with the alternative logic it would just export all available chains. So when inline cache filters the one it needs should be in there.
|
|
@tonistiigi Committed the initial attempt of |
| Session session.Group | ||
| // CompressionOpt is options to specify compressions. All objects that meets | ||
| // any of the options will be cached | ||
| CompressionOpt []CompressionOpt |
There was a problem hiding this comment.
This doesn't strictly need to be a slice as of now because we always pass one or zero element here. (maybe *CompressionOpt is just enough) But in the future, when we want to pass more compressions to LoadRemote this might need to be a slice.
WDYT?
There was a problem hiding this comment.
I think eventually CompressionOpt.Type should be a slice and then in here and in LoadRemotes we possibly don't need a slice. Unless I'm missing something atm I don't think we even need a Force field (still need it as csv option). I'm fine with leaving the array conversion to the next PR though if you prefer.
| func (sr *immutableRef) getRemote(ctx context.Context, createIfNeeded bool, compressionopt solver.CompressionOpt, s session.Group) (*solver.Remote, error) { | ||
| compressionType := compressionopt.Type | ||
| forceCompression := compressionopt.Force | ||
| ctx, done, err := leaseutil.WithLease(ctx, sr.cm.LeaseManager, leaseutil.MakeTemporary) |
There was a problem hiding this comment.
This lease should be moved to the caller as it is somewhat expensive and we shouldn't call it for every compression. In follow-up we should figure out if there is a way to avoid it at all when no new blobs need to be created.
| remote, remotes = remotes[0], remotes[1:] // pop the first element | ||
| } | ||
| if len(opt.CompressionOpt) > 0 { | ||
| for _, r := range remotes { // record all reamaining remotes as well |
| Session session.Group | ||
| // CompressionOpt is options to specify compressions. All objects that meets | ||
| // any of the options will be cached | ||
| CompressionOpt []CompressionOpt |
There was a problem hiding this comment.
I think eventually CompressionOpt.Type should be a slice and then in here and in LoadRemotes we possibly don't need a slice. Unless I'm missing something atm I don't think we even need a Force field (still need it as csv option). I'm fine with leaving the array conversion to the next PR though if you prefer.
cadec20 to
f6549c4
Compare
|
@tonistiigi I think we can focus on the bugfix part mentioned in #2347 and #2350 then we can unblock enhancement PRs. |
f6549c4 to
f9e0125
Compare
|
I'm not sure why you have reverted the |
f9e0125 to
8fab465
Compare
|
@tonistiigi Fixed to have |
|
Current design sgtm if we agree that follow up will change compression params into array. |
8fab465 to
7470dab
Compare
|
@tonistiigi Added tests. The following is the overview and note about the current behaviour of GetRemotes(ctx context.Context, createIfNeeded bool, compressionopt solver.CompressionOpt, all bool, s session.Group) ([]*solver.Remote, error)If If Maybe we can change the behaviour of
I think we can change |
| return | ||
| } | ||
|
|
||
| func (sr *immutableRef) getAvailableBlobs(ctx context.Context, compressionopt solver.CompressionOpt, s session.Group, target *compression.Type) ([]*solver.Remote, error) { |
There was a problem hiding this comment.
why is target pointer in here?
There was a problem hiding this comment.
Refactored not to use target.
| if len(compressions) == 0 { | ||
| // no available compression blobs for this blob (maybe a lazy ref). | ||
| // return a single remote with the specified compression | ||
| remote, err := sr.getRemote(ctx, false, compressionopt, s) |
There was a problem hiding this comment.
Refactored not to call getRemote here.
| var parentVariants []*solver.Remote | ||
| if sr.parent != nil { | ||
| var err error | ||
| parentVariants, err = sr.parent.getAvailableBlobs(ctx, compressionopt, s, nil) |
There was a problem hiding this comment.
Isn't this inefficient? computeBlobChain/getRemote already resolves parents and this does the same over again? The parents returned by getRemote are thrown away iiuc.
There was a problem hiding this comment.
Fixed to leverage the chain already resolved by getRemote.
| type CacheExportOpt struct { | ||
| // Convert can convert a build result to transferable object | ||
| Convert func(context.Context, Result) (*Remote, error) | ||
| Convert func(context.Context, Result) ([]*Remote, error) |
There was a problem hiding this comment.
Maybe smth like ResolveRemotes makes more sense as a name now as it doesn't quite make sense how you can convert something into an array. Or at least pluralize the comment
There was a problem hiding this comment.
Renamed to ResolveRemotes.
7470dab to
329a89f
Compare
Co-authored-by: Tonis Tiigi <tonistiigi@gmail.com> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
329a89f to
f9e0346
Compare
This is a following-up patch for #2350 to move that forward.
Currently, compression options aren't propagated to the inline cache export and it always uses gzip compressor. This leads to an issue that the
compressionoption is ignored when--export-cache type=inlineis specified.For example, a build something like the following ignores
compression=uncompressedoption and creates gzip images.This patch solves this issue by propagating compression options to the inline cache export as well. This also adds an option to
solver.(*exporter).ExportTo()to avoid unexpected contents are recorded when inline export.This adds @tonistiigi as a co-author because this patch is based on a commit of #2350.