mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #19458 from dmcgowan/layerstore-error-handling
Add more robust error handling on layer store creation
This commit is contained in:
commit
e11a7f5371
2 changed files with 21 additions and 16 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
|
@ -154,7 +155,7 @@ func (fms *fileMetadataStore) GetParent(layer ChainID) (ChainID, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
dgst, err := digest.ParseDigest(string(content))
|
dgst, err := digest.ParseDigest(strings.TrimSpace(string(content)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -168,7 +169,7 @@ func (fms *fileMetadataStore) GetDiffID(layer ChainID) (DiffID, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
dgst, err := digest.ParseDigest(string(content))
|
dgst, err := digest.ParseDigest(strings.TrimSpace(string(content)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -177,16 +178,17 @@ func (fms *fileMetadataStore) GetDiffID(layer ChainID) (DiffID, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fms *fileMetadataStore) GetCacheID(layer ChainID) (string, error) {
|
func (fms *fileMetadataStore) GetCacheID(layer ChainID) (string, error) {
|
||||||
content, err := ioutil.ReadFile(fms.getLayerFilename(layer, "cache-id"))
|
contentBytes, err := ioutil.ReadFile(fms.getLayerFilename(layer, "cache-id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
content := strings.TrimSpace(string(contentBytes))
|
||||||
|
|
||||||
if !stringIDRegexp.MatchString(string(content)) {
|
if !stringIDRegexp.MatchString(content) {
|
||||||
return "", errors.New("invalid cache id value")
|
return "", errors.New("invalid cache id value")
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(content), nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fms *fileMetadataStore) TarSplitReader(layer ChainID) (io.ReadCloser, error) {
|
func (fms *fileMetadataStore) TarSplitReader(layer ChainID) (io.ReadCloser, error) {
|
||||||
|
@ -227,32 +229,34 @@ func (fms *fileMetadataStore) SetMountParent(mount string, parent ChainID) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fms *fileMetadataStore) GetMountID(mount string) (string, error) {
|
func (fms *fileMetadataStore) GetMountID(mount string) (string, error) {
|
||||||
content, err := ioutil.ReadFile(fms.getMountFilename(mount, "mount-id"))
|
contentBytes, err := ioutil.ReadFile(fms.getMountFilename(mount, "mount-id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
content := strings.TrimSpace(string(contentBytes))
|
||||||
|
|
||||||
if !stringIDRegexp.MatchString(string(content)) {
|
if !stringIDRegexp.MatchString(content) {
|
||||||
return "", errors.New("invalid mount id value")
|
return "", errors.New("invalid mount id value")
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(content), nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fms *fileMetadataStore) GetInitID(mount string) (string, error) {
|
func (fms *fileMetadataStore) GetInitID(mount string) (string, error) {
|
||||||
content, err := ioutil.ReadFile(fms.getMountFilename(mount, "init-id"))
|
contentBytes, err := ioutil.ReadFile(fms.getMountFilename(mount, "init-id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
content := strings.TrimSpace(string(contentBytes))
|
||||||
|
|
||||||
if !stringIDRegexp.MatchString(string(content)) {
|
if !stringIDRegexp.MatchString(content) {
|
||||||
return "", errors.New("invalid init id value")
|
return "", errors.New("invalid init id value")
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(content), nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fms *fileMetadataStore) GetMountParent(mount string) (ChainID, error) {
|
func (fms *fileMetadataStore) GetMountParent(mount string) (ChainID, error) {
|
||||||
|
@ -264,7 +268,7 @@ func (fms *fileMetadataStore) GetMountParent(mount string) (ChainID, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
dgst, err := digest.ParseDigest(string(content))
|
dgst, err := digest.ParseDigest(strings.TrimSpace(string(content)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver) (St
|
||||||
l, err := ls.loadLayer(id)
|
l, err := ls.loadLayer(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Failed to load layer %s: %s", id, err)
|
logrus.Debugf("Failed to load layer %s: %s", id, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if l.parent != nil {
|
if l.parent != nil {
|
||||||
l.parent.referenceCount++
|
l.parent.referenceCount++
|
||||||
|
@ -109,22 +110,22 @@ func (ls *layerStore) loadLayer(layer ChainID) (*roLayer, error) {
|
||||||
|
|
||||||
diff, err := ls.store.GetDiffID(layer)
|
diff, err := ls.store.GetDiffID(layer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to get diff id for %s: %s", layer, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
size, err := ls.store.GetSize(layer)
|
size, err := ls.store.GetSize(layer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to get size for %s: %s", layer, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheID, err := ls.store.GetCacheID(layer)
|
cacheID, err := ls.store.GetCacheID(layer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to get cache id for %s: %s", layer, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parent, err := ls.store.GetParent(layer)
|
parent, err := ls.store.GetParent(layer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to get parent for %s: %s", layer, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cl = &roLayer{
|
cl = &roLayer{
|
||||||
|
|
Loading…
Add table
Reference in a new issue