Skip to content

refactor: remove usage of goto in the image store #2969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions pkg/storage/imagestore/imagestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,35 +1125,38 @@ func (is *ImageStore) FullBlobUpload(repo string, body io.Reader, dstDigest godi
}

func (is *ImageStore) DedupeBlob(src string, dstDigest godigest.Digest, dstRepo string, dst string) error {
retry:
is.log.Debug().Str("src", src).Str("dstDigest", dstDigest.String()).Str("dst", dst).Msg("dedupe begin")
for {
is.log.Debug().Str("src", src).Str("dstDigest", dstDigest.String()).Str("dst", dst).Msg("dedupe begin")

dstRecord, err := is.cache.GetBlob(dstDigest)
if err := inject.Error(err); err != nil && !errors.Is(err, zerr.ErrCacheMiss) {
is.log.Error().Err(err).Str("blobPath", dst).Str("component", "dedupe").Msg("failed to lookup blob record")

return err
}

if dstRecord == "" {
// cache record doesn't exist, so first disk and cache entry for this digest
if err := is.cache.PutBlob(dstDigest, dst); err != nil {
is.log.Error().Err(err).Str("blobPath", dst).Str("component", "dedupe").
Msg("failed to insert blob record")
dstRecord, err := is.cache.GetBlob(dstDigest)
if err := inject.Error(err); err != nil && !errors.Is(err, zerr.ErrCacheMiss) {
is.log.Error().Err(err).Str("blobPath", dst).Str("component", "dedupe").Msg("failed to lookup blob record")

return err
}

// move the blob from uploads to final dest
if err := is.storeDriver.Move(src, dst); err != nil {
is.log.Error().Err(err).Str("src", src).Str("dst", dst).Str("component", "dedupe").
Msg("failed to rename blob")
if dstRecord == "" {
// cache record doesn't exist, so first disk and cache entry for this digest
if err := is.cache.PutBlob(dstDigest, dst); err != nil {
is.log.Error().Err(err).Str("blobPath", dst).Str("component", "dedupe").
Msg("failed to insert blob record")

return err
return err
}

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

return err
}

is.log.Debug().Str("src", src).Str("dst", dst).Str("component", "dedupe").Msg("rename")

return nil
}

is.log.Debug().Str("src", src).Str("dst", dst).Str("component", "dedupe").Msg("rename")
} else {
// cache record exists, but due to GC and upgrades from older versions,
// disk content and cache records may go out of sync
if is.cache.UsesRelativePaths() {
Expand All @@ -1173,7 +1176,7 @@ retry:
return err
}

goto retry
continue
}

// prevent overwrite original blob
Expand Down Expand Up @@ -1219,9 +1222,9 @@ retry:
}

is.log.Debug().Str("src", src).Str("component", "dedupe").Msg("remove")
}

return nil
return nil
}
}

// DeleteBlobUpload deletes an existing blob upload that is currently in progress.
Expand Down
Loading