Skip to content

Commit 1545f3b

Browse files
committed
Fixed redundant multiple mounting clusters
Fixes #445
1 parent e29d6f2 commit 1545f3b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.3.0
44

5+
* Fixed redundant multiple mounting clusters ([#445](https://github.com/databrickslabs/terraform-provider-databricks/issues/445))
56
* Added optional parameter azure_environment to provider config which defaults to public ([#437](https://github.com/databrickslabs/terraform-provider-databricks/pull/437)).
67
* Added [databricks_service_principal](https://github.com/databrickslabs/terraform-provider-databricks/pull/386) resource.
78
* `skip_validation` from `databricks_instance_profile` was removed and is always set to `true`.

compute/clusters.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"sort"
88
"strings"
9+
"sync"
910
"time"
1011

1112
"github.com/databrickslabs/databricks-terraform/common"
@@ -293,8 +294,16 @@ func (a ClustersAPI) ListNodeTypes() (l NodeTypeList, err error) {
293294
return
294295
}
295296

297+
// getOrCreateClusterMutex guards "mounting" cluster creation to prevent multiple
298+
// redundant instances created at the same name. Compute package private property.
299+
// https://github.com/databrickslabs/terraform-provider-databricks/issues/445
300+
var getOrCreateClusterMutex sync.Mutex
301+
296302
// GetOrCreateRunningCluster creates an autoterminating cluster if it doesn't exist
297303
func (a ClustersAPI) GetOrCreateRunningCluster(name string, custom ...Cluster) (c ClusterInfo, err error) {
304+
getOrCreateClusterMutex.Lock()
305+
defer getOrCreateClusterMutex.Unlock()
306+
298307
if len(custom) > 1 {
299308
err = fmt.Errorf("You can only specify 1 custom cluster conf, not %d", len(custom))
300309
return

storage/mounts.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,16 @@ func getMountingClusterID(ctx context.Context, client *common.DatabricksClient,
112112
r := compute.Cluster{
113113
NumWorkers: 0,
114114
ClusterName: "terraform-mount",
115-
SparkVersion: clustersAPI.LatestSparkVersionOrDefault(compute.SparkVersionRequest{
116-
Latest: true,
117-
LongTermSupport: true,
118-
}),
119-
NodeTypeID: clustersAPI.GetSmallestNodeType(compute.NodeTypeRequest{LocalDisk: true}),
115+
SparkVersion: clustersAPI.LatestSparkVersionOrDefault(
116+
compute.SparkVersionRequest{
117+
Latest: true,
118+
LongTermSupport: true,
119+
}),
120+
NodeTypeID: clustersAPI.GetSmallestNodeType(
121+
compute.NodeTypeRequest{
122+
LocalDisk: true,
123+
}),
124+
120125
AutoterminationMinutes: 10,
121126
SparkConf: map[string]string{
122127
"spark.master": "local[*]",

0 commit comments

Comments
 (0)