Skip to content

Commit

Permalink
fix(storage): resolve cache/storage inconsistencies on HEAD request (#…
Browse files Browse the repository at this point in the history
…794)

Signed-off-by: Petu Eusebiu <[email protected]>
  • Loading branch information
eusebiu-constantin-petu-dbk authored Oct 11, 2022
1 parent f3b1913 commit fd87a22
Show file tree
Hide file tree
Showing 3 changed files with 416 additions and 396 deletions.
13 changes: 13 additions & 0 deletions pkg/storage/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,19 @@ func (is *ImageStoreLocal) checkCacheBlob(digest string) (string, error) {

dstRecord = path.Join(is.rootDir, dstRecord)

if _, err := os.Stat(dstRecord); err != nil {
is.log.Error().Err(err).Str("blob", dstRecord).Msg("failed to stat blob")

// the actual blob on disk may have been removed by GC, so sync the cache
if err := is.cache.DeleteBlob(digest, dstRecord); err != nil {
is.log.Error().Err(err).Str("digest", digest).Str("blobPath", dstRecord).Msg("unable to remove blob path from cache")

return "", err
}

return "", zerr.ErrBlobNotFound
}

is.log.Debug().Str("digest", digest).Str("dstRecord", dstRecord).Msg("cache: found dedupe record")

return dstRecord, nil
Expand Down
27 changes: 13 additions & 14 deletions pkg/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,19 @@ func (is *ObjectStorage) checkCacheBlob(digest string) (string, error) {
return "", err
}

if _, err := is.store.Stat(context.Background(), dstRecord); err != nil {
is.log.Error().Err(err).Str("blob", dstRecord).Msg("failed to stat blob")

// the actual blob on disk may have been removed by GC, so sync the cache
if err := is.cache.DeleteBlob(digest, dstRecord); err != nil {
is.log.Error().Err(err).Str("digest", digest).Str("blobPath", dstRecord).Msg("unable to remove blob path from cache")

return "", err
}

return "", zerr.ErrBlobNotFound
}

is.log.Debug().Str("digest", digest).Str("dstRecord", dstRecord).Msg("cache: found dedupe record")

return dstRecord, nil
Expand Down Expand Up @@ -1161,13 +1174,6 @@ func (is *ObjectStorage) GetBlobPartial(repo, digest, mediaType string, from, to
if err != nil {
is.log.Error().Err(err).Str("blob", dstRecord).Msg("failed to stat blob")

// the actual blob on disk may have been removed by GC, so sync the cache
if err := is.cache.DeleteBlob(digest, dstRecord); err != nil {
is.log.Error().Err(err).Str("dstDigest", digest).Str("dst", dstRecord).Msg("dedupe: unable to delete blob record")

return nil, -1, -1, err
}

return nil, -1, -1, zerr.ErrBlobNotFound
}

Expand Down Expand Up @@ -1243,13 +1249,6 @@ func (is *ObjectStorage) GetBlob(repo, digest, mediaType string) (io.ReadCloser,
if err != nil {
is.log.Error().Err(err).Str("blob", dstRecord).Msg("failed to stat blob")

// the actual blob on disk may have been removed by GC, so sync the cache
if err := is.cache.DeleteBlob(digest, dstRecord); err != nil {
is.log.Error().Err(err).Str("dstDigest", digest).Str("dst", dstRecord).Msg("dedupe: unable to delete blob record")

return nil, -1, err
}

return nil, -1, zerr.ErrBlobNotFound
}

Expand Down
Loading

0 comments on commit fd87a22

Please sign in to comment.