Skip to content

Commit 546622c

Browse files
committed
llbsolver: filter out records marked deleted from list responses
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent c563db6 commit 546622c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

solver/llbsolver/history.go

Lines changed: 23 additions & 4 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
@@ -559,6 +560,9 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
559560
if req.Ref != "" && e.Ref != req.Ref {
560561
continue
561562
}
563+
if _, ok := h.deleted[e.Ref]; ok {
564+
continue
565+
}
562566
sub.ps.Send(&controlapi.BuildHistoryEvent{
563567
Type: controlapi.BuildHistoryEventType_STARTED,
564568
Record: e,
@@ -568,6 +572,7 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
568572
h.mu.Unlock()
569573

570574
if !req.ActiveOnly {
575+
events := []*controlapi.BuildHistoryEvent{}
571576
if err := h.DB.View(func(tx *bolt.Tx) error {
572577
b := tx.Bucket([]byte(recordsBucket))
573578
if b == nil {
@@ -581,17 +586,31 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
581586
if err := br.Unmarshal(dt); err != nil {
582587
return errors.Wrapf(err, "failed to unmarshal build record %s", key)
583588
}
584-
if err := f(&controlapi.BuildHistoryEvent{
589+
events = append(events, &controlapi.BuildHistoryEvent{
585590
Record: &br,
586591
Type: controlapi.BuildHistoryEventType_COMPLETE,
587-
}); err != nil {
588-
return err
589-
}
592+
})
590593
return nil
591594
})
592595
}); err != nil {
593596
return err
594597
}
598+
// filter out records that have been marked for deletion
599+
h.mu.Lock()
600+
for i, e := range events {
601+
if _, ok := h.deleted[e.Record.Ref]; ok {
602+
events[i] = nil
603+
}
604+
}
605+
h.mu.Unlock()
606+
for _, e := range events {
607+
if e.Record == nil {
608+
continue
609+
}
610+
if err := f(e); err != nil {
611+
return err
612+
}
613+
}
595614
}
596615

597616
if req.EarlyExit {

0 commit comments

Comments
 (0)