Skip to content

Commit

Permalink
fix bug that caused mutable refs to have size 0
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Sipsma <[email protected]>
  • Loading branch information
sipsma committed Aug 1, 2024
1 parent 058da20 commit 160689c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 7 additions & 3 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1440,14 +1440,18 @@ func (cm *cacheManager) DiskUsage(ctx context.Context, opt client.DiskUsageInfo)
func(d *client.UsageInfo) {
eg.Go(func() error {
cm.mu.Lock()
ref, err := cm.get(ctx, d.ID, nil, NoUpdateLastUsed)
// TODO: note about this change, do upstream too? May be real bug fix
// previous code was getting equalImmutable of mutable refs and setting size to 0
// ref, err := cm.get(ctx, d.ID, nil, NoUpdateLastUsed)
rec, err := cm.getRecord(ctx, d.ID, NoUpdateLastUsed)
cm.mu.Unlock()
if err != nil {
d.Size = 0
return nil
}
defer ref.Release(context.TODO())
s, err := ref.size(ctx)
// defer ref.Release(context.TODO())
// s, err := ref.size(ctx)
s, err := rec.size(ctx)
if err != nil {
return err
}
Expand Down
12 changes: 10 additions & 2 deletions cache/manager_dagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (cm *cacheManager) GetOrInitVolume(
}
parentID := ""

rec, err := func() (*cacheRecord, error) {
rec, err := func() (_ *cacheRecord, rerr error) {
cm.mu.Lock()
defer cm.mu.Unlock()

Expand All @@ -90,8 +90,9 @@ func (cm *cacheManager) GetOrInitVolume(
if err != nil {
return nil, fmt.Errorf("failed to create lease: %w", err)
}
// TODO: this defer should run outside this function too
defer func() {
if err != nil {
if rerr != nil {
ctx := context.WithoutCancel(ctx)
if err := cm.LeaseManager.Delete(ctx, leases.Lease{
ID: l.ID,
Expand Down Expand Up @@ -131,6 +132,10 @@ func (cm *cacheManager) GetOrInitVolume(
if err := initializeMetadata(rec.cacheMetadata, rec.parentRefs, opts...); err != nil {
return nil, err
}
// this is needed because for some reason snapshotID is an imageRefOption
if err := setImageRefMetadata(rec.cacheMetadata, opts...); err != nil {
return nil, fmt.Errorf("failed to append image ref metadata to ref %s: %w", id, err)
}

cm.records[id] = rec
return rec, nil
Expand All @@ -139,6 +144,9 @@ func (cm *cacheManager) GetOrInitVolume(
return nil, fmt.Errorf("failed to get volume cache record: %w", err)
}
}()
if err != nil {
return nil, err
}

releaseFunc, err := cm.volumeSnapshotter.Acquire(ctx, id, sharingMode)
if err != nil {
Expand Down

0 comments on commit 160689c

Please sign in to comment.