Skip to content

Commit

Permalink
Merge pull request #2372 from jgiannuzzi/fix-issue-2198
Browse files Browse the repository at this point in the history
Fix flakiness during import of a cache with empty layers removed
  • Loading branch information
tonistiigi authored Sep 24, 2021
2 parents ec787d9 + 2c540bd commit deb1440
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions cache/remotecache/v1/cachestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,35 +214,41 @@ func (cs *cacheResultStorage) Save(res solver.Result, createdAt time.Time) (solv
}

func (cs *cacheResultStorage) LoadWithParents(ctx context.Context, res solver.CacheResult) (map[string]solver.Result, error) {
v := cs.byResultID(res.ID)
if v == nil || v.result == nil {
return nil, errors.WithStack(solver.ErrNotFound)
}

m := map[string]solver.Result{}

visited := make(map[*item]struct{})
if err := v.walkAllResults(func(i *item) error {
if i.result == nil {
return nil
}
id, ok := cs.byItem[i]
if !ok {
return nil
}
if isSubRemote(*i.result, *v.result) {
ref, err := cs.w.FromRemote(ctx, i.result)
if err != nil {
return err

ids, ok := cs.byResult[res.ID]
if !ok || len(ids) == 0 {
return nil, errors.WithStack(solver.ErrNotFound)
}

for id := range ids {
v, ok := cs.byID[id]
if ok && v.result != nil {
if err := v.walkAllResults(func(i *item) error {
if i.result == nil {
return nil
}
id, ok := cs.byItem[i]
if !ok {
return nil
}
if isSubRemote(*i.result, *v.result) {
ref, err := cs.w.FromRemote(ctx, i.result)
if err != nil {
return err
}
m[id] = worker.NewWorkerRefResult(ref, cs.w)
}
return nil
}, visited); err != nil {
for _, v := range m {
v.Release(context.TODO())
}
return nil, err
}
m[id] = worker.NewWorkerRefResult(ref, cs.w)
}
return nil
}, visited); err != nil {
for _, v := range m {
v.Release(context.TODO())
}
return nil, err
}

return m, nil
Expand Down

0 comments on commit deb1440

Please sign in to comment.