Skip to content

Commit

Permalink
solver: fix printing progress messages after merged edges
Browse files Browse the repository at this point in the history
When different LLB vertexes (eg. parallel requests referencing
local sources from different sessions) generate same cache keys
during solve they are merged together into a single operation.

Currently, when this happened the progress for the vertex that
was dropped got lost. This fixes this case by adding the
progressWriter of the redirected vertex as a target to the
source one.

This should also work with multiple levels of merged edges,
just multiple nested multiwriters as well.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Oct 18, 2023
1 parent 100d3cb commit 759b90c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions solver/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (s *state) getEdge(index Index) *edge {
return e
}

func (s *state) setEdge(index Index, targetEdge *edge) {
func (s *state) setEdge(index Index, targetEdge *edge, targetState *state) {
s.mu.Lock()
defer s.mu.Unlock()
e, ok := s.edges[index]
Expand All @@ -172,6 +172,13 @@ func (s *state) setEdge(index Index, targetEdge *edge) {
s.edges[index] = e
}
targetEdge.takeOwnership(e)

if targetState != nil {
if _, ok := targetState.allPw[s.mpw]; !ok {
targetState.mpw.Add(s.mpw)
targetState.allPw[s.mpw] = struct{}{}
}
}
}

func (s *state) combinedCacheManager() CacheManager {
Expand Down Expand Up @@ -273,7 +280,7 @@ func NewSolver(opts SolverOpt) *Solver {
return jl
}

func (jl *Solver) setEdge(e Edge, newEdge *edge) {
func (jl *Solver) setEdge(e Edge, targetEdge *edge) {
jl.mu.RLock()
defer jl.mu.RUnlock()

Expand All @@ -282,7 +289,10 @@ func (jl *Solver) setEdge(e Edge, newEdge *edge) {
return
}

st.setEdge(e.Index, newEdge)
// potentially passing nil targetSt is intentional and handled in st.setEdge
targetSt := jl.actives[targetEdge.edge.Vertex.Digest()]

st.setEdge(e.Index, targetEdge, targetSt)
}

func (jl *Solver) getState(e Edge) *state {
Expand Down
2 changes: 2 additions & 0 deletions util/progress/multiwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type MultiWriter struct {
meta map[string]interface{}
}

var _ rawProgressWriter = &MultiWriter{}

func NewMultiWriter(opts ...WriterOption) *MultiWriter {
mw := &MultiWriter{
writers: map[rawProgressWriter]struct{}{},
Expand Down

0 comments on commit 759b90c

Please sign in to comment.