Skip to content

Commit

Permalink
Merge pull request #2425 from sipsma/refinalize
Browse files Browse the repository at this point in the history
Re-add Finalize method to ImmutableRef.
  • Loading branch information
tonistiigi authored Oct 25, 2021
2 parents f352ee8 + 3adb271 commit 33fb83e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cache/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (sr *immutableRef) computeBlobChain(ctx context.Context, createIfNeeded boo
return errors.Errorf("missing lease requirement for computeBlobChain")
}

if err := sr.finalizeLocked(ctx); err != nil {
if err := sr.Finalize(ctx); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispecs.Descriptor,
chainID = imagespecidentity.ChainID([]digest.Digest{p.getChainID(), chainID})
blobChainID = imagespecidentity.ChainID([]digest.Digest{p.getBlobChainID(), blobChainID})

if err := p.finalizeLocked(ctx); err != nil {
if err := p.Finalize(ctx); err != nil {
p.Release(context.TODO())
return nil, err
}
Expand Down Expand Up @@ -467,7 +467,7 @@ func (cm *cacheManager) New(ctx context.Context, s ImmutableRef, sess session.Gr
}
parent = p.(*immutableRef)
}
if err := parent.finalizeLocked(ctx); err != nil {
if err := parent.Finalize(ctx); err != nil {
return nil, err
}
if err := parent.Extract(ctx, sess); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestManager(t *testing.T) {

checkDiskUsage(ctx, t, cm, 1, 0)

err = snap.(*immutableRef).finalizeLocked(ctx)
err = snap.Finalize(ctx)
require.NoError(t, err)

err = snap.Release(ctx)
Expand Down Expand Up @@ -948,7 +948,7 @@ func TestLazyCommit(t *testing.T) {
require.NoError(t, err)

// this time finalize commit
err = snap.(*immutableRef).finalizeLocked(ctx)
err = snap.Finalize(ctx)
require.NoError(t, err)

err = snap.Release(ctx)
Expand Down Expand Up @@ -1022,7 +1022,7 @@ func TestLazyCommit(t *testing.T) {
snap2, err = cm.Get(ctx, snap.ID())
require.NoError(t, err)

err = snap2.(*immutableRef).finalizeLocked(ctx)
err = snap2.Finalize(ctx)
require.NoError(t, err)

err = snap2.Release(ctx)
Expand Down
5 changes: 4 additions & 1 deletion cache/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type ImmutableRef interface {
Ref
Parent() ImmutableRef
Clone() ImmutableRef
// Finalize commits the snapshot to the driver if it's not already.
// This means the snapshot can no longer be mounted as mutable.
Finalize(context.Context) error

Extract(ctx context.Context, s session.Group) error // +progress
GetRemote(ctx context.Context, createIfNeeded bool, compressionType compression.Type, forceCompression bool, s session.Group) (*solver.Remote, error)
Expand Down Expand Up @@ -818,7 +821,7 @@ func (sr *immutableRef) release(ctx context.Context) error {
return nil
}

func (sr *immutableRef) finalizeLocked(ctx context.Context) error {
func (sr *immutableRef) Finalize(ctx context.Context) error {
sr.mu.Lock()
defer sr.mu.Unlock()
return sr.finalize(ctx)
Expand Down

0 comments on commit 33fb83e

Please sign in to comment.