Skip to content
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

Fix refs ignoring gc labels of contents #2674

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
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
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check if the lease on each ref (not the one in ctx) is effective. The context lease prevents contents are garbage collected during its lifecycle so hides the issue.

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