Skip to content

Commit 7e8d852

Browse files
[Fix] databricks_mount: remove redundant listing of mounted directories (#4590)
Directory listings can take very long when there are lots of files in the mounted directory. This slows down both the state refresh and the actual mounting up to the point that the operation times out. Fixes [4509](#4509) ## Changes <!-- Summary of your changes that are easy to understand --> Remove directory listing of mounted directories. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework --------- Co-authored-by: Alex Ott <[email protected]>
1 parent 9ced85b commit 7e8d852

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bug Fixes
1010

1111
* Recreate `databricks_access_control_rule_set` when the `name` changes ([#4572](https://github.com/databricks/terraform-provider-databricks/pull/4572)).
12+
* Avoid timeouts during `databricks_mount` state refresh and creation ([#4590](https://github.com/databricks/terraform-provider-databricks/pull/4590)).
1213

1314
### Documentation
1415

storage/mounts.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ func (mp MountPoint) Mount(mo Mount, client *common.DatabricksClient) (source st
7979
sparkConfRe := regexp.MustCompile(`"\{\{sparkconf/([^\}]+)\}\}"`)
8080
extraConfigs = sparkConfRe.ReplaceAll(extraConfigs, []byte(`spark.conf.get("$1")`))
8181
command := fmt.Sprintf(`
82+
def check_path(path_string):
83+
fs = sc._jvm.org.apache.hadoop.fs.FileSystem.get(sc._jsc.hadoopConfiguration())
84+
path = spark.sparkContext._jvm.org.apache.hadoop.fs.Path(f"dbfs:{path_string}")
85+
fs.exists(path)
86+
8287
def safe_mount(mount_point, mount_source, configs, encryptionType):
8388
for mount in dbutils.fs.mounts():
8489
if mount.mountPoint == mount_point and mount.source == mount_source:
8590
return
8691
try:
8792
dbutils.fs.mount(mount_source, mount_point, extra_configs=configs, encryption_type=encryptionType)
8893
dbutils.fs.refreshMounts()
89-
dbutils.fs.ls(mount_point)
94+
check_path(mount_point)
9095
return mount_source
9196
except Exception as e:
9297
try:

storage/mounts_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,19 @@ func TestMountPoint_Mount(t *testing.T) {
9797
expectedMountConfig := `{"fake-key":"fake-value"}`
9898
mountName := "this_mount"
9999
expectedCommand := fmt.Sprintf(`
100+
def check_path(path_string):
101+
fs = sc._jvm.org.apache.hadoop.fs.FileSystem.get(sc._jsc.hadoopConfiguration())
102+
path = spark.sparkContext._jvm.org.apache.hadoop.fs.Path(f"dbfs:{path_string}")
103+
fs.exists(path)
104+
100105
def safe_mount(mount_point, mount_source, configs, encryptionType):
101106
for mount in dbutils.fs.mounts():
102107
if mount.mountPoint == mount_point and mount.source == mount_source:
103108
return
104109
try:
105110
dbutils.fs.mount(mount_source, mount_point, extra_configs=configs, encryption_type=encryptionType)
106111
dbutils.fs.refreshMounts()
107-
dbutils.fs.ls(mount_point)
112+
check_path(mount_point)
108113
return mount_source
109114
except Exception as e:
110115
try:

0 commit comments

Comments
 (0)