Scope dav recursive list and delete to the requested prefix#130
Open
wayneeseguin wants to merge 1 commit into
Open
Scope dav recursive list and delete to the requested prefix#130wayneeseguin wants to merge 1 commit into
wayneeseguin wants to merge 1 commit into
Conversation
The dav backend's List started its PROPFIND walk at the blobstore endpoint root and filtered by prefix only at the leaves, so DeleteRecursive traversed every directory in the store to delete one prefix. Against a large partitioned WebDAV blobstore this issues thousands of PROPFIND round trips per delete and the operation times out. Bound the walk to the prefix's subtree: - List now starts the PROPFIND at the deepest directory the prefix fully names (the portion up to its last slash), matching how the s3 backend pushes the prefix to the server. Directories that would escape the endpoint through dot-dot segments are rejected and fall back to the endpoint-root walk, and the starting URL is slash-terminated so servers that redirect directory URLs to their canonical form are not triggered. - listRecursive now skips collections whose paths cannot contain blob IDs matching the prefix, which prunes sibling partitions when the prefix does not name a directory. Blob IDs are still matched as string prefixes at the leaves, so the observable results of List and DeleteRecursive are unchanged; only the traversal is narrower. A missing prefix directory still yields an empty list via the existing 404 handling. Add a dav integration spec covering multi-segment prefixes, which the existing single-segment specs never exercised. Fixes cloudfoundry#129
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.
Fixes #129
Problem
The dav backend's
List(prefix)starts itsDepth: 1PROPFIND walk at the blobstore endpoint root and applies the prefix only when it reaches a leaf, soDeleteRecursivetraverses the entire blobstore to delete one prefix. Against a production-sized WebDAV blobstore, where keys are partitioned into two-character directories, that is thousands of PROPFIND round trips per delete. Cloud Controller callsdelete-recursiveto clear an app's buildpack cache on everycf delete -r, and the walk does not finish before the operation times out. The s3 backend already scopes the same operation by passing the prefix to the server.Fix
Two changes in
dav/client/storage_client.go, both affecting only which requests are made, not what is returned:Listnow roots the walk at the deepest directory the prefix fully names — the portion of the prefix up to its last/, computed by the newprefixDirhelper. Blob IDs are matched as string prefixes rather than directory paths, so only that portion is guaranteed to be a directory; the final segment may match both a file (ab/cd/guid-file) and a directory (ab/cd/guid/), and starting one level up keeps both reachable. For Cloud Controller's partitioned keys (ab/cd/<guid>), the walk starts atab/cdand a recursive delete becomes two PROPFINDs instead of a whole-store traversal.listRecursivenow prunes subcollections that cannot contain matching blob IDs, via the newcollectionMayContainPrefixhelper: every blob under a collection with relative pathrelhas an ID starting withrel + "/", so the walk descends only whenrel + "/"and the prefix are string prefixes of one another. This bounds single-segment prefixes (which name no directory) and keeps the walk narrow below the starting point.Two details of the starting URL:
prefixDirrejects directories that would escape the endpoint through..segments (path.Dircleans the path, so../etcanda/../../bare caught). Such prefixes fall back to the endpoint-root walk, exactly as before — they can never match a blob ID, so the result stays empty, and no request is ever issued outside the configured endpoint path.Observable behavior is unchanged: the leaf filter is untouched,
List("")still walks the whole store, and a prefix whose directory does not exist still yields an empty list (the existing 404-on-PROPFIND handling), whichDeleteRecursivealready treats as a no-op.Testing
dav/client/storage_client_list_test.gorunListandDeleteRecursiveagainst an httptest WebDAV fake that records every PROPFIND and DELETE path, and assert both the returned/deleted blob sets and the exact set of directories the walk touched — e.g. deletingab/cd/<guid>PROPFINDs onlyab/cdandab/cd/<guid>, and never enters sibling partitions.prefixDirandcollectionMayContainPrefixedge cases (empty, single-segment, trailing-slash, leading-slash, and..-containing prefixes), and a dedicated test asserts that escaping prefixes never produce a PROPFIND outside the endpoint path.ab/cd/<id>): it puts blobs under the prefix plus bystanders in sibling partitions, then verifieslistanddelete-recursivetouch only the prefixed blobs. The existing integration prefixes are all single-segment, which never exercise the deeper starting URL.go build ./...,go vet ./...,go test ./dav/...(unit and Docker integration, 8 of 8 specs), andgolangci-lint run ./dav/...all pass. The gcs/azurebs/s3 integration suites need live cloud credentials and were not run.