chitralverma opened a new issue, #9319:
URL: https://github.com/apache/opendal/issues/9319

   
   > AI-assisted: this issue was drafted with an AI coding agent (Claude Code, 
Opus 5.5) from code reading on `main`. The author is accountable for its 
content.
   
   ### Summary
   
   The [conditional operations 
contract](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/core/src/docs/specs/conditional-operations.md#L38-L53)
 requires that a service either enforces every accepted condition or returns 
`Unsupported`. On `main` (`4ae8e61`), the GCS service advertises the conditions 
involved but some request builders silently drop one of them:
   
   1. **`if_not_exists` + `if_version_match` on write (JSON simple, JSON 
resumable, and XML).** Each builder encodes `if_version_match` first and skips 
`if_not_exists` through an `else if`. The request carries only 
`ifGenerationMatch=<version>`. If the object exists at that generation, GCS 
overwrites it, which breaks `if_not_exists`:
      - 
[`gcs_insert_object_request`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L354-L363)
      - 
[`gcs_initiate_resumable_upload_request`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L435-L439)
      - 
[`gcs_insert_object_xml_request`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L592-L596)
   
      Version-based `if_not_changed` lowers to `if_version_match`, so 
`if_not_exists` + `if_not_changed` hits the same path.
   2. **`if_version_not_match` on presigned write.** 
[`presign`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/backend.rs#L633-L636)
 builds the request with `gcs_insert_object_xml_request`. That builder has no 
`if_version_not_match` branch 
([L592-L602](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L592-L602)),
 so the signed `PUT` has no generation-inequality condition. `OpPresign::check` 
checks write options against the write capabilities, and 
[`write_with_if_version_not_match: 
true`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/backend.rs#L370-L372)
 lets the option through.
   3. **`if_not_exists` + `if_version_match` on compose.** 
[`gcs_compose_object_request`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L822-L826)
 has the same `else if`. GCS advertises both [`compose_with_if_not_exists` and 
`compose_with_if_version_match`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/backend.rs#L416-L417),
 and the [`compose` 
guard](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/backend.rs#L591-L601)
 does not reject the combination.
   
   The rewrite (copy) builder has the same `else if` 
([L900-L904](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L900-L904)).
 Copy cannot reach it today because GCS does not advertise 
`copy_with_if_not_exists`.
   
   Existing unit tests assert the single-condition output for case 1 
([insert](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L1684-L1700),
 
[resumable](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/core/services/gcs/src/core.rs#L1723-L1736)).
   
   ### Reachability
   
   The Rust `WriteOptions` / `ComposeOptions` and the generated .NET 
`WriteOptions` (`IfVersionMatch`, `IfVersionNotMatch`, `IfNotExists`, 
`IfNotChanged`) can reach these paths today. #9234 would also expose them on 
Java `WriteOptions`.
   
   ### Evidence and limits
   
   All of this comes from reading the code and from inspecting the generated 
requests offline. That inspection is in the #9234 review, which used a loopback 
HTTP check and a locally signed presigned `PUT`. There is **no live GCS 
reproduction**, so this issue does not claim an observed overwrite.
   
   `if_not_exists` and `if_version_match` can never both hold. A missing object 
fails the version match, and an existing object fails `if_not_exists`. Under 
the contract, the service must therefore reject the combination with 
`Unsupported` (or `ConditionNotMatch`) and must not send either condition 
alone. For an operation that returns `Unsupported`, the contract determines the 
outcome, so the fix does not depend on GCS server behavior.
   
   ### Proposed direction
   
   Return `Unsupported` for each combination the service cannot encode 
completely, and add regression tests. #9234 already does this for write and 
presign-write in `bf85034cde`. Compose (case 3) is not covered there yet. A 
separate core PR, ahead of the Java exposure, would keep the binding PR scoped.
   
   Related: #9234, #8650.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to