Skip to content

Commit

Permalink
move compute cache key function 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 760b53e commit c3a67d4
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions solver/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,19 +783,9 @@ func (e *edge) createInputRequests(desiredState edgeStatusType, f *pipeFactory,
} else {
debugSchedulerSkipInputRequestBasedOnDepState(e, dep, desiredStateDep)
}

// initialize function to compute cache key based on dependency result
if dep.state == edgeStatusComplete && dep.slowCacheReq == nil && (e.slowCacheFunc(dep) != nil || e.preprocessFunc(dep) != nil) && e.cacheMap != nil {
pfn := e.preprocessFunc(dep)
fn := e.slowCacheFunc(dep)
res := dep.result
func(pfn PreprocessFunc, fn ResultBasedCacheFunc, res Result, index Index) {
dep.slowCacheReq = f.NewFuncRequest(func(ctx context.Context) (interface{}, error) {
v, err := e.op.CalcSlowCache(ctx, index, pfn, fn, res)
return v, errors.Wrap(err, "failed to compute cache key")
})
}(pfn, fn, res, dep.index)
addedNew = true
}
addedNew = e.computeCacheKeyFromDep(dep, f) || addedNew
}
return addedNew
}
Expand Down Expand Up @@ -872,6 +862,26 @@ func (e *edge) createOutgoingRequest(dep *dep, desiredStateDep edgeStatusType, f
return true
}

func (e *edge) computeCacheKeyFromDep(dep *dep, f *pipeFactory) (addedNew bool) {
if dep.state != edgeStatusComplete || dep.slowCacheReq != nil || e.cacheMap == nil {
return false
}

pfn := e.preprocessFunc(dep)
fn := e.slowCacheFunc(dep)
if pfn == nil && fn == nil {
return false
}

res := dep.result
index := dep.index
dep.slowCacheReq = f.NewFuncRequest(func(ctx context.Context) (interface{}, error) {
v, err := e.op.CalcSlowCache(ctx, index, pfn, fn, res)
return v, errors.Wrap(err, "failed to compute cache key")
})
return true
}

// 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 c3a67d4

Please sign in to comment.