-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Propagate compression options to the inline cache export #2405
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 |
solver/types.go
Outdated
// Mode defines a cache export algorithm | ||
Mode CacheExportMode | ||
// Session is the session group to client (for auth credentials etc) | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
solver/exporter.go
Outdated
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 |
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.
remaining (same on lin 136)
solver/types.go
Outdated
// Mode defines a cache export algorithm | ||
Mode CacheExportMode | ||
// Session is the session group to client (for auth credentials etc) | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
cache/remote.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is target pointer in here?
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.
Refactored not to use target
.
cache/remote.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this returns nil?
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.
Refactored not to call getRemote
here.
cache/remote.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to leverage the chain already resolved by getRemote
.
solver/types.go
Outdated
@@ -94,11 +95,20 @@ const ( | |||
// CacheExportOpt defines options for exporting build cache | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to ResolveRemotes
.
7470dab
to
329a89f
Compare
Co-authored-by: Tonis Tiigi <[email protected]> Signed-off-by: Kohei Tokunaga <[email protected]>
329a89f
to
f9e0346
Compare
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.
👍
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
compression
option is ignored when--export-cache type=inline
is specified.For example, a build something like the following ignores
compression=uncompressed
option 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.