mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 12:28:01 +08:00
feat(storage): rebuild storage(s3/local) dedupe index when switching dedupe status (#1062)
Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package mocks
|
||||
|
||||
import godigest "github.com/opencontainers/go-digest"
|
||||
|
||||
type CacheMock struct {
|
||||
// Returns the human-readable "name" of the driver.
|
||||
NameFn func() string
|
||||
|
||||
// Retrieves the blob matching provided digest.
|
||||
GetBlobFn func(digest godigest.Digest) (string, error)
|
||||
|
||||
// Uploads blob to cachedb.
|
||||
PutBlobFn func(digest godigest.Digest, path string) error
|
||||
|
||||
// Check if blob exists in cachedb.
|
||||
HasBlobFn func(digest godigest.Digest, path string) bool
|
||||
|
||||
// Delete a blob from the cachedb.
|
||||
DeleteBlobFn func(digest godigest.Digest, path string) error
|
||||
}
|
||||
|
||||
func (cacheMock CacheMock) Name() string {
|
||||
if cacheMock.NameFn != nil {
|
||||
return cacheMock.NameFn()
|
||||
}
|
||||
|
||||
return "mock"
|
||||
}
|
||||
|
||||
func (cacheMock CacheMock) GetBlob(digest godigest.Digest) (string, error) {
|
||||
if cacheMock.GetBlobFn != nil {
|
||||
return cacheMock.GetBlobFn(digest)
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (cacheMock CacheMock) PutBlob(digest godigest.Digest, path string) error {
|
||||
if cacheMock.PutBlobFn != nil {
|
||||
return cacheMock.PutBlobFn(digest, path)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cacheMock CacheMock) HasBlob(digest godigest.Digest, path string) bool {
|
||||
if cacheMock.HasBlobFn != nil {
|
||||
return cacheMock.HasBlobFn(digest, path)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (cacheMock CacheMock) DeleteBlob(digest godigest.Digest, path string) error {
|
||||
if cacheMock.DeleteBlobFn != nil {
|
||||
return cacheMock.DeleteBlobFn(digest, path)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -36,15 +36,19 @@ type MockedImageStore struct {
|
||||
CheckBlobFn func(repo string, digest godigest.Digest) (bool, int64, error)
|
||||
GetBlobPartialFn func(repo string, digest godigest.Digest, mediaType string, from, to int64,
|
||||
) (io.ReadCloser, int64, int64, error)
|
||||
GetBlobFn func(repo string, digest godigest.Digest, mediaType string) (io.ReadCloser, int64, error)
|
||||
DeleteBlobFn func(repo string, digest godigest.Digest) error
|
||||
GetIndexContentFn func(repo string) ([]byte, error)
|
||||
GetBlobContentFn func(repo string, digest godigest.Digest) ([]byte, error)
|
||||
GetReferrersFn func(repo string, digest godigest.Digest, artifactTypes []string) (ispec.Index, error)
|
||||
GetOrasReferrersFn func(repo string, digest godigest.Digest, artifactType string) ([]artifactspec.Descriptor, error)
|
||||
URLForPathFn func(path string) (string, error)
|
||||
RunGCRepoFn func(repo string) error
|
||||
RunGCPeriodicallyFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
GetBlobFn func(repo string, digest godigest.Digest, mediaType string) (io.ReadCloser, int64, error)
|
||||
DeleteBlobFn func(repo string, digest godigest.Digest) error
|
||||
GetIndexContentFn func(repo string) ([]byte, error)
|
||||
GetBlobContentFn func(repo string, digest godigest.Digest) ([]byte, error)
|
||||
GetReferrersFn func(repo string, digest godigest.Digest, artifactTypes []string) (ispec.Index, error)
|
||||
GetOrasReferrersFn func(repo string, digest godigest.Digest, artifactType string,
|
||||
) ([]artifactspec.Descriptor, error)
|
||||
URLForPathFn func(path string) (string, error)
|
||||
RunGCRepoFn func(repo string) error
|
||||
RunGCPeriodicallyFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
RunDedupeBlobsFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
RunDedupeForDigestFn func(digest godigest.Digest, dedupe bool, duplicateBlobs []string) error
|
||||
GetNextDigestWithBlobPathsFn func(lastDigests []godigest.Digest) (godigest.Digest, []string, error)
|
||||
}
|
||||
|
||||
func (is MockedImageStore) Lock(t *time.Time) {
|
||||
@@ -332,3 +336,26 @@ func (is MockedImageStore) RunGCPeriodically(interval time.Duration, sch *schedu
|
||||
is.RunGCPeriodicallyFn(interval, sch)
|
||||
}
|
||||
}
|
||||
|
||||
func (is MockedImageStore) RunDedupeBlobs(interval time.Duration, sch *scheduler.Scheduler) {
|
||||
if is.RunDedupeBlobsFn != nil {
|
||||
is.RunDedupeBlobsFn(interval, sch)
|
||||
}
|
||||
}
|
||||
|
||||
func (is MockedImageStore) RunDedupeForDigest(digest godigest.Digest, dedupe bool, duplicateBlobs []string) error {
|
||||
if is.RunDedupeForDigestFn != nil {
|
||||
return is.RunDedupeForDigestFn(digest, dedupe, duplicateBlobs)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (is MockedImageStore) GetNextDigestWithBlobPaths(lastDigests []godigest.Digest,
|
||||
) (godigest.Digest, []string, error) {
|
||||
if is.GetNextDigestWithBlobPathsFn != nil {
|
||||
return is.GetNextDigestWithBlobPathsFn(lastDigests)
|
||||
}
|
||||
|
||||
return "", []string{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user