Skip to content

Commit 44facdd

Browse files
authored
Merge pull request moby#3827 from tonistiigi/history-fixes
fixes for history events
2 parents 7a5ca71 + 51039e4 commit 44facdd

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

solver/llbsolver/history.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type HistoryQueueOpt struct {
3535
}
3636

3737
type HistoryQueue struct {
38+
// mu protects active, refs and deleted maps
3839
mu sync.Mutex
3940
initOnce sync.Once
4041
HistoryQueueOpt
@@ -132,6 +133,10 @@ func (h *HistoryQueue) delete(ref string, sync bool) error {
132133
return nil
133134
}
134135
delete(h.deleted, ref)
136+
h.ps.Send(&controlapi.BuildHistoryEvent{
137+
Type: controlapi.BuildHistoryEventType_DELETED,
138+
Record: &controlapi.BuildHistoryRecord{Ref: ref},
139+
})
135140
if err := h.DB.Update(func(tx *bolt.Tx) error {
136141
b := tx.Bucket([]byte(recordsBucket))
137142
if b == nil {
@@ -559,7 +564,10 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
559564
if req.Ref != "" && e.Ref != req.Ref {
560565
continue
561566
}
562-
sub.ps.Send(&controlapi.BuildHistoryEvent{
567+
if _, ok := h.deleted[e.Ref]; ok {
568+
continue
569+
}
570+
sub.send(&controlapi.BuildHistoryEvent{
563571
Type: controlapi.BuildHistoryEventType_STARTED,
564572
Record: e,
565573
})
@@ -568,6 +576,7 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
568576
h.mu.Unlock()
569577

570578
if !req.ActiveOnly {
579+
events := []*controlapi.BuildHistoryEvent{}
571580
if err := h.DB.View(func(tx *bolt.Tx) error {
572581
b := tx.Bucket([]byte(recordsBucket))
573582
if b == nil {
@@ -581,17 +590,31 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
581590
if err := br.Unmarshal(dt); err != nil {
582591
return errors.Wrapf(err, "failed to unmarshal build record %s", key)
583592
}
584-
if err := f(&controlapi.BuildHistoryEvent{
593+
events = append(events, &controlapi.BuildHistoryEvent{
585594
Record: &br,
586595
Type: controlapi.BuildHistoryEventType_COMPLETE,
587-
}); err != nil {
588-
return err
589-
}
596+
})
590597
return nil
591598
})
592599
}); err != nil {
593600
return err
594601
}
602+
// filter out records that have been marked for deletion
603+
h.mu.Lock()
604+
for i, e := range events {
605+
if _, ok := h.deleted[e.Record.Ref]; ok {
606+
events[i] = nil
607+
}
608+
}
609+
h.mu.Unlock()
610+
for _, e := range events {
611+
if e.Record == nil {
612+
continue
613+
}
614+
if err := f(e); err != nil {
615+
return err
616+
}
617+
}
595618
}
596619

597620
if req.EarlyExit {

0 commit comments

Comments
 (0)