Skip to content

feat(services/cos): support copy_with_if_not_exists via x-cos-forbid-…#7526

Merged
Xuanwo merged 1 commit into
apache:mainfrom
mikewhb:fix/cos-copy-if-not-exists
May 13, 2026
Merged

feat(services/cos): support copy_with_if_not_exists via x-cos-forbid-…#7526
Xuanwo merged 1 commit into
apache:mainfrom
mikewhb:fix/cos-copy-if-not-exists

Conversation

@mikewhb
Copy link
Copy Markdown
Contributor

@mikewhb mikewhb commented May 13, 2026

…overwrite

Currently the COS backend declares write_with_if_not_exists but the COPY path silently drops OpCopy.if_not_exists: the copy() impl annotates the arg as _args, and cos_copy_object() does not even take an OpCopy.

This is observable when frameworks such as object_store use the default rename_if_not_exists implementation (copy_if_not_exists + delete) for commit-style atomicity (Lance, Iceberg, Delta, etc.). Without the x-cos-forbid-overwrite header, concurrent committers all win the COPY and silently overwrite each others manifests.

Changes:

  • backend.rs: declare copy_with_if_not_exists capability (gated on enable_versioning, mirroring write_with_if_not_exists).
  • backend.rs: stop dropping OpCopy and forward it to the core.
  • core.rs: cos_copy_object now accepts &OpCopy and emits x-cos-forbid-overwrite: true when args.if_not_exists() is set.

Tested:

  • cargo check / cargo test --lib -p opendal-service-cos pass.
  • End-to-end verified against ap-guangzhou COS using the patched build: single-writer T1/T2 scenarios behave correctly (200 / 409 FileAlreadyExists). Highly-concurrent races on the same fresh key still show non-atomic behavior on the server side, but that is a separate server-level issue and out of scope for this PR.

Refs: https://www.tencentcloud.com/document/product/436/7749

Which issue does this PR close?

Closes #.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

AI Usage Statement

@mikewhb mikewhb requested a review from Xuanwo as a code owner May 13, 2026 02:54
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. releases-note/feat The PR implements a new feature or has a title that begins with "feat" labels May 13, 2026
…overwrite

Currently the COS backend declares write_with_if_not_exists but the COPY
path silently drops OpCopy.if_not_exists: the copy() impl annotates the
arg as `_args`, and cos_copy_object() does not even take an OpCopy.

This is observable when frameworks such as object_store use the default
rename_if_not_exists implementation (copy_if_not_exists + delete) for
commit-style atomicity (Lance, Iceberg, Delta, etc.). Without the
x-cos-forbid-overwrite header, concurrent committers all win the COPY
and silently overwrite each others manifests.

Changes:
* backend.rs: declare copy_with_if_not_exists capability (gated on
  enable_versioning, mirroring write_with_if_not_exists).
* backend.rs: stop dropping OpCopy and forward it to the core.
* core.rs: cos_copy_object now accepts &OpCopy and emits
  x-cos-forbid-overwrite: true when args.if_not_exists() is set.

Tested:
* cargo check / cargo test --lib -p opendal-service-cos pass.
* End-to-end verified against ap-guangzhou COS using the patched build:
  single-writer T1/T2 scenarios behave correctly (200 / 409
  FileAlreadyExists). Highly-concurrent races on the same fresh key
  still show non-atomic behavior on the server side, but that is a
  separate server-level issue and out of scope for this PR.

Refs: https://www.tencentcloud.com/document/product/436/7749
Signed-off-by: arrowbowang <arrowbowang@tencent.com>
@mikewhb mikewhb force-pushed the fix/cos-copy-if-not-exists branch from 7a5416e to f6a9cc0 Compare May 13, 2026 03:29
Copy link
Copy Markdown
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you!

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 13, 2026
@Xuanwo Xuanwo merged commit 128ebcd into apache:main May 13, 2026
122 of 123 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer releases-note/feat The PR implements a new feature or has a title that begins with "feat" size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants