Skip to content

Commit

Permalink
move desired state calculation to its own function
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
  • Loading branch information
jsternberg committed Oct 7, 2024
1 parent f90be01 commit b6f6182
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions solver/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,31 +775,7 @@ func (e *edge) createInputRequests(desiredState edgeStatusType, f *pipeFactory,

// cycle all dependencies. set up outgoing requests if needed
for _, dep := range e.deps {
desiredStateDep := dep.state

if e.noCacheMatchPossible || force {
desiredStateDep = edgeStatusComplete
} else if dep.state == edgeStatusInitial && desiredState > dep.state {
desiredStateDep = edgeStatusCacheFast
} else if dep.state == edgeStatusCacheFast && desiredState > dep.state {
// wait all deps to complete cache fast before continuing with slow cache
if (e.allDepsCompletedCacheFast && len(e.keys) == 0) || len(dep.keyMap) == 0 || e.allDepsHaveKeys(true) {
if !e.skipPhase2FastCache(dep) && e.cacheMap != nil {
desiredStateDep = edgeStatusCacheSlow
}
}
} else if e.cacheMap != nil && dep.state == edgeStatusCacheSlow && desiredState == edgeStatusComplete {
// if all deps have completed cache-slow or content based cache for input is available
if (len(dep.keyMap) == 0 || e.allDepsCompletedCacheSlow || (!e.skipPhase2FastCache(dep) && e.slowCacheFunc(dep) != nil)) && (len(e.cacheRecords) == 0) {
if len(dep.keyMap) == 0 || !e.skipPhase2SlowCache(dep) {
desiredStateDep = edgeStatusComplete
}
}
} else if e.cacheMap != nil && dep.state == edgeStatusCacheSlow && e.slowCacheFunc(dep) != nil && desiredState == edgeStatusCacheSlow {
if len(dep.keyMap) == 0 || !e.skipPhase2SlowCache(dep) {
desiredStateDep = edgeStatusComplete
}
}
desiredStateDep := e.desiredStateDep(dep, desiredState, force)

// outgoing request is needed
if dep.state < desiredStateDep {
Expand Down Expand Up @@ -856,6 +832,45 @@ func (e *edge) ensureDepsInitialized() {
}
}

func (e *edge) desiredStateDep(dep *dep, desiredState edgeStatusType, force bool) edgeStatusType {
if e.noCacheMatchPossible || force {
return edgeStatusComplete
}

if dep.state == edgeStatusInitial && desiredState > dep.state {
return edgeStatusCacheFast
}

if dep.state == edgeStatusCacheFast && desiredState > dep.state {
// wait all deps to complete cache fast before continuing with slow cache
if (e.allDepsCompletedCacheFast && len(e.keys) == 0) || len(dep.keyMap) == 0 || e.allDepsHaveKeys(true) {
if !e.skipPhase2FastCache(dep) && e.cacheMap != nil {
return edgeStatusCacheSlow
}
}
return dep.state
}

if e.cacheMap != nil && dep.state == edgeStatusCacheSlow && desiredState == edgeStatusComplete {
// if all deps have completed cache-slow or content based cache for input is available
if (len(dep.keyMap) == 0 || e.allDepsCompletedCacheSlow || (!e.skipPhase2FastCache(dep) && e.slowCacheFunc(dep) != nil)) && (len(e.cacheRecords) == 0) {
if len(dep.keyMap) == 0 || !e.skipPhase2SlowCache(dep) {
return edgeStatusComplete
}
}
return dep.state
}

if e.cacheMap != nil && dep.state == edgeStatusCacheSlow && e.slowCacheFunc(dep) != nil && desiredState == edgeStatusCacheSlow {
if len(dep.keyMap) == 0 || !e.skipPhase2SlowCache(dep) {
return edgeStatusComplete
}
return dep.state
}

return dep.state
}

// execIfPossible creates a request for getting the edge result if there is
// enough state
func (e *edge) execIfPossible(f *pipeFactory) bool {
Expand Down

0 comments on commit b6f6182

Please sign in to comment.