Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track actives map usage for use in error reporting #37

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions solver/inconsistent_graph_state_error_tracker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package solver

// earthly-specific: this is used to collect information related to "inconsistent graph state" errors

import (
"fmt"
"strings"
"time"

digest "github.com/opencontainers/go-digest"
)

var dgstTrackerInst = newDgstTracker()

type dgstTrackerItem struct {
dgst digest.Digest
action string
seen time.Time
}

type dgstTracker struct {
head int
records []dgstTrackerItem
}

func newDgstTracker() *dgstTracker {
n := 10000
return &dgstTracker{
records: make([]dgstTrackerItem, n),
}
}

func (d *dgstTracker) add(dgst digest.Digest, action string) {
d.head += 1
if d.head >= len(d.records) {
d.head = 0
}
d.records[d.head].dgst = dgst
d.records[d.head].action = action
d.records[d.head].seen = time.Now()
}

func (d *dgstTracker) String() string {
var sb strings.Builder

for i := d.head; i >= 0; i-- {
if d.records[i].seen.IsZero() {
break
}
sb.WriteString(fmt.Sprintf("%s %s %s; ", d.records[i].dgst, d.records[i].action, d.records[i].seen))
}
for i := len(d.records) - 1; i > d.head; i-- {
if d.records[i].seen.IsZero() {
break
}
sb.WriteString(fmt.Sprintf("%s %s %s; ", d.records[i].dgst, d.records[i].action, d.records[i].seen))
}
return sb.String()
}
12 changes: 11 additions & 1 deletion solver/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ func (jl *Solver) getEdge(e Edge) *edge {
jl.mu.RLock()
defer jl.mu.RUnlock()

st, ok := jl.actives[e.Vertex.Digest()]
dgst := e.Vertex.Digest()
st, ok := jl.actives[dgst]
if !ok {
dgstTrackerInst.add(dgst, "get-edge-not-found")
return nil
}
return st.getEdge(e.Index)
Expand Down Expand Up @@ -356,11 +358,13 @@ func (jl *Solver) loadUnlocked(v, parent Vertex, j *Job, cache map[Vertex]Vertex
// existing active vertex, as otherwise the original vertex will use an
// incorrect digest and can incorrectly delete it while it is still in use.
v = st.vtx
dgstTrackerInst.add(dgst, "loadUnlocked-found-dgstWithoutCache")
}

if !ok {
st, ok = jl.actives[dgst]

dgstTrackerInst.add(dgst, "loadUnlocked-not-found-dgstWithoutCache")
// !ignorecache merges with ignorecache but ignorecache doesn't merge with !ignorecache
if ok && !st.vtx.Options().IgnoreCache && v.Options().IgnoreCache {
dgst = dgstWithoutCache
Expand Down Expand Up @@ -394,6 +398,9 @@ func (jl *Solver) loadUnlocked(v, parent Vertex, j *Job, cache map[Vertex]Vertex
origDigest: origVtx.Digest(),
}
jl.actives[dgst] = st
dgstTrackerInst.add(dgst, "loadUnlocked-add")
} else {
dgstTrackerInst.add(dgst, "loadUnlocked-exists")
}

st.mu.Lock()
Expand All @@ -409,6 +416,8 @@ func (jl *Solver) loadUnlocked(v, parent Vertex, j *Job, cache map[Vertex]Vertex
if _, ok := st.jobs[j]; !ok {
st.jobs[j] = struct{}{}
}
} else {
dgstTrackerInst.add(dgst, "loadUnlocked-nil-job")
}
st.mu.Unlock()

Expand Down Expand Up @@ -515,6 +524,7 @@ func (jl *Solver) deleteIfUnreferenced(k digest.Digest, st *state) {
}
st.Release()
delete(jl.actives, k)
dgstTrackerInst.add(k, "delete")
}
}

Expand Down
2 changes: 2 additions & 0 deletions solver/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ type pipeFactory struct {
func (pf *pipeFactory) NewInputRequest(ee Edge, req *edgeRequest) pipe.Receiver {
target := pf.s.ef.getEdge(ee)
if target == nil {
dgst := ee.Vertex.Digest()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe protect against ee.Vertex = nil ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(applies to other lines too)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually forget, i've seen that was assumed already in the old code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, buildkit makes this guarantee for us fortunately :)

bklog.G(context.TODO()).Errorf("failed to get edge dgst=%s name=%s desiredState=%s; actives history: %s", dgst, ee.Vertex.Name(), req.desiredState, dgstTrackerInst.String()) // earthly-specific
return pf.NewFuncRequest(func(_ context.Context) (interface{}, error) {
return nil, errors.Errorf("failed to get edge: inconsistent graph state")
})
Expand Down
Loading