@@ -35,6 +35,7 @@ import (
35
35
digest "github.com/opencontainers/go-digest"
36
36
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
37
37
"github.com/pkg/errors"
38
+ "github.com/sirupsen/logrus"
38
39
"golang.org/x/sync/errgroup"
39
40
)
40
41
@@ -107,12 +108,7 @@ func (cr *cacheRecord) ref(triggerLastUsed bool, descHandlers DescHandlers, pg p
107
108
progress : pg ,
108
109
}
109
110
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" )
116
112
return ref
117
113
}
118
114
@@ -124,12 +120,7 @@ func (cr *cacheRecord) mref(triggerLastUsed bool, descHandlers DescHandlers) *mu
124
120
descHandlers : descHandlers ,
125
121
}
126
122
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" )
133
124
return ref
134
125
}
135
126
@@ -493,6 +484,24 @@ type immutableRef struct {
493
484
progress progress.Controller
494
485
}
495
486
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
+
496
505
// Order is from parent->child, sr will be at end of slice. Refs should not
497
506
// be released as they are used internally in the underlying cacheRecords.
498
507
func (sr * immutableRef ) layerChain () []* immutableRef {
@@ -615,6 +624,24 @@ type mutableRef struct {
615
624
descHandlers DescHandlers
616
625
}
617
626
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
+
618
645
func (sr * mutableRef ) DescHandler (dgst digest.Digest ) * DescHandler {
619
646
return sr .descHandlers [dgst ]
620
647
}
@@ -1320,12 +1347,7 @@ func (sr *immutableRef) updateLastUsedNow() bool {
1320
1347
1321
1348
func (sr * immutableRef ) release (ctx context.Context ) (rerr error ) {
1322
1349
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 ())
1329
1351
if rerr != nil {
1330
1352
l = l .WithError (rerr )
1331
1353
}
@@ -1514,12 +1536,7 @@ func (sr *mutableRef) Release(ctx context.Context) error {
1514
1536
1515
1537
func (sr * mutableRef ) release (ctx context.Context ) (rerr error ) {
1516
1538
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 ())
1523
1540
if rerr != nil {
1524
1541
l = l .WithError (rerr )
1525
1542
}
0 commit comments