Skip to content

Commit

Permalink
Merge pull request #2674 from ktock/variantlease
Browse files Browse the repository at this point in the history
Fix refs ignoring gc labels of contents
  • Loading branch information
tonistiigi authored Feb 25, 2022
2 parents 27cc24a + ec09df1 commit b9657e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 2 additions & 6 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,10 +1266,6 @@ func TestSharingCompressionVariant(t *testing.T) {
require.NoError(t, err)
defer cleanup()

ctx, done, err := leaseutil.WithLease(ctx, co.lm, leaseutil.MakeTemporary)
require.NoError(t, err)
defer done(context.TODO())

allCompressions := []compression.Type{compression.Uncompressed, compression.Gzip, compression.Zstd, compression.EStargz}

do := func(test func(testCaseSharingCompressionVariant)) {
Expand Down Expand Up @@ -1382,7 +1378,7 @@ func testSharingCompressionVariant(ctx context.Context, t *testing.T, co *cmOut,
require.NoError(t, err)
defer aRef.Release(ctx)
var bDesc ocispecs.Descriptor
for _, compressionType := range testCase.aVariants {
for _, compressionType := range append([]compression.Type{testCase.a}, testCase.aVariants...) {
remotes, err := aRef.GetRemotes(ctx, true, config.RefConfig{Compression: compression.New(compressionType).SetForce(true)}, false, nil)
require.NoError(t, err)
require.Equal(t, 1, len(remotes))
Expand All @@ -1395,7 +1391,7 @@ func testSharingCompressionVariant(ctx context.Context, t *testing.T, co *cmOut,
bRef, err := cm.GetByBlob(ctx, bDesc, nil, descHandlers)
require.NoError(t, err)
defer bRef.Release(ctx)
for _, compressionType := range testCase.bVariants {
for _, compressionType := range append([]compression.Type{testCase.b}, testCase.bVariants...) {
remotes, err := bRef.GetRemotes(ctx, true, config.RefConfig{Compression: compression.New(compressionType).SetForce(true)}, false, nil)
require.NoError(t, err)
require.Equal(t, 1, len(remotes))
Expand Down
22 changes: 22 additions & 0 deletions cache/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ func (cr *cacheRecord) viewLeaseID() string {
return cr.ID() + "-view"
}

func (cr *cacheRecord) compressionVariantsLeaseID() string {
return cr.ID() + "-variants"
}

func (cr *cacheRecord) viewSnapshotID() string {
return cr.getSnapshotID() + "-view"
}
Expand Down Expand Up @@ -438,6 +442,11 @@ func (cr *cacheRecord) remove(ctx context.Context, removeSnapshot bool) error {
}); err != nil && !errdefs.IsNotFound(err) {
return errors.Wrapf(err, "failed to delete lease for %s", cr.ID())
}
if err := cr.cm.LeaseManager.Delete(ctx, leases.Lease{
ID: cr.compressionVariantsLeaseID(),
}); err != nil && !errdefs.IsNotFound(err) {
return errors.Wrapf(err, "failed to delete compression variant lease for %s", cr.ID())
}
}
if err := cr.cm.MetadataStore.Clear(cr.ID()); err != nil {
return errors.Wrapf(err, "failed to delete metadata of %s", cr.ID())
Expand Down Expand Up @@ -699,6 +708,19 @@ const (
// this ref. This doesn't record the blob to the cache record (i.e. the passed blob can't
// be acquired through getBlob). Use setBlob for that purpose.
func (sr *immutableRef) linkBlob(ctx context.Context, desc ocispecs.Descriptor) error {
if _, err := sr.cm.LeaseManager.Create(ctx, func(l *leases.Lease) error {
l.ID = sr.compressionVariantsLeaseID()
// do not make it flat lease to allow linking blobs using gc label
return nil
}); err != nil && !errdefs.IsAlreadyExists(err) {
return err
}
if err := sr.cm.LeaseManager.AddResource(ctx, leases.Lease{ID: sr.compressionVariantsLeaseID()}, leases.Resource{
ID: desc.Digest.String(),
Type: "content",
}); err != nil {
return err
}
cs := sr.cm.ContentStore
blobDigest := sr.getBlob()
info, err := cs.Info(ctx, blobDigest)
Expand Down

0 comments on commit b9657e3

Please sign in to comment.