mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 20:38:08 +08:00
fix(storage): sanitize storage locks (#1003)
removed all locks from common code removed locks from GetBlobContent Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
notreg "github.com/notaryproject/notation-go/registry"
|
||||
godigest "github.com/opencontainers/go-digest"
|
||||
@@ -89,8 +90,13 @@ func (olu BaseOciLayoutUtils) GetRepositories() ([]string, error) {
|
||||
|
||||
// Below method will return image path including root dir, root dir is determined by splitting.
|
||||
func (olu BaseOciLayoutUtils) GetImageManifests(repo string) ([]ispec.Descriptor, error) {
|
||||
var lockLatency time.Time
|
||||
|
||||
imageStore := olu.StoreController.GetImageStore(repo)
|
||||
|
||||
imageStore.RLock(&lockLatency)
|
||||
defer imageStore.RUnlock(&lockLatency)
|
||||
|
||||
buf, err := imageStore.GetIndexContent(repo)
|
||||
if err != nil {
|
||||
if goerrors.Is(errors.ErrRepoNotFound, err) {
|
||||
@@ -118,8 +124,13 @@ func (olu BaseOciLayoutUtils) GetImageManifests(repo string) ([]ispec.Descriptor
|
||||
func (olu BaseOciLayoutUtils) GetImageBlobManifest(repo string, digest godigest.Digest) (ispec.Manifest, error) {
|
||||
var blobIndex ispec.Manifest
|
||||
|
||||
var lockLatency time.Time
|
||||
|
||||
imageStore := olu.StoreController.GetImageStore(repo)
|
||||
|
||||
imageStore.RLock(&lockLatency)
|
||||
defer imageStore.RUnlock(&lockLatency)
|
||||
|
||||
blobBuf, err := imageStore.GetBlobContent(repo, digest)
|
||||
if err != nil {
|
||||
olu.Log.Error().Err(err).Msg("unable to open image metadata file")
|
||||
@@ -139,8 +150,13 @@ func (olu BaseOciLayoutUtils) GetImageBlobManifest(repo string, digest godigest.
|
||||
func (olu BaseOciLayoutUtils) GetImageInfo(repo string, digest godigest.Digest) (ispec.Image, error) {
|
||||
var imageInfo ispec.Image
|
||||
|
||||
var lockLatency time.Time
|
||||
|
||||
imageStore := olu.StoreController.GetImageStore(repo)
|
||||
|
||||
imageStore.RLock(&lockLatency)
|
||||
defer imageStore.RUnlock(&lockLatency)
|
||||
|
||||
blobBuf, err := imageStore.GetBlobContent(repo, digest)
|
||||
if err != nil {
|
||||
olu.Log.Error().Err(err).Msg("unable to open image layers file")
|
||||
@@ -265,6 +281,11 @@ func (olu BaseOciLayoutUtils) GetImageConfigInfo(repo string, manifestDigest god
|
||||
func (olu BaseOciLayoutUtils) GetImageManifestSize(repo string, manifestDigest godigest.Digest) int64 {
|
||||
imageStore := olu.StoreController.GetImageStore(repo)
|
||||
|
||||
var lockLatency time.Time
|
||||
|
||||
imageStore.RLock(&lockLatency)
|
||||
defer imageStore.RUnlock(&lockLatency)
|
||||
|
||||
manifestBlob, err := imageStore.GetBlobContent(repo, manifestDigest)
|
||||
if err != nil {
|
||||
olu.Log.Error().Err(err).Msg("error when getting manifest blob content")
|
||||
|
||||
@@ -322,7 +322,12 @@ func TestSyncInternal(t *testing.T) {
|
||||
Layers: []ispec.Descriptor{desc},
|
||||
}
|
||||
|
||||
sig := newSignaturesCopier(client, *regURL, storage.StoreController{DefaultStore: &local.ImageStoreLocal{}}, log)
|
||||
metrics := monitoring.NewMetricsServer(false, log)
|
||||
imageStore := local.NewImageStore(t.TempDir(), false, storage.DefaultGCDelay,
|
||||
false, false, log, metrics, nil, nil,
|
||||
)
|
||||
|
||||
sig := newSignaturesCopier(client, *regURL, storage.StoreController{DefaultStore: imageStore}, log)
|
||||
|
||||
err = sig.syncCosignSignature(testImage, testImage, testImageTag, &ispec.Manifest{})
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
glob "github.com/bmatcuk/doublestar/v4"
|
||||
@@ -333,6 +334,8 @@ func pushSyncedLocalImage(localRepo, reference, localCachePath string,
|
||||
) error {
|
||||
log.Info().Msgf("pushing synced local image %s/%s:%s to local registry", localCachePath, localRepo, reference)
|
||||
|
||||
var lockLatency time.Time
|
||||
|
||||
metrics := monitoring.NewMetricsServer(false, log)
|
||||
|
||||
cacheImageStore := local.NewImageStore(localCachePath, false,
|
||||
@@ -373,7 +376,10 @@ func pushSyncedLocalImage(localRepo, reference, localCachePath string,
|
||||
}
|
||||
|
||||
for _, manifest := range indexManifest.Manifests {
|
||||
cacheImageStore.RLock(&lockLatency)
|
||||
manifestBuf, err := cacheImageStore.GetBlobContent(localRepo, manifest.Digest)
|
||||
cacheImageStore.RUnlock(&lockLatency)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Str("errorType", TypeOf(err)).
|
||||
Err(err).Str("dir", path.Join(cacheImageStore.RootDir(), localRepo)).Str("digest", manifest.Digest.String()).
|
||||
|
||||
Reference in New Issue
Block a user