fix(services/cos): honor if_not_exists on multipart uploads - #8043
Open
aysha-afrah26 wants to merge 1 commit into
Open
fix(services/cos): honor if_not_exists on multipart uploads#8043aysha-afrah26 wants to merge 1 commit into
aysha-afrah26 wants to merge 1 commit into
Conversation
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.
Which issue does this PR close?
None
Rationale for this change
COS advertises
write_with_if_not_exists, and any write larger thanwrite_multi_min_size(1 MiB) goes through the multipart writer instead of a single PutObject. On the simple pathcos_put_object_requestsetsx-cos-forbid-overwritewhen the caller asks forif_not_exists, but the multipart initiate and complete requests never set it, so once a write crosses the multipart threshold the overwrite guard is dropped and an existing object is replaced while the caller still getsOk. I noticed this while reading the recent OSS fix in #8041, which is the same shape: the header has to ride on both InitiateMultipartUpload and CompleteMultipartUpload. Tencent documentsx-cos-forbid-overwriteas a supported header on InitiateMultipartUpload and lists thecos:x-cos-forbid-overwritecondition key against both InitiateMultipartUpload and CompleteMultipartUpload, so setting it on only one of them is not enough. The fix threadsOpWriteintocos_complete_multipart_uploadand sets the header on both requests whenif_not_exists()is true. Small single-shot writes are unaffected since they already carried the header.What changes are included in this PR?
x-cos-forbid-overwrite: trueoncos_initiate_multipart_uploadandcos_complete_multipart_uploadwhenargs.if_not_exists()is set.OpWritethrough tocos_complete_multipart_uploadfrom the writer'scomplete_part.No new test is added:
test_writer_write_with_if_not_existsalready drives the chunked writer path for any service withwrite_with_if_not_existsandwrite_can_multi, so it covers COS and fails against a real bucket on the current code.Are there any user-facing changes?
A large
if_not_existswrite to COS (overwrite_multi_min_size) now returnsConditionNotMatchwhen the object already exists, matching the behavior of small writes. Code that relied on the previous silent overwrite for large objects will now see the precondition enforced.AI Usage Statement