@@ -35,10 +35,10 @@ var (
35
35
36
36
// bpDetectCompressionStepData contains data that the copy pipeline needs about the “detect compression” step.
37
37
type bpDetectCompressionStepData struct {
38
- isCompressed bool
39
- format compressiontypes.Algorithm // Valid if isCompressed
40
- decompressor compressiontypes.DecompressorFunc // Valid if isCompressed
41
- srcCompressorName string // Compressor name to possibly record in the blob info cache for the source blob.
38
+ isCompressed bool
39
+ format compressiontypes.Algorithm // Valid if isCompressed
40
+ decompressor compressiontypes.DecompressorFunc // Valid if isCompressed
41
+ srcCompressorBaseVariantName string // Compressor name to possibly record in the blob info cache for the source blob.
42
42
}
43
43
44
44
// blobPipelineDetectCompressionStep updates *stream to detect its current compression format.
@@ -58,9 +58,9 @@ func blobPipelineDetectCompressionStep(stream *sourceStream, srcInfo types.BlobI
58
58
decompressor : decompressor ,
59
59
}
60
60
if res .isCompressed {
61
- res .srcCompressorName = format .Name ()
61
+ res .srcCompressorBaseVariantName = format .BaseVariantName ()
62
62
} else {
63
- res .srcCompressorName = internalblobinfocache .Uncompressed
63
+ res .srcCompressorBaseVariantName = internalblobinfocache .Uncompressed
64
64
}
65
65
66
66
if expectedBaseFormat , known := expectedBaseCompressionFormats [stream .info .MediaType ]; known && res .isCompressed && format .BaseVariantName () != expectedBaseFormat .Name () {
@@ -71,13 +71,13 @@ func blobPipelineDetectCompressionStep(stream *sourceStream, srcInfo types.BlobI
71
71
72
72
// bpCompressionStepData contains data that the copy pipeline needs about the compression step.
73
73
type bpCompressionStepData struct {
74
- operation bpcOperation // What we are actually doing
75
- uploadedOperation types.LayerCompression // Operation to use for updating the blob metadata (matching the end state, not necessarily what we do)
76
- uploadedAlgorithm * compressiontypes.Algorithm // An algorithm parameter for the compressionOperation edits.
77
- uploadedAnnotations map [string ]string // Compression-related annotations that should be set on the uploaded blob. WARNING: This is only set after the srcStream.reader is fully consumed.
78
- srcCompressorName string // Compressor name to record in the blob info cache for the source blob.
79
- uploadedCompressorName string // Compressor name to record in the blob info cache for the uploaded blob.
80
- closers []io.Closer // Objects to close after the upload is done, if any.
74
+ operation bpcOperation // What we are actually doing
75
+ uploadedOperation types.LayerCompression // Operation to use for updating the blob metadata (matching the end state, not necessarily what we do)
76
+ uploadedAlgorithm * compressiontypes.Algorithm // An algorithm parameter for the compressionOperation edits.
77
+ uploadedAnnotations map [string ]string // Compression-related annotations that should be set on the uploaded blob. WARNING: This is only set after the srcStream.reader is fully consumed.
78
+ srcCompressorBaseVariantName string // Compressor base variant name to record in the blob info cache for the source blob.
79
+ uploadedCompressorName string // Compressor name to record in the blob info cache for the uploaded blob.
80
+ closers []io.Closer // Objects to close after the upload is done, if any.
81
81
}
82
82
83
83
type bpcOperation int
@@ -129,11 +129,11 @@ func (ic *imageCopier) bpcPreserveEncrypted(stream *sourceStream, _ bpDetectComp
129
129
// We can’t do anything with an encrypted blob unless decrypted.
130
130
logrus .Debugf ("Using original blob without modification for encrypted blob" )
131
131
return & bpCompressionStepData {
132
- operation : bpcOpPreserveOpaque ,
133
- uploadedOperation : types .PreserveOriginal ,
134
- uploadedAlgorithm : nil ,
135
- srcCompressorName : internalblobinfocache .UnknownCompression ,
136
- uploadedCompressorName : internalblobinfocache .UnknownCompression ,
132
+ operation : bpcOpPreserveOpaque ,
133
+ uploadedOperation : types .PreserveOriginal ,
134
+ uploadedAlgorithm : nil ,
135
+ srcCompressorBaseVariantName : internalblobinfocache .UnknownCompression ,
136
+ uploadedCompressorName : internalblobinfocache .UnknownCompression ,
137
137
}, nil
138
138
}
139
139
return nil , nil
@@ -158,13 +158,13 @@ func (ic *imageCopier) bpcCompressUncompressed(stream *sourceStream, detected bp
158
158
Size : - 1 ,
159
159
}
160
160
return & bpCompressionStepData {
161
- operation : bpcOpCompressUncompressed ,
162
- uploadedOperation : types .Compress ,
163
- uploadedAlgorithm : uploadedAlgorithm ,
164
- uploadedAnnotations : annotations ,
165
- srcCompressorName : detected .srcCompressorName ,
166
- uploadedCompressorName : uploadedAlgorithm .Name (),
167
- closers : []io.Closer {reader },
161
+ operation : bpcOpCompressUncompressed ,
162
+ uploadedOperation : types .Compress ,
163
+ uploadedAlgorithm : uploadedAlgorithm ,
164
+ uploadedAnnotations : annotations ,
165
+ srcCompressorBaseVariantName : detected .srcCompressorBaseVariantName ,
166
+ uploadedCompressorName : uploadedAlgorithm .Name (),
167
+ closers : []io.Closer {reader },
168
168
}, nil
169
169
}
170
170
return nil , nil
@@ -199,13 +199,13 @@ func (ic *imageCopier) bpcRecompressCompressed(stream *sourceStream, detected bp
199
199
}
200
200
succeeded = true
201
201
return & bpCompressionStepData {
202
- operation : bpcOpRecompressCompressed ,
203
- uploadedOperation : types .PreserveOriginal ,
204
- uploadedAlgorithm : ic .compressionFormat ,
205
- uploadedAnnotations : annotations ,
206
- srcCompressorName : detected .srcCompressorName ,
207
- uploadedCompressorName : ic .compressionFormat .Name (),
208
- closers : []io.Closer {decompressed , recompressed },
202
+ operation : bpcOpRecompressCompressed ,
203
+ uploadedOperation : types .PreserveOriginal ,
204
+ uploadedAlgorithm : ic .compressionFormat ,
205
+ uploadedAnnotations : annotations ,
206
+ srcCompressorBaseVariantName : detected .srcCompressorBaseVariantName ,
207
+ uploadedCompressorName : ic .compressionFormat .Name (),
208
+ closers : []io.Closer {decompressed , recompressed },
209
209
}, nil
210
210
}
211
211
return nil , nil
@@ -226,12 +226,12 @@ func (ic *imageCopier) bpcDecompressCompressed(stream *sourceStream, detected bp
226
226
Size : - 1 ,
227
227
}
228
228
return & bpCompressionStepData {
229
- operation : bpcOpDecompressCompressed ,
230
- uploadedOperation : types .Decompress ,
231
- uploadedAlgorithm : nil ,
232
- srcCompressorName : detected .srcCompressorName ,
233
- uploadedCompressorName : internalblobinfocache .Uncompressed ,
234
- closers : []io.Closer {s },
229
+ operation : bpcOpDecompressCompressed ,
230
+ uploadedOperation : types .Decompress ,
231
+ uploadedAlgorithm : nil ,
232
+ srcCompressorBaseVariantName : detected .srcCompressorBaseVariantName ,
233
+ uploadedCompressorName : internalblobinfocache .Uncompressed ,
234
+ closers : []io.Closer {s },
235
235
}, nil
236
236
}
237
237
return nil , nil
@@ -269,11 +269,14 @@ func (ic *imageCopier) bpcPreserveOriginal(_ *sourceStream, detected bpDetectCom
269
269
algorithm = nil
270
270
}
271
271
return & bpCompressionStepData {
272
- operation : bpcOp ,
273
- uploadedOperation : uploadedOp ,
274
- uploadedAlgorithm : algorithm ,
275
- srcCompressorName : detected .srcCompressorName ,
276
- uploadedCompressorName : detected .srcCompressorName ,
272
+ operation : bpcOp ,
273
+ uploadedOperation : uploadedOp ,
274
+ uploadedAlgorithm : algorithm ,
275
+ srcCompressorBaseVariantName : detected .srcCompressorBaseVariantName ,
276
+ // We only record the base variant of the format on upload; we didn’t do anything with
277
+ // the TOC, we don’t know whether it matches the blob digest, so we don’t want to trigger
278
+ // reuse of any kind between the blob digest and the TOC digest.
279
+ uploadedCompressorName : detected .srcCompressorBaseVariantName ,
277
280
}
278
281
}
279
282
@@ -333,9 +336,9 @@ func (d *bpCompressionStepData) recordValidatedDigestData(c *copier, uploadedInf
333
336
return fmt .Errorf ("Internal error: Unexpected d.operation value %#v" , d .operation )
334
337
}
335
338
}
336
- if d .srcCompressorName == "" || d .uploadedCompressorName == "" {
337
- return fmt .Errorf ("internal error: missing compressor names (src: %q, uploaded: %q)" ,
338
- d .srcCompressorName , d .uploadedCompressorName )
339
+ if d .srcCompressorBaseVariantName == "" || d .uploadedCompressorName == "" {
340
+ return fmt .Errorf ("internal error: missing compressor names (src base : %q, uploaded: %q)" ,
341
+ d .srcCompressorBaseVariantName , d .uploadedCompressorName )
339
342
}
340
343
if d .uploadedCompressorName != internalblobinfocache .UnknownCompression {
341
344
if d .uploadedCompressorName != compressiontypes .ZstdChunkedAlgorithmName {
@@ -347,15 +350,19 @@ func (d *bpCompressionStepData) recordValidatedDigestData(c *copier, uploadedInf
347
350
// between zstd and zstd:chunked; so we could, in varying situations over time, call RecordDigestCompressorName
348
351
// with the same digest and both ZstdAlgorithmName and ZstdChunkedAlgorithmName , which causes warnings about
349
352
// inconsistent data to be logged.
350
- c .blobInfoCache .RecordDigestCompressorName (uploadedInfo .Digest , d .uploadedCompressorName )
353
+ c .blobInfoCache .RecordDigestCompressorData (uploadedInfo .Digest , internalblobinfocache.DigestCompressorData {
354
+ BaseVariantCompressor : d .uploadedCompressorName ,
355
+ })
351
356
}
352
357
}
353
358
if srcInfo .Digest != "" && srcInfo .Digest != uploadedInfo .Digest &&
354
- d .srcCompressorName != internalblobinfocache .UnknownCompression {
355
- if d .srcCompressorName != compressiontypes .ZstdChunkedAlgorithmName {
356
- // HACK: Don’t record zstd:chunked algorithms, see above.
357
- c .blobInfoCache .RecordDigestCompressorName (srcInfo .Digest , d .srcCompressorName )
358
- }
359
+ d .srcCompressorBaseVariantName != internalblobinfocache .UnknownCompression {
360
+ // If the source is already using some TOC-dependent variant, we either copied the
361
+ // blob as is, or perhaps decompressed it; either way we don’t trust the TOC digest,
362
+ // so record neither the variant name, nor the TOC digest.
363
+ c .blobInfoCache .RecordDigestCompressorData (srcInfo .Digest , internalblobinfocache.DigestCompressorData {
364
+ BaseVariantCompressor : d .srcCompressorBaseVariantName ,
365
+ })
359
366
}
360
367
return nil
361
368
}
0 commit comments