builder-next: fix layer access bug

After switch to leases all ref IDs use generated IDs meaning that
EnsureLayer hack needs to save the chainID for pulled layers.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2020-05-12 19:06:22 -07:00
parent a93e9eb0e9
commit a430bc5d5f
2 changed files with 12 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/containerd/containerd/leases"
"github.com/sirupsen/logrus"
bolt "go.etcd.io/bbolt"
)
type sLM struct {
@ -99,6 +100,15 @@ func (l *sLM) addRef(lID, sID string) {
if load {
l.s.getLayer(sID, true)
if _, ok := l.s.chainID(sID); ok {
l.s.db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte(lID))
if err != nil {
return err
}
return b.Put(keyChainID, []byte(sID))
})
}
}
}

View File

@ -167,10 +167,11 @@ func (s *snapshotter) getLayer(key string, withCommitted bool) (layer.Layer, err
s.mu.Unlock()
return nil, errors.WithStack(err)
}
s.mu.Unlock()
if id == "" {
s.mu.Unlock()
return nil, nil
}
return s.getLayer(string(id), withCommitted)
}
var err error
l, err = s.opt.LayerStore.Get(id)