Skip to content

Commit

Permalink
chore(cachedb): move Cache interface to pkg/storage/types
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Aaron <[email protected]>
  • Loading branch information
andaaron committed Jan 26, 2025
1 parent b44cdfd commit 185c55c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
5 changes: 3 additions & 2 deletions pkg/storage/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
zlog "zotregistry.dev/zot/pkg/log"
"zotregistry.dev/zot/pkg/storage/cache"
"zotregistry.dev/zot/pkg/storage/constants"
storageTypes "zotregistry.dev/zot/pkg/storage/types"
)

func CreateCacheDatabaseDriver(storageConfig config.StorageConfig, log zlog.Logger) (cache.Cache, error) {
func CreateCacheDatabaseDriver(storageConfig config.StorageConfig, log zlog.Logger) (storageTypes.Cache, error) {
if !storageConfig.Dedupe && storageConfig.StorageDriver == nil {
return nil, nil //nolint:nilnil
}
Expand Down Expand Up @@ -70,7 +71,7 @@ func CreateCacheDatabaseDriver(storageConfig config.StorageConfig, log zlog.Logg
return nil, nil //nolint:nilnil
}

func Create(dbtype string, parameters interface{}, log zlog.Logger) (cache.Cache, error) {
func Create(dbtype string, parameters interface{}, log zlog.Logger) (storageTypes.Cache, error) {
switch dbtype {
case "boltdb":
{
Expand Down
11 changes: 6 additions & 5 deletions pkg/storage/cache_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"zotregistry.dev/zot/pkg/log"
"zotregistry.dev/zot/pkg/storage"
"zotregistry.dev/zot/pkg/storage/cache"
storageTypes "zotregistry.dev/zot/pkg/storage/types"
test "zotregistry.dev/zot/pkg/test/common"
)

Expand Down Expand Up @@ -44,31 +45,31 @@ func generateData() map[godigest.Digest]string {
return dataMap
}

func helperPutAll(cache cache.Cache, testData map[godigest.Digest]string) {
func helperPutAll(cache storageTypes.Cache, testData map[godigest.Digest]string) {
for digest, path := range testData {
_ = cache.PutBlob(digest, path)
}
}

func helperDeleteAll(cache cache.Cache, testData map[godigest.Digest]string) {
func helperDeleteAll(cache storageTypes.Cache, testData map[godigest.Digest]string) {
for digest, path := range testData {
_ = cache.DeleteBlob(digest, path)
}
}

func helperHasAll(cache cache.Cache, testData map[godigest.Digest]string) {
func helperHasAll(cache storageTypes.Cache, testData map[godigest.Digest]string) {
for digest, path := range testData {
_ = cache.HasBlob(digest, path)
}
}

func helperGetAll(cache cache.Cache, testData map[godigest.Digest]string) {
func helperGetAll(cache storageTypes.Cache, testData map[godigest.Digest]string) {
for digest := range testData {
_, _ = cache.GetBlob(digest)
}
}

func helperMix(cache cache.Cache, testData map[godigest.Digest]string, digestSlice []godigest.Digest) {
func helperMix(cache storageTypes.Cache, testData map[godigest.Digest]string, digestSlice []godigest.Digest) {
// The test data contains datasetSize entries by default, and each set of operations uses 5 entries
for i := 0; i < 1000; i++ {
_ = cache.PutBlob(digestSlice[i*5], testData[digestSlice[i*5]])
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/imagestore/imagestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
zlog "zotregistry.dev/zot/pkg/log"
zreg "zotregistry.dev/zot/pkg/regexp"
"zotregistry.dev/zot/pkg/scheduler"
"zotregistry.dev/zot/pkg/storage/cache"
common "zotregistry.dev/zot/pkg/storage/common"
storageConstants "zotregistry.dev/zot/pkg/storage/constants"
storageTypes "zotregistry.dev/zot/pkg/storage/types"
Expand All @@ -46,7 +45,7 @@ type ImageStore struct {
lock *sync.RWMutex
log zlog.Logger
metrics monitoring.MetricServer
cache cache.Cache
cache storageTypes.Cache
dedupe bool
linter common.Lint
commit bool
Expand All @@ -70,7 +69,7 @@ func (is *ImageStore) DirExists(d string) bool {
// Use the last argument to properly set a cache database, or it will default to boltDB local storage.
func NewImageStore(rootDir string, cacheDir string, dedupe, commit bool, log zlog.Logger,
metrics monitoring.MetricServer, linter common.Lint, storeDriver storageTypes.Driver,
cacheDriver cache.Cache, compat []compat.MediaCompatibility,
cacheDriver storageTypes.Cache, compat []compat.MediaCompatibility,
) storageTypes.ImageStore {
if err := storeDriver.EnsureDir(rootDir); err != nil {
log.Error().Err(err).Str("rootDir", rootDir).Msg("failed to create root dir")
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"zotregistry.dev/zot/pkg/compat"
"zotregistry.dev/zot/pkg/extensions/monitoring"
zlog "zotregistry.dev/zot/pkg/log"
"zotregistry.dev/zot/pkg/storage/cache"
common "zotregistry.dev/zot/pkg/storage/common"
"zotregistry.dev/zot/pkg/storage/imagestore"
storageTypes "zotregistry.dev/zot/pkg/storage/types"
Expand All @@ -13,7 +12,7 @@ import (
// NewImageStore returns a new image store backed by a file storage.
// Use the last argument to properly set a cache database, or it will default to boltDB local storage.
func NewImageStore(rootDir string, dedupe, commit bool, log zlog.Logger,
metrics monitoring.MetricServer, linter common.Lint, cacheDriver cache.Cache,
metrics monitoring.MetricServer, linter common.Lint, cacheDriver storageTypes.Cache,
compat []compat.MediaCompatibility,
) storageTypes.ImageStore {
return imagestore.NewImageStore(
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"zotregistry.dev/zot/pkg/compat"
"zotregistry.dev/zot/pkg/extensions/monitoring"
zlog "zotregistry.dev/zot/pkg/log"
"zotregistry.dev/zot/pkg/storage/cache"
common "zotregistry.dev/zot/pkg/storage/common"
"zotregistry.dev/zot/pkg/storage/imagestore"
storageTypes "zotregistry.dev/zot/pkg/storage/types"
Expand All @@ -20,7 +19,7 @@ import (
// Use the last argument to properly set a cache database, or it will default to boltDB local storage.
func NewImageStore(rootDir string, cacheDir string, dedupe, commit bool, log zlog.Logger,
metrics monitoring.MetricServer, linter common.Lint, store driver.StorageDriver,
cacheDriver cache.Cache, compat []compat.MediaCompatibility,
cacheDriver storageTypes.Cache, compat []compat.MediaCompatibility,
) storageTypes.ImageStore {
return imagestore.NewImageStore(
rootDir,
Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func createMockStorage(rootDir string, cacheDir string, dedupe bool, store drive
log := log.Logger{Logger: zerolog.New(os.Stdout)}
metrics := monitoring.NewMetricsServer(true, log)

var cacheDriver cache.Cache
var cacheDriver storageTypes.Cache

// from pkg/cli/server/root.go/applyDefaultValues, s3 magic
if _, err := os.Stat(path.Join(cacheDir,
Expand All @@ -81,7 +81,7 @@ func createMockStorage(rootDir string, cacheDir string, dedupe bool, store drive
}

func createMockStorageWithMockCache(rootDir string, dedupe bool, store driver.StorageDriver,
cacheDriver cache.Cache,
cacheDriver storageTypes.Cache,
) storageTypes.ImageStore {
log := log.Logger{Logger: zerolog.New(os.Stdout)}
metrics := monitoring.NewMetricsServer(false, log)
Expand Down Expand Up @@ -133,7 +133,7 @@ func createObjectsStore(rootDir string, cacheDir string, dedupe bool) (
log := log.Logger{Logger: zerolog.New(os.Stdout)}
metrics := monitoring.NewMetricsServer(false, log)

var cacheDriver cache.Cache
var cacheDriver storageTypes.Cache

var err error

Expand Down Expand Up @@ -162,7 +162,7 @@ func createObjectsStoreDynamo(rootDir string, cacheDir string, dedupe bool, tabl
log := log.Logger{Logger: zerolog.New(os.Stdout)}
metrics := monitoring.NewMetricsServer(false, log)

var cacheDriver cache.Cache
var cacheDriver storageTypes.Cache

// from pkg/cli/server/root.go/applyDefaultValues, s3 magic
tableName = strings.ReplaceAll(tableName, "/", "")
Expand Down
10 changes: 5 additions & 5 deletions pkg/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ type createObjectStoreOpts struct {
}

func createObjectsStore(options createObjectStoreOpts) (
storageTypes.Driver, storageTypes.ImageStore, cache.Cache, error,
storageTypes.Driver, storageTypes.ImageStore, storageTypes.Cache, error,
) {
var (
cacheDriver cache.Cache
cacheDriver storageTypes.Cache
useRelPaths bool
)

Expand Down Expand Up @@ -1043,7 +1043,7 @@ func TestMandatoryAnnotations(t *testing.T) {
testDir = path.Join("/oci-repo-test", uuid.String())
opts.rootDir = testDir

var cacheDriver cache.Cache
var cacheDriver storageTypes.Cache
store, _, cacheDriver, _ = createObjectsStore(opts)

imgStore = imagestore.NewImageStore(testDir, cacheDir, false, false, log, metrics,
Expand All @@ -1055,7 +1055,7 @@ func TestMandatoryAnnotations(t *testing.T) {

defer cleanupStorage(store, testDir)
} else {
var cacheDriver cache.Cache
var cacheDriver storageTypes.Cache
store, _, cacheDriver, _ = createObjectsStore(opts)

imgStore = imagestore.NewImageStore(cacheDir, cacheDir, true, true, log, metrics,
Expand Down Expand Up @@ -1118,7 +1118,7 @@ func TestMandatoryAnnotations(t *testing.T) {
},
}, store, nil, nil)
} else {
var cacheDriver cache.Cache
var cacheDriver storageTypes.Cache
store, _, cacheDriver, _ = createObjectsStore(opts)

imgStore = imagestore.NewImageStore(cacheDir, cacheDir, true, true, log, metrics,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cache
package types

import (
godigest "github.com/opencontainers/go-digest"
Expand Down

0 comments on commit 185c55c

Please sign in to comment.