From 94429a82dfaad9c3bf25313d11a69c20cffaaa76 Mon Sep 17 00:00:00 2001 From: LaurentiuNiculae Date: Wed, 23 Aug 2023 19:29:23 +0300 Subject: [PATCH] fix(parse): lock storage while reading using image store (#1719) Signed-off-by: Laurentiu Niculae --- pkg/meta/parse.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/meta/parse.go b/pkg/meta/parse.go index c2e5f4b4..b9c9652c 100644 --- a/pkg/meta/parse.go +++ b/pkg/meta/parse.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "time" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -44,6 +45,11 @@ func ParseStorage(metaDB mTypes.MetaDB, storeController storage.StoreController, func ParseRepo(repo string, metaDB mTypes.MetaDB, storeController storage.StoreController, log log.Logger) error { imageStore := storeController.GetImageStore(repo) + var lockLatency time.Time + + imageStore.RLock(&lockLatency) + defer imageStore.RUnlock(&lockLatency) + indexBlob, err := imageStore.GetIndexContent(repo) if err != nil { log.Error().Err(err).Str("repository", repo).Msg("load-repo: failed to read index.json for repo") @@ -246,6 +252,11 @@ func getCosignSignatureLayersInfo( return layers, err } + var lockLatency time.Time + + imageStore.RLock(&lockLatency) + defer imageStore.RUnlock(&lockLatency) + for _, layer := range manifestContent.Layers { layerContent, err := imageStore.GetBlobContent(repo, layer.Digest) if err != nil { @@ -293,6 +304,11 @@ func getNotationSignatureLayersInfo( layer := manifestContent.Layers[0].Digest + var lockLatency time.Time + + imageStore.RLock(&lockLatency) + defer imageStore.RUnlock(&lockLatency) + layerContent, err := imageStore.GetBlobContent(repo, layer) if err != nil { log.Error().Err(err).Str("repository", repo).Str("reference", manifestDigest).Str("layerDigest", layer.String()).Msg( @@ -326,6 +342,11 @@ func NewManifestData(repoName string, manifestBlob []byte, imageStore storageTyp return mTypes.ManifestData{}, err } + var lockLatency time.Time + + imageStore.RLock(&lockLatency) + defer imageStore.RUnlock(&lockLatency) + configBlob, err := imageStore.GetBlobContent(repoName, manifestContent.Config.Digest) if err != nil { return mTypes.ManifestData{}, err