Skip to content

Commit

Permalink
Merge pull request #868 from tonistiigi/solver-cache-fix
Browse files Browse the repository at this point in the history
solver: change early input resolve strategy
  • Loading branch information
tiborvass authored Mar 14, 2019
2 parents f3b968c + fbb7112 commit 0515c76
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions solver/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newEdge(ed Edge, op activeOp, index *edgeIndex) *edge {
edge: ed,
op: op,
depRequests: map[pipe.Receiver]*dep{},
keyMap: map[string]*CacheKey{},
keyMap: map[string]struct{}{},
cacheRecords: map[string]*CacheRecord{},
index: index,
}
Expand All @@ -51,7 +51,7 @@ type edge struct {
execReq pipe.Receiver
err error
cacheRecords map[string]*CacheRecord
keyMap map[string]*CacheKey
keyMap map[string]struct{}

noCacheMatchPossible bool
allDepsCompletedCacheFast bool
Expand Down Expand Up @@ -527,6 +527,10 @@ func (e *edge) recalcCurrentState() {
}
}

for key := range newKeys {
e.keyMap[key] = struct{}{}
}

for _, r := range newKeys {
// TODO: add all deps automatically
mergedKey := r.clone()
Expand Down Expand Up @@ -613,6 +617,36 @@ func (e *edge) recalcCurrentState() {
e.allDepsCompletedCacheSlow = e.cacheMapDone && allDepsCompletedCacheSlow
e.allDepsStateCacheSlow = e.cacheMapDone && allDepsStateCacheSlow
e.allDepsCompleted = e.cacheMapDone && allDepsCompleted

if e.allDepsStateCacheSlow && len(e.cacheRecords) > 0 && e.state == edgeStatusCacheFast {
openKeys := map[string]struct{}{}
for _, dep := range e.deps {
isSlowIncomplete := e.slowCacheFunc(dep) != nil && (dep.state == edgeStatusCacheSlow || (dep.state == edgeStatusComplete && !dep.slowCacheComplete))
if !isSlowIncomplete {
openDepKeys := map[string]struct{}{}
for key := range dep.keyMap {
if _, ok := e.keyMap[key]; !ok {
openDepKeys[key] = struct{}{}
}
}
if len(openKeys) != 0 {
for k := range openKeys {
if _, ok := openDepKeys[k]; !ok {
delete(openKeys, k)
}
}
} else {
openKeys = openDepKeys
}
if len(openKeys) == 0 {
e.state = edgeStatusCacheSlow
if debugScheduler {
logrus.Debugf("upgrade to cache-slow because no open keys")
}
}
}
}
}
}
}

Expand Down

0 comments on commit 0515c76

Please sign in to comment.