@@ -35,6 +35,7 @@ import (
3535 digest "github.com/opencontainers/go-digest"
3636 ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
3737 "github.com/pkg/errors"
38+ "github.com/sirupsen/logrus"
3839 "golang.org/x/sync/errgroup"
3940)
4041
@@ -107,12 +108,7 @@ func (cr *cacheRecord) ref(triggerLastUsed bool, descHandlers DescHandlers, pg p
107108 progress : pg ,
108109 }
109110 cr .refs [ref ] = struct {}{}
110- bklog .G (context .TODO ()).WithFields (map [string ]any {
111- "id" : cr .ID (),
112- "newRefCount" : len (cr .refs ),
113- "mutable" : false ,
114- "stack" : bklog.LazyStackTrace {},
115- }).Trace ("acquired cache ref" )
111+ bklog .G (context .TODO ()).WithFields (ref .traceLogFields ()).Trace ("acquired cache ref" )
116112 return ref
117113}
118114
@@ -124,12 +120,7 @@ func (cr *cacheRecord) mref(triggerLastUsed bool, descHandlers DescHandlers) *mu
124120 descHandlers : descHandlers ,
125121 }
126122 cr .refs [ref ] = struct {}{}
127- bklog .G (context .TODO ()).WithFields (map [string ]any {
128- "id" : cr .ID (),
129- "newRefCount" : len (cr .refs ),
130- "mutable" : true ,
131- "stack" : bklog.LazyStackTrace {},
132- }).Trace ("acquired cache ref" )
123+ bklog .G (context .TODO ()).WithFields (ref .traceLogFields ()).Trace ("acquired cache ref" )
133124 return ref
134125}
135126
@@ -493,6 +484,24 @@ type immutableRef struct {
493484 progress progress.Controller
494485}
495486
487+ // hold ref lock before calling
488+ func (sr * immutableRef ) traceLogFields () logrus.Fields {
489+ m := map [string ]any {
490+ "id" : sr .ID (),
491+ "refID" : fmt .Sprintf ("%p" , sr ),
492+ "newRefCount" : len (sr .refs ),
493+ "mutable" : false ,
494+ "stack" : bklog.LazyStackTrace {},
495+ }
496+ if sr .equalMutable != nil {
497+ m ["equalMutableID" ] = sr .equalMutable .ID ()
498+ }
499+ if sr .equalImmutable != nil {
500+ m ["equalImmutableID" ] = sr .equalImmutable .ID ()
501+ }
502+ return m
503+ }
504+
496505// Order is from parent->child, sr will be at end of slice. Refs should not
497506// be released as they are used internally in the underlying cacheRecords.
498507func (sr * immutableRef ) layerChain () []* immutableRef {
@@ -615,6 +624,24 @@ type mutableRef struct {
615624 descHandlers DescHandlers
616625}
617626
627+ // hold ref lock before calling
628+ func (sr * mutableRef ) traceLogFields () logrus.Fields {
629+ m := map [string ]any {
630+ "id" : sr .ID (),
631+ "refID" : fmt .Sprintf ("%p" , sr ),
632+ "newRefCount" : len (sr .refs ),
633+ "mutable" : true ,
634+ "stack" : bklog.LazyStackTrace {},
635+ }
636+ if sr .equalMutable != nil {
637+ m ["equalMutableID" ] = sr .equalMutable .ID ()
638+ }
639+ if sr .equalImmutable != nil {
640+ m ["equalImmutableID" ] = sr .equalImmutable .ID ()
641+ }
642+ return m
643+ }
644+
618645func (sr * mutableRef ) DescHandler (dgst digest.Digest ) * DescHandler {
619646 return sr .descHandlers [dgst ]
620647}
@@ -1320,12 +1347,7 @@ func (sr *immutableRef) updateLastUsedNow() bool {
13201347
13211348func (sr * immutableRef ) release (ctx context.Context ) (rerr error ) {
13221349 defer func () {
1323- l := bklog .G (ctx ).WithFields (map [string ]any {
1324- "id" : sr .ID (),
1325- "newRefCount" : len (sr .refs ),
1326- "mutable" : false ,
1327- "stack" : bklog.LazyStackTrace {},
1328- })
1350+ l := bklog .G (ctx ).WithFields (sr .traceLogFields ())
13291351 if rerr != nil {
13301352 l = l .WithError (rerr )
13311353 }
@@ -1514,12 +1536,7 @@ func (sr *mutableRef) Release(ctx context.Context) error {
15141536
15151537func (sr * mutableRef ) release (ctx context.Context ) (rerr error ) {
15161538 defer func () {
1517- l := bklog .G (ctx ).WithFields (map [string ]any {
1518- "id" : sr .ID (),
1519- "newRefCount" : len (sr .refs ),
1520- "mutable" : true ,
1521- "stack" : bklog.LazyStackTrace {},
1522- })
1539+ l := bklog .G (ctx ).WithFields (sr .traceLogFields ())
15231540 if rerr != nil {
15241541 l = l .WithError (rerr )
15251542 }
0 commit comments