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

llb: per-vertex metadata (e.g. IgnoreCache) #114

Merged
merged 1 commit into from
Oct 3, 2017

Conversation

AkihiroSuda
Copy link
Member

Signed-off-by: Akihiro Suda [email protected]

This PR is an initial step to add per-vertex metadata, of which structure is defined in solver/pb/ops.proto:

message Metadata {
	// key = LLB op digest string. Currently, empty string is not expected but may change in the future.
	map<string, MetadataEntry> entries = 1 [(gogoproto.castkey) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false];
}

message MetadataEntry {
	bool ignore_cache = 1;
	// TODO: add worker constraint, etc.
}

Currently, only ignore_cache is implemented.
buildctl build --no-cache sets ignore_cache for all the vertices.

Future version will contain worker constraint and so on: #62 (comment) #41 #81

@tonistiigi

client/solve.go Outdated
func (c *Client) Solve(ctx context.Context, r io.Reader, opt SolveOpt, statusChan chan *SolveStatus) error {
// Solve calls Solve on the controller.
// def and metadata are empty if opt.Frontend is set.
func (c *Client) Solve(ctx context.Context, def [][]byte, metadata pb.Metadata, opt SolveOpt, statusChan chan *SolveStatus) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid protobuf types in client pkg

}

message BuildInput {
int64 input = 1 [(gogoproto.customtype) = "InputIndex", (gogoproto.nullable) = false];
}

message Metadata {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really related to LLB definition at all, or controller definition? How about defining

struct {
   Definition [][]byte
   Metadata map[digest.Digest]MetadataEntry
}

that would be what llb.Marshal generates and client.Solve takes as an input. buildctl can also understand that and override if needed. Then a script generating llb can also define it. For example, worker constraints need to be defined by the script not by the override in buildctl.

solver/solver.go Outdated
@@ -479,6 +485,12 @@ func (s *Solver) getRef(ctx context.Context, g *vertex, index Index) (ref Refere
return false, err
}
if lookupRef != nil {
if md, ok := g.SysMetadata().(pb.MetadataEntry); ok && md.IgnoreCache {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this only work for the last vertex?

@AkihiroSuda
Copy link
Member Author

I'll rebase today

solver/jobs.go Outdated
@@ -210,6 +211,9 @@ func (j *job) getRef(ctx context.Context, v *vertex, index Index) (Reference, er
}

func getRef(s VertexSolver, ctx context.Context, v *vertex, index Index, cache InstructionCache) (Reference, error) {
if v.sysMetadata.IgnoreCache {
logrus.Warnf("Unimplemented OpMetadata: IgnoreCache (%s, %s)", v.digest, v.name)
Copy link
Member Author

@AkihiroSuda AkihiroSuda Oct 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonistiigi
I'll try to implement cache invalidation in another PR, please review the data structure?

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments. Most could be addressed in a follow-up. Overall looks good

@@ -92,12 +93,12 @@ func (e *ExecOp) Validate() error {
return nil
}

func (e *ExecOp) Marshal() ([]byte, error) {
func (e *ExecOp) Marshal() ([]byte, *pb.OpMetadata, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just (*llb.Definition, error). This can be follow-up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function just returns []byte representation of single Op while llb.Definition contains [][]byte representation of multiple Ops.
Should we modify definition of llb.Definition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -49,9 +53,36 @@ var buildCommand = cli.Command{
Name: "frontend-opt",
Usage: "Define custom options for frontend",
},
cli.BoolFlag{
Name: "no-cache",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove this, for now, to avoid confusion if it doesn't work yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put "not implemented" to the command line help string.
This will be soonly implemented.

}
} else {
if clicontext.Bool("no-cache") {
return errors.New("no-cache is not supported for frontends")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we map these to frontend-opt ? (follow-up)

}
return nil
l := make([]byte, 4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably no reason to add a length if we just marshal the whole object. Just write/read the protobuf object.

@@ -48,48 +48,54 @@ func (s State) Value(k interface{}) interface{} {
return s.ctx.Value(k)
}

func (s State) Marshal() ([][]byte, error) {
list, err := marshal(s.Output().Vertex(), nil, map[digest.Digest]struct{}{}, map[Vertex]struct{}{})
func (s State) Marshal() (Definition, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I like when functions like this return pointers. As it contains slices/maps it shares the memory anyway.

solver/vertex.go Outdated
@@ -17,6 +18,7 @@ type Vertex interface {
// Sys returns an internal value that is used to execute the vertex. Usually
// this is capured by the operation resolver method during solve.
Sys() interface{}
SysMetadata() pb.OpMetadata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just Metadata(), and maybe return solver.Metadata interface? Atm the solver should be usable without llb definition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated PR.

However, Solver still has depend on the pb package:

func (s *Solver) Solve(ctx context.Context, id string, f frontend.Frontend, def *pb.Definition, exp exporter.ExporterInstance, frontendOpt map[string]string) error

Copy link
Member

@tonistiigi tonistiigi Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yes I think I broke it when I moved the protobuf-to-vertex conversion to the job.load. Need to think about it later if there is a way around that.

@AkihiroSuda
Copy link
Member Author

@tonistiigi updated

cache invalidation itself it not implemented yet

Signed-off-by: Akihiro Suda <[email protected]>
@AkihiroSuda
Copy link
Member Author

CI green

@tonistiigi
Copy link
Member

LGTM

@tonistiigi tonistiigi merged commit f419a8c into moby:master Oct 3, 2017
alexcb added a commit to alexcb/buildkit that referenced this pull request Feb 17, 2023
prevent long lived connection reuse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants