Merge pull request #1557 from tonistiigi/mark-cached
solver: fix marking already cached vertex as cancelledv0.8
commit
6220b8a4fc
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func (j *Job) Status(ctx context.Context, ch chan *client.SolveStatus) error {
|
||||
vs := &vertexStream{cache: map[digest.Digest]*client.Vertex{}}
|
||||
vs := &vertexStream{cache: map[digest.Digest]*client.Vertex{}, wasCached: make(map[digest.Digest]struct{})}
|
||||
pr := j.pr.Reader(ctx)
|
||||
defer func() {
|
||||
if enc := vs.encore(); len(enc) > 0 {
|
||||
|
@ -73,6 +73,7 @@ func (j *Job) Status(ctx context.Context, ch chan *client.SolveStatus) error {
|
|||
|
||||
type vertexStream struct {
|
||||
cache map[digest.Digest]*client.Vertex
|
||||
wasCached map[digest.Digest]struct{}
|
||||
}
|
||||
|
||||
func (vs *vertexStream) append(v client.Vertex) []*client.Vertex {
|
||||
|
@ -91,17 +92,34 @@ func (vs *vertexStream) append(v client.Vertex) []*client.Vertex {
|
|||
}
|
||||
}
|
||||
}
|
||||
if v.Cached {
|
||||
vs.markCached(v.Digest)
|
||||
}
|
||||
|
||||
vcopy := v
|
||||
return append(out, &vcopy)
|
||||
}
|
||||
|
||||
func (vs *vertexStream) markCached(dgst digest.Digest) {
|
||||
if v, ok := vs.cache[dgst]; ok {
|
||||
if _, ok := vs.wasCached[dgst]; !ok {
|
||||
for _, inp := range v.Inputs {
|
||||
vs.markCached(inp)
|
||||
}
|
||||
}
|
||||
vs.wasCached[dgst] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (vs *vertexStream) encore() []*client.Vertex {
|
||||
var out []*client.Vertex
|
||||
for _, v := range vs.cache {
|
||||
if v.Started != nil && v.Completed == nil {
|
||||
now := time.Now()
|
||||
v.Completed = &now
|
||||
if _, ok := vs.wasCached[v.Digest]; !ok && v.Error == "" {
|
||||
v.Error = context.Canceled.Error()
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue