From 759b90cc977f0bf1be5b30bb99de8a9b05fca0fd Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 17 Oct 2023 22:20:22 -0700 Subject: [PATCH] solver: fix printing progress messages after merged edges 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 --- solver/jobs.go | 16 +++++++++++++--- util/progress/multiwriter.go | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/solver/jobs.go b/solver/jobs.go index 67d53e2acccbf..6f908b56f891e 100644 --- a/solver/jobs.go +++ b/solver/jobs.go @@ -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] @@ -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 { @@ -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() @@ -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 { diff --git a/util/progress/multiwriter.go b/util/progress/multiwriter.go index 7cce8a7ca7d2a..f0f7b40aff5be 100644 --- a/util/progress/multiwriter.go +++ b/util/progress/multiwriter.go @@ -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{}{},