Skip to content

feat(storage): add deleteSourceObjects option to Bucket::compose()#9211

Merged
kalragauri merged 2 commits into
googleapis:mainfrom
salilg-eng:feat/delete_source_objects
May 29, 2026
Merged

feat(storage): add deleteSourceObjects option to Bucket::compose()#9211
kalragauri merged 2 commits into
googleapis:mainfrom
salilg-eng:feat/delete_source_objects

Conversation

@salilg-eng
Copy link
Copy Markdown
Contributor

@salilg-eng salilg-eng commented May 25, 2026

Overview

This Pull Request implements support for the native GCS server-side auto-deletion of source objects when merging files using Bucket::compose().

When the option deleteSourceObjects => true is supplied, GCS natively handles the sequential cleanup of intermediate component files on the server-side, making the composition operation immeasurably faster, safer, and completely transaction-secure.

Architecture & Design Decisions

  • Native Request Body Serialization:
    Instead of sending deleteSourceObjects as a URL query parameter or running a manual client-side cleanup loop, this implementation fully integrates the option inside the JSON request body payload (ComposeRequest properties).
  • Zero Client-side Overhead:
    Completely delegates the deletion process to the GCS backend. The library makes exactly one single POST call to objects.compose without spawning any local deletion loops, catching errors, or making redundant connection calls.
  • API Spec Alignment:
    Updated the API service discovery spec (storage-v1.json) to define deleteSourceObjects inside the ComposeRequest body properties, while removing it from the URL query parameters. This allows Guzzle's RequestBuilder to naturally handle request mapping and serialization.

Changes

  1. Storage/src/Bucket.php:
    • Declared deleteSourceObjects inside the compose() method docstrings.
    • Erased all legacy client-side deletion loops, validation unsets, and error handlers to fully leverage GCS server-side native capability.
  2. Storage/src/Connection/ServiceDefinition/storage-v1.json:
    • Removed deleteSourceObjects from the query parameter metadata list of the objects.compose method.
    • Added deleteSourceObjects as a boolean property under the ComposeRequest request body schema.
  3. Storage/tests/Unit/BucketTest.php:
    • Added mock test case verifying Guzzle serializes deleteSourceObjects => true inside the request body parameters.
    • Confirms that no local connection calls to deleteObject() are spawned.
  4. Storage/tests/System/ManageObjectsTest.php:
    • Includes live GCS E2E integration test cases matching standard GCS behavior options (true, false, null).

Verification & Testing

All unit tests have been successfully verified and pass with a 100% success rate locally:

  • Result: OK (64 tests, 111 assertions)

@salilg-eng salilg-eng requested review from a team as code owners May 25, 2026 11:50
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label May 25, 2026
Comment thread Storage/src/Bucket.php Outdated
@salilg-eng salilg-eng requested a review from Hectorhammett May 27, 2026 09:41
@salilg-eng
Copy link
Copy Markdown
Contributor Author

Hi maintainers,

The single PHPStan Static Analysis failure is a preexisting upstream repository issue and is completely unrelated to the changes in this PR.

This PR strictly modifies 4 files under the Storage package, which is 100% static-analysis green. The failure occurs entirely under the Spanner component due to the release of PHPStan 2.2.0 yesterday (May 28).

Since the CI workflow uses composer update -d dev on every run, the build automatically pulled the new 2.2.0 release which has stricter sealed array validation rules, flagging preexisting array shapes inside Spanner/src/ValueMapper.php and Spanner/src/Operation.php. Upstream main commits analyzed before yesterday passed solely because they ran under the older 2.1.56 release.

Ready for a final look and merge!

@salilg-eng salilg-eng force-pushed the feat/delete_source_objects branch from 5187dcb to 3c277b6 Compare May 29, 2026 07:33
Copy link
Copy Markdown

@kalragauri kalragauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR description to match the updated implementation.

Comment thread Storage/tests/Unit/BucketTest.php Outdated
$bucket->compose(['file1.txt', 'file2.txt'], 'combined-files.abc');
}


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra blank line.

Copy link
Copy Markdown
Contributor Author

@salilg-eng salilg-eng May 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed space

@kalragauri kalragauri merged commit cc0d5a2 into googleapis:main May 29, 2026
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants