Skip to content

Commit 915430b

Browse files
bundle/deploy/lock: own *locker.Locker on the lock object, not on bundle.Bundle
Pre-refactor the locker was stashed on b.Locker so the two mutators (acquire then release) could share it via the Bundle. After PR #5314 both lifecycle methods live on a single struct, so the cross-method state-passing through bundle.Bundle is redundant — grep finds zero external consumers of b.Locker. Move the *locker.Locker to a field on workspaceFilesystemLock and delete the now-unused Locker field on bundle.Bundle. Co-authored-by: Isaac
1 parent 09f9090 commit 915430b

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

bundle/bundle.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/databricks/cli/libs/auth"
2222
"github.com/databricks/cli/libs/cache"
2323
"github.com/databricks/cli/libs/fileset"
24-
"github.com/databricks/cli/libs/locker"
2524
"github.com/databricks/cli/libs/log"
2625
"github.com/databricks/cli/libs/logdiag"
2726
libsync "github.com/databricks/cli/libs/sync"
@@ -129,9 +128,6 @@ type Bundle struct {
129128
// Stores an initialized copy of this bundle's Terraform wrapper.
130129
Terraform *tfexec.Terraform
131130

132-
// Stores the locker responsible for acquiring/releasing a deployment lock.
133-
Locker *locker.Locker
134-
135131
// TerraformPlanPath is the path to the plan from the terraform CLI
136132
TerraformPlanPath string
137133

bundle/deploy/lock/workspace_filesystem.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import (
1515
// bundle's workspace state path. This preserves the historical behavior of
1616
// the previous lock.Acquire / lock.Release mutators.
1717
type workspaceFilesystemLock struct {
18-
b *bundle.Bundle
19-
goal Goal
18+
// b is retained for the workspace client and the permissions reporter on
19+
// the Acquire error path; lock state itself lives on the struct.
20+
b *bundle.Bundle
21+
locker *locker.Locker
22+
goal Goal
2023
}
2124

2225
func newWorkspaceFilesystemLock(b *bundle.Bundle, goal Goal) *workspaceFilesystemLock {
@@ -39,7 +42,7 @@ func (l *workspaceFilesystemLock) Acquire(ctx context.Context) error {
3942
return err
4043
}
4144

42-
b.Locker = lk
45+
l.locker = lk
4346

4447
force := b.Config.Bundle.Deployment.Lock.Force
4548
log.Infof(ctx, "Acquiring deployment lock (force: %v)", force)
@@ -61,24 +64,22 @@ func (l *workspaceFilesystemLock) Acquire(ctx context.Context) error {
6164
}
6265

6366
func (l *workspaceFilesystemLock) Release(ctx context.Context, _ DeploymentStatus) error {
64-
b := l.b
65-
6667
// Return early if locking is disabled.
67-
if !b.Config.Bundle.Deployment.Lock.IsEnabled() {
68+
if !l.b.Config.Bundle.Deployment.Lock.IsEnabled() {
6869
log.Infof(ctx, "Skipping; locking is disabled")
6970
return nil
7071
}
7172

7273
// Return early if the locker is not set.
7374
// It is likely an error occurred prior to initialization of the locker instance.
74-
if b.Locker == nil {
75+
if l.locker == nil {
7576
log.Warnf(ctx, "Unable to release lock if locker is not configured")
7677
return nil
7778
}
7879

7980
log.Infof(ctx, "Releasing deployment lock")
8081
if l.goal == GoalDestroy {
81-
return b.Locker.Unlock(ctx, locker.AllowLockFileNotExist)
82+
return l.locker.Unlock(ctx, locker.AllowLockFileNotExist)
8283
}
83-
return b.Locker.Unlock(ctx)
84+
return l.locker.Unlock(ctx)
8485
}

0 commit comments

Comments
 (0)