Skip to content

Commit

Permalink
Merge pull request #4285 from tonistiigi/double-merge-edge-fix
Browse files Browse the repository at this point in the history
solver: fix issue with double merged edges
  • Loading branch information
tonistiigi authored Oct 23, 2023
2 parents ef9ae3a + 100d3cb commit 20847b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
13 changes: 10 additions & 3 deletions solver/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type edge struct {
hasActiveOutgoing bool

releaserCount int
owner *edge
keysDidChange bool
index *edgeIndex

Expand Down Expand Up @@ -116,10 +117,12 @@ type edgeRequest struct {
currentKeys int
}

// incrementReferenceCount increases the number of times release needs to be
// takeOwnership increases the number of times release needs to be
// called to release the edge. Called on merging edges.
func (e *edge) incrementReferenceCount() {
e.releaserCount++
func (e *edge) takeOwnership(old *edge) {
e.releaserCount += old.releaserCount + 1
old.owner = e
old.releaseResult()
}

// release releases the edge resources
Expand All @@ -128,6 +131,10 @@ func (e *edge) release() {
e.releaserCount--
return
}
e.releaseResult()
}

func (e *edge) releaseResult() {
e.index.Release(e)
if e.result != nil {
go e.result.Release(context.TODO())
Expand Down
21 changes: 15 additions & 6 deletions solver/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func (s *state) getEdge(index Index) *edge {
s.mu.Lock()
defer s.mu.Unlock()
if e, ok := s.edges[index]; ok {
for e.owner != nil {
e = e.owner
}
return e
}

Expand All @@ -153,19 +156,22 @@ func (s *state) getEdge(index Index) *edge {
return e
}

func (s *state) setEdge(index Index, newEdge *edge) {
func (s *state) setEdge(index Index, targetEdge *edge) {
s.mu.Lock()
defer s.mu.Unlock()
e, ok := s.edges[index]
if ok {
if e == newEdge {
for e.owner != nil {
e = e.owner
}
if e == targetEdge {
return
}
e.release()
} else {
e = newEdge(Edge{Index: index, Vertex: s.vtx}, s.op, s.index)
s.edges[index] = e
}

newEdge.incrementReferenceCount()
s.edges[index] = newEdge
targetEdge.takeOwnership(e)
}

func (s *state) combinedCacheManager() CacheManager {
Expand All @@ -186,6 +192,9 @@ func (s *state) combinedCacheManager() CacheManager {

func (s *state) Release() {
for _, e := range s.edges {
for e.owner != nil {
e = e.owner
}
e.release()
}
if s.op != nil {
Expand Down

0 comments on commit 20847b7

Please sign in to comment.