Skip to content

Commit f789a29

Browse files
committed
fix(dedupe): use a common blobs dir to simplify
Currently, our dedupe scheme is very complicated since master copy is kept in one of the repo dirs and if that image is deleted, the owning repo is changed, requiring multiple repo locks causing unnecessary contention. Signed-off-by: Ramkumar Chinchani <[email protected]>
1 parent 69e58b0 commit f789a29

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pkg/storage/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ const (
2626
DefaultGCInterval = 1 * time.Hour
2727
S3StorageDriverName = "s3"
2828
LocalStorageDriverName = "local"
29+
GlobalBlobsDir = "_blobs"
2930
)

pkg/storage/imagestore/imagestore.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
zreg "zotregistry.dev/zot/pkg/regexp"
3030
"zotregistry.dev/zot/pkg/scheduler"
3131
common "zotregistry.dev/zot/pkg/storage/common"
32+
"zotregistry.dev/zot/pkg/storage/constants"
3233
storageConstants "zotregistry.dev/zot/pkg/storage/constants"
3334
storageTypes "zotregistry.dev/zot/pkg/storage/types"
3435
"zotregistry.dev/zot/pkg/test/inject"
@@ -1146,22 +1147,35 @@ retry:
11461147
}
11471148

11481149
if dstRecord == "" {
1150+
// cache record doesn't exist, so make a master copy in the hidden global blobs dir
1151+
bdir := path.Join(is.rootDir, constants.GlobalBlobsDir, dstDigest.Algorithm().String())
1152+
_ = is.storeDriver.EnsureDir(bdir)
1153+
1154+
bdst := path.Join(bdir, dstDigest.Encoded())
1155+
11491156
// cache record doesn't exist, so first disk and cache entry for this digest
1150-
if err := is.cache.PutBlob(dstDigest, dst); err != nil {
1157+
if err := is.cache.PutBlob(dstDigest, bdst); err != nil {
11511158
is.log.Error().Err(err).Str("blobPath", dst).Str("component", "dedupe").
11521159
Msg("failed to insert blob record")
11531160

11541161
return err
11551162
}
11561163

11571164
// move the blob from uploads to final dest
1158-
if err := is.storeDriver.Move(src, dst); err != nil {
1165+
if err := is.storeDriver.Move(src, bdst); err != nil {
11591166
is.log.Error().Err(err).Str("src", src).Str("dst", dst).Str("component", "dedupe").
11601167
Msg("failed to rename blob")
11611168

11621169
return err
11631170
}
11641171

1172+
if err := is.storeDriver.Link(bdst, dst); err != nil {
1173+
is.log.Error().Err(err).Str("blobPath", dstRecord).Str("component", "dedupe").
1174+
Msg("failed to link blobs")
1175+
1176+
return err
1177+
}
1178+
11651179
is.log.Debug().Str("src", src).Str("dst", dst).Str("component", "dedupe").Msg("rename")
11661180
} else {
11671181
// cache record exists, but due to GC and upgrades from older versions,

0 commit comments

Comments
 (0)