Skip to content

Skip the per-file parent-directory check in fs cp -r - #7711

Draft
yuanjieding-db wants to merge 3 commits into
mainfrom
yuanjieding-db/fs-cp-skip-parent-check
Draft

yuanjieding-db wants to merge 3 commits into
mainfrom
yuanjieding-db/fs-cp-skip-parent-check

Conversation

@yuanjieding-db

@yuanjieding-db yuanjieding-db commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Stack. Each PR is based on the one before it, so its diff shows only its own change.

PR
1 #7711 Skip the per-file parent-directory check in fs cp -r
2 #7784 testserver: optional response headers on fault rules
3 #7712 fs cp -r: keep going past failed files (validation results are here)
4 #7785 fs cp -r: stop when files keep failing for 5 minutes
5 #7786 fs cp -r: back off during failure bursts
6 #7787 fs cp -r: retry transient directory errors

This is part 1.

Changes

databricks fs cp -r now writes each file with filer.CreateParentDirectories, so the filer no longer checks that the parent directory exists before each write. Single-file fs cp is unchanged.

Why

The recursive walk already creates every target directory (Mkdir) before it queues the files inside it, so the per-file check is redundant. On Volumes that check is a HEAD /api/2.0/fs/directories/... before every PUT /api/2.0/fs/files/..., so a copy of many small files sends two requests per file where one is enough. On DBFS it is a get-status alongside create, add-block and close. Each extra request is one more chance to be throttled or hit a transient error.

How each filer fs cp can write to handles the flag:

  • Files API (Volumes, Skills): skips the GetDirectoryMetadata HEAD. The PUT itself is unchanged.
  • DBFS: skips the get-status on the parent. dbfs/create already creates missing parents.
  • Local: creates parents only if the write fails with not-exist, which should not happen after the walk's Mkdir.

One difference: if a target directory is deleted while the copy runs, later files into it no longer fail with "no such directory". On DBFS and local they recreate it. On Volumes the PUT returns whatever the server returns for a missing parent.

Tests

  • Unit test TestCp_writeModes: cpDirToDir passes CreateParentDirectories (plus OverwriteIfExists with --overwrite), and single-file cpFileToFile passes neither. The mock target also fails any such write whose directory wasn't Mkdired first. Fails without the change, and fails if the walk's Mkdir is removed.
  • New acceptance test acceptance/cmd/fs/cp-r-requests records testserver requests. Before this change, cp -r of 3 files in 2 directories sent 3 HEAD /fs/directories requests. Now it sends 2 directory PUTs and 3 file PUTs. The single-file copy in the same test still sends its parent-directory HEAD (plus the target Stat).
  • go test ./cmd/fs/ ./libs/filer/, go test ./acceptance -run TestAccept/cmd/fs, ./task lint-q, ./task fmt-q.

This pull request and its description were written by Isaac.

yuanjieding-db and others added 3 commits November 17, 2026 09:00
A recursive copy creates every target directory during the walk, before
it queues the files in that directory. The filer then checked the parent
directory again before each write (a HEAD on the Files API, get-status on
DBFS), doubling the request count for copies of many small files.

Pass filer.CreateParentDirectories for files written by cpDirToDir so the
filer skips that check. Single-file copies are unchanged.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions

Copy link
Copy Markdown
Contributor

Commit: 31b84c469 | Workflow run

Regression test report

Selected 1 changed tests (limit=20, 0 not selected)

1 tests: regression=1 unreleased=0 coverage=0 failing=0
test branch main (d2c32d7) latest (v1.26.0)
TestAccept/cmd/fs/cp-r-requests ✅ ❌ ❌
TestAccept/cmd/fs/cp-r-requests: branch ✅ | main (d2c32d7) ❌ | latest (v1.26.0) ❌

main (d2c32d7):

acceptance_test.go:1380: Diff:
        --- cmd/fs/cp-r-requests/output.txt
        +++ /tmp/TestAcceptcmdfscp-r-requests3987294931/002/output.txt
        @@ -7,6 +7,9 @@
         === Recursive copy: a directory PUT per directory, a file PUT per file, no directory HEAD per file
         
         >>> print_requests.py --sort //api/2.0/fs/
        +{"method":"HEAD","path":"/api/2.0/fs/directories/Volumes/main/default/fs-cp-r-requests/dst"}
        +{"method":"HEAD","path":"/api/2.0/fs/directories/Volumes/main/default/fs-cp-r-requests/dst"}
        +{"method":"HEAD","path":"/api/2.0/fs/directories/Volumes/main/default/fs-cp-r-requests/dst/sub"}
         {"method":"PUT","path":"/api/2.0/fs/directories/Volumes/main/default/fs-cp-r-requests/dst"}
         {"method":"PUT","path":"/api/2.0/fs/directories/Volumes/main/default/fs-cp-r-requests/dst/sub"}
         {"method":"PUT","path":"/api/2.0/fs/files/Volumes/main/default/fs-cp-r-requests/dst/a.txt"}
        
FAIL

latest (v1.26.0): same output as main (d2c32d7)

@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 31b84c4

Run: 44052573374

Env 🔄​flaky 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 270 16 5:25
🔄​ aws-windows-latest-4core-16gb 1 1 271 14 4:17
💚​ azure linux-2core-8gb 1 269 16 5:08
💚​ azure-windows-latest-4core-16gb 1 271 14 3:56
💚​ gcp linux-2core-8gb 1 270 16 4:43
💚​ gcp-windows-latest-4core-16gb 1 272 14 3:54
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🔄​ TestGitCloneOnNonDefaultBranch ✅​p 🔄​f ✅​p ✅​p ✅​p ✅​p
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:29 aws-windows-latest-4core-16gb TestAccept
3:11 azure-windows-latest-4core-16gb TestAccept
3:10 gcp-windows-latest-4core-16gb TestAccept

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants