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 31e2bf9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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
4 changes: 3 additions & 1 deletion cache/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,16 @@ func (cr *cacheRecord) size(ctx context.Context) (int64, error) {
return s, nil
}
driverID := cr.getSnapshotID()
snapshotter := cr.cm.snapshotterFor(cr.cacheMetadata)
if cr.equalMutable != nil {
driverID = cr.equalMutable.getSnapshotID()
snapshotter = cr.cm.snapshotterFor(cr.equalMutable.cacheMetadata)
}
cr.mu.Unlock()
var usage snapshots.Usage
if !cr.getBlobOnly() {
var err error
usage, err = cr.cm.snapshotterFor(cr.cacheMetadata).Usage(ctx, driverID)
usage, err = snapshotter.Usage(ctx, driverID)
if err != nil {
cr.mu.Lock()
isDead := cr.isDead()
Expand Down

0 comments on commit 31e2bf9

Please sign in to comment.