Skip to content

Commit

Permalink
Pass a whole blobinfocache.DigestCompressorData to CandidateTemplateW…
Browse files Browse the repository at this point in the history
…ithCompression

This is why we introduced DigestCompressorData in the first place, so that
this function can easily work with the full information.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Jul 27, 2024
1 parent 09131f2 commit ceabfec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
6 changes: 5 additions & 1 deletion pkg/blobinfocache/boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ func (bdc *cache) appendReplacementCandidates(candidates []prioritize.CandidateW
compressorName = string(compressorNameValue)
}
}
template := prioritize.CandidateTemplateWithCompression(v2Options, digest, compressorName)
template := prioritize.CandidateTemplateWithCompression(v2Options, digest, blobinfocache.DigestCompressorData{
BaseVariantCompressor: compressorName,
SpecificVariantCompressor: blobinfocache.UnknownCompression,
SpecificVariantAnnotations: nil,
})
if template == nil {
return candidates
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/blobinfocache/internal/prioritize/prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const replacementAttempts = 5
// This is a heuristic/guess, and could well use a different value.
const replacementUnknownLocationAttempts = 2

// CandidateTemplateWithCompression returns a partially-filled BICReplacementCandidate2 if a blob
// with compressionName (which can be Uncompressed or UnknownCompression) is acceptable for a CandidateLocations* call with v2Options.
// CandidateTemplateWithCompression returns a partially-filled BICReplacementCandidate2 if a blob
// with data is acceptable for a CandidateLocations* call with v2Options.
//
// v2Options can be set to nil if the call is CandidateLocations (i.e. compression is not required to be known);
// if not nil, the call is assumed to be CandidateLocations2.
//
// The returned value is suitable for CandidateWithLocation and CandidateWithUnknownLocation.
func CandidateTemplateWithCompression(v2Options *blobinfocache.CandidateLocations2Options, digest digest.Digest, compressorName string) *blobinfocache.BICReplacementCandidate2 {
func CandidateTemplateWithCompression(v2Options *blobinfocache.CandidateLocations2Options, digest digest.Digest, data blobinfocache.DigestCompressorData) *blobinfocache.BICReplacementCandidate2 {
if v2Options == nil {
return &blobinfocache.BICReplacementCandidate2{ // Anything goes. The CompressionOperation, CompressionAlgorithm values are not used.
Digest: digest,
Expand All @@ -46,7 +46,7 @@ func CandidateTemplateWithCompression(v2Options *blobinfocache.CandidateLocation
if v2Options.RequiredCompression != nil {
requiredCompression = v2Options.RequiredCompression.Name()
}
switch compressorName {
switch data.BaseVariantCompressor {
case blobinfocache.Uncompressed:
if !manifest.CandidateCompressionMatchesReuseConditions(manifest.ReuseConditions{
PossibleManifestFormats: v2Options.PossibleManifestFormats,
Expand All @@ -66,10 +66,10 @@ func CandidateTemplateWithCompression(v2Options *blobinfocache.CandidateLocation
logrus.Debugf("Ignoring BlobInfoCache record of digest %q with unknown compression", digest.String())
return nil // Not allowed with CandidateLocations2
default:
algo, err := compression.AlgorithmByName(compressorName)
algo, err := compression.AlgorithmByName(data.BaseVariantCompressor)
if err != nil {
logrus.Debugf("Ignoring BlobInfoCache record of digest %q with unrecognized compression %q: %v",
digest.String(), compressorName, err)
digest.String(), data.BaseVariantCompressor, err)
return nil // The BICReplacementCandidate2.CompressionAlgorithm field is required
}

Expand All @@ -78,7 +78,7 @@ func CandidateTemplateWithCompression(v2Options *blobinfocache.CandidateLocation
RequiredCompression: v2Options.RequiredCompression,
}, &algo) {
logrus.Debugf("Ignoring BlobInfoCache record of digest %q, compression %q does not match required %s or MIME types %#v",
digest.String(), compressorName, requiredCompression, v2Options.PossibleManifestFormats)
digest.String(), data.BaseVariantCompressor, requiredCompression, v2Options.PossibleManifestFormats)
return nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/blobinfocache/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ func (mem *cache) appendReplacementCandidates(candidates []prioritize.CandidateW
if v, ok := mem.compressors[digest]; ok {
compressorName = v
}
template := prioritize.CandidateTemplateWithCompression(v2Options, digest, compressorName)
template := prioritize.CandidateTemplateWithCompression(v2Options, digest, blobinfocache.DigestCompressorData{
BaseVariantCompressor: compressorName,
SpecificVariantCompressor: blobinfocache.UnknownCompression,
SpecificVariantAnnotations: nil,
})
if template == nil {
return candidates
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/blobinfocache/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,11 @@ func (sqc *cache) appendReplacementCandidates(candidates []prioritize.CandidateW
compressorName = compressor
}
}
template := prioritize.CandidateTemplateWithCompression(v2Options, digest, compressorName)
template := prioritize.CandidateTemplateWithCompression(v2Options, digest, blobinfocache.DigestCompressorData{
BaseVariantCompressor: compressorName,
SpecificVariantCompressor: blobinfocache.UnknownCompression,
SpecificVariantAnnotations: nil,
})
if template == nil {
return candidates, nil
}
Expand Down

0 comments on commit ceabfec

Please sign in to comment.