Repository navigation
Skip the per-file parent-directory check in fs cp -r - #7711
Draft
yuanjieding-db wants to merge 3 commits into
Draft
yuanjieding-db wants to merge 3 commits into
yuanjieding-db wants to merge 3 commits into
Conversation
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>
Contributor
|
Commit: Regression test reportSelected 1 changed tests (limit=20, 0 not selected) 1 tests: regression=1 unreleased=0 coverage=0 failing=0
TestAccept/cmd/fs/cp-r-requests: branch ✅ | main (d2c32d7) ❌ | latest (v1.26.0) ❌main (d2c32d7): latest (v1.26.0): same output as main (d2c32d7) |
Collaborator
✅ Integration test reportCommit: 31b84c4
Top 3 slowest tests (at least 2 minutes):
|
This was referenced Nov 17, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack. Each PR is based on the one before it, so its diff shows only its own change.
This is part 1.
Changes
databricks fs cp -rnow writes each file withfiler.CreateParentDirectories, so the filer no longer checks that the parent directory exists before each write. Single-filefs cpis 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 aHEAD /api/2.0/fs/directories/...before everyPUT /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 aget-statusalongside create, add-block and close. Each extra request is one more chance to be throttled or hit a transient error.How each filer
fs cpcan write to handles the flag:GetDirectoryMetadataHEAD. The PUT itself is unchanged.get-statuson the parent.dbfs/createalready creates missing parents.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
TestCp_writeModes:cpDirToDirpassesCreateParentDirectories(plusOverwriteIfExistswith--overwrite), and single-filecpFileToFilepasses neither. The mock target also fails any such write whose directory wasn'tMkdired first. Fails without the change, and fails if the walk'sMkdiris removed.acceptance/cmd/fs/cp-r-requestsrecords testserver requests. Before this change,cp -rof 3 files in 2 directories sent 3HEAD /fs/directoriesrequests. Now it sends 2 directoryPUTs and 3 filePUTs. The single-file copy in the same test still sends its parent-directory HEAD (plus the targetStat).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.