Repository navigation
fix: delete a project's storage objects on S3 - #14626
Conversation
|
Review complete. 🟠 1 high · 🟡 1 medium 💬 Inline comments (2)
This PR introduces explicit path-style vs virtual-hosted addressing for the S3 storage device, adds recursive delete, deletePath, and deletePrefix (batched via DeleteObjects with continuation tokens), and reworks the project-deletion worker to construct devices lazily and clean project storage roots. Tests cover the new device semantics and add an e2e regression for project storage deletion, with CI lane wiring updated.
Reviewed commit: e5e0fd2 |
🟢 Tier S · Ready to mergeThis change adds paginated recursive deletion for S3 objects, with path containment checks and error reporting, and updates project cleanup to construct storage devices from the deleted project document. It also adds unit and end-to-end coverage for recursive deletion and project storage cleanup.
📂 Walkthrough · 10
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
Adds path-style S3 addressing, recursive/bulk delete support to the storage device, and per-project storage cleanup in the deletes worker.
Key findings
- 🟠 Virtual-hosted S3 copy builds a doubled bucket copy-source — S3.php:577
- 🟡
..in S3 paths resolves past the device root in list/delete prefixes — S3.php:906
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
8a5d69f to
a6ae564
Compare
The findings that requested changes are resolved. See the summary comment for what is still open.
|
@hansi-codes review |
a6ae564 to
2ab28cf
Compare
commit: |
2ab28cf to
bde3bc0
Compare
… objects A deployment archive, a build output and a deployment screenshot are each one object, but the worker deleted them with recursive set. Once a recursive S3 delete lists and batch-deletes everything under path/, that flag would add a listing request per file for nothing, and would remove any object that happens to sit under the file's name followed by a slash.
…r outside the root
An empty key turns `DELETE /` into DeleteBucket, and a recursive delete or deletePath() that resolves to the whole bucket names every object in it. Both are refused with an InvalidArgumentException before any request is sent, ahead of the recursive delete that lists and removes the keys under a directory.
A path-style device also refuses a bare bucket name, its own or another, since `DELETE /{bucket}` is DeleteBucket there as well.
Only deletePath() refuses the device root itself; its check compares resolved paths, so '.', 'x/..' and '/' are caught along with ''. delete($root, true) is still allowed, because the deletes worker removes a deleted project's storage that way.
getAbsolutePath() pops '..' without stopping at the root, so root/../other names a sibling of the root. A recursive delete or deletePath() whose resolved directory is not inside the root is refused as well, and the comparison is made on whole path segments so root-x/ is not mistaken for part of root/.
Device::delete() and Device::deletePath() document that a device may refuse such paths with an InvalidArgumentException.
…S3 delete S3 has no directories, so a recursive delete that only sends DELETE for the path removes at most one object and leaves everything under path/ behind. A recursive delete now lists the keys under path/ page by page, following the continuation token, and removes each page with one DeleteObjects request. deletePath() goes through the same code, so recursive delete() reuses deletePath()'s escaping and bucket addressing. A page with no keys does not end the delete while a continuation token remains. A listing that cannot be followed raises a RemoteException instead of passing for an empty or finished directory: one without IsTruncated, which every ListObjectsV2 result carries, one that is truncated without a continuation token (a ListObjects V1 answer carries only NextMarker), and one that hands back the token it was asked with, which would otherwise loop forever. Following the continuation token, the empty page and the listings that cannot be followed are covered by unit tests: the first needs more than 1000 objects end to end, and MinIO cannot be made to answer the others. An E2E test deletes nested objects through a path-style endpoint and keeps a sibling that shares the name as a prefix.
DeleteObjects can answer 200 with a body that is a top-level Error, which fails every key of the batch. That body was read as an empty error list, so the delete reported success while the objects survived. It now raises a RemoteException carrying the batch size, the directory and the error code. An Error entry that has a Code but no Key now counts as a failure instead of being skipped, and is reported with `?` for its key. An Error that decodes to no entries, such as `<Error/>` or bare text, fails the whole batch. Every failure message names the directory being deleted. These stay unit tests: MinIO offers no way to make it fail keys of a batch.
…evices The project row is deleted before the deletes worker runs, and the worker resolves its injected project by reading that row back. For a project delete the injected project is therefore empty, so the injected storage devices were rooted at 'app-' with no ID: the recursive deletes ran against a root that holds none of the project's objects, and every file, deployment, build and cache entry of the deleted project stayed behind. deleteProject() now builds the uploads, sites, functions, builds and cache devices from the deleted project's ID, wrapped in the telemetry device like the injected ones, each inside its own try so one failing root does not leave the others. The device parameters, and the cache device injection that only this path used, are gone; deleteProjectsByTeam() no longer builds devices for it. deleteProject() refuses a document without an ID before it touches anything. The danger of an empty ID is the database half: getProjectDB() and the projectInternalId queries would run for an empty project. A unit test sends such a message and checks that no database, device or execution store is called. testDeleteProjectStorage uploads a file and deploys a function, waits for the build to be ready and for its output to be stored, deletes the project and waits for its uploads, functions and builds roots to be empty. It runs in the S3 storage group, so the Project service is added to that group.
bde3bc0 to
a01dca3
Compare
What does this PR do?
Deleting a project leaves its storage behind. Two bugs stack up:
A) Devices built from the deleted project
deleteProject()builds its devices from the deleted$document(wrapped inTelemetryDevice) and throws on an empty project id. Deployment source, build and screenshot files are deleted as single objects (non-recursive).Signature changes (protected/public, for subclasses):
deviceForCacheis no longer injected;deleteProjectsByTeam()also takesTelemetry.B) Recursive S3 delete removes the whole directory
DeleteObjectsbody are XML-escapedRemoteExceptionon per-key<Error>s, on a whole-batch error, and on a listing that is not aListObjectsV2resultTest Plan
Each test was seen red before its fix:
S3Base::testRecursiveDeleteStaysInsideTheRoot/outside-…/sentinel.txt is outside the root and must survive delete('../outside-…', true);/root-…/sentinel.txt … must survive delete('../root-…', true)testDeleteRecursivedelete()skips the prefixrec-…/a/1.txt survived delete('rec-…/a', true)testRecursiveDeleteRefusesAnEmptyPrefixdeletePath('.') must refuse…,deletePath('x/..') must refuse…testDeletePathKeepsSiblings,testRecursiveDeleteEscapesKeysimgmatchesimg2; keys not escapedtestRecursiveDeleteFollowsTheContinuationTokenactual size 3 matches expected size 5testAnEmptyTruncatedPageDoesNotEndTheDeleteactual size 1 matches expected size 3testAListingThatIsNotAListObjectsResultIsAnErrortestKeysTheServiceFailedToDeleteAreAnError(one key / two keys / whole batch)<Error>ignoredKeys the service could not delete must not be reported as deletedDeletesTest::testProjectDeleteWithoutAnIdTouchesNothingStore::deleteProject(''): void was not expected to be calledProjectConsoleClientTest::testDeleteProjectStorageThe unit tests cover what MinIO can't produce (pagination edge cases, service errors).
testDeleteProjectStorageruns in the default (local device) Project lanes and, via#[Group('s3')]and.github/ci/e2e.json, in the S3 Storage lane.Merge order
The S3 Storage lane uses path-style MinIO (
_APP_STORAGE_S3_ENDPOINT: http://minio:9000, bucketappwrite, noMINIO_DOMAIN), where bucket-level listing is broken onmain. That was fixed by the path-style addressing PR, #14628.Checklist