Skip to content

feat(core): copy_with can replace user metadata and content type - #8431

Merged
Xuanwo merged 14 commits into
apache:mainfrom
dmxlol:feat-copy-user-metadata
Nov 22, 2026
Merged

Xuanwo merged 14 commits into
apache:mainfrom
dmxlol:feat-copy-user-metadata

Conversation

@dmxlol

@dmxlol dmxlol commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #8430.

Rationale for this change

A metadata-only change, such as setting a file's mtime after upload, currently costs a full
read and rewrite. OpenDAL's copy cannot carry new metadata, and it refuses from == to.
S3 can make this change with one zero-body CopyObject that sends
x-amz-metadata-directive: REPLACE. The issue has the details.

What changes are included in this PR?

  • CopyOptions gets user_metadata, content_type and content_language, named as in
    WriteOptions. copy_with and copier_with get matching builder methods, and OpCopy
    gets matching getters.
  • Whole-set replacement: when any of the three is set, the destination gets exactly the given
    values and every unset field takes the service default. Documented on CopyOptions, in
    RFC-8431 and in specs/metadata.md.
  • New capability flags copy_with_user_metadata, copy_with_content_type and
    copy_with_content_language. Operator checks them against the effective capability of the
    composed stack and returns Unsupported before any request, so a CapabilityOverrideLayer
    can turn them off or on. They are on by default for s3.
  • compatible_services.md (s3) lists the providers the copy metadata tests ran against and
    shows the CapabilityOverrideLayer opt-out.
  • Operator::copy* accepts from == to when one of the options is set.
  • services-s3: CopyObject sends x-amz-metadata-directive: REPLACE with Content-Type,
    Content-Language and x-amz-meta-*; a multipart copy sets them on CreateMultipartUpload.
  • RFC-8431 and the portable spec updates (specs/metadata.md, one line in
    specs/conditional-operations.md).
  • Regenerated .NET bindings (the generator adds the three options to the .NET CopyOptions).
  • #[allow(clippy::large_enum_variant)] on the FuturesDeleteSink state: the larger
    Capability pushed it over clippy's threshold.
  • Tests: OpCopy options round trip; correctness-check tests (Unsupported, same-path copy);
    capability_override_gates_copy_metadata (through Operator::new(...).layer(...), zero copy
    calls when a flag is overridden off, accepted when overridden on);
    S3 request-shape tests for single and multipart copy; behavior tests
    test_copy_with_user_metadata_in_place, test_copy_with_content_language_in_place and
    test_copy_with_metadata_multipart.

Tested against (AWS, Silo and SeaweedFS rerun on the current head; Garage on the previous one):

  • AWS S3 (eu-central-1, versioned bucket, aws_s3_with_versioning overrides): 151 of 159. All copy
    tests pass, including the source_version tests and the three new metadata tests. The 8 failures
    are versioned delete and restore tests, denied s3:DeleteObjectVersion for the test IAM user;
    they fail the same way on main.
  • Silo (fixtures/s3): full suite 136 of 136.
  • SeaweedFS 4.52 (fixtures/s3/docker-compose-seaweedfs.yml): full suite 149 of 149.
  • Garage v2.1.0: 128 of 149; the same 21 fail on main (conditional writes, copies and deletes,
    response overrides, special characters), none of them a metadata copy. The three new copy tests pass.

Are there any user-facing changes?

Yes. This PR adds three copy options, their builder methods and three capability flags;
nothing existing changes. The behavior is documented on CopyOptions::user_metadata: when any
of the options is set, the destination does not inherit source metadata, and unset fields such
as Cache-Control take the service default. The .NET bindings get the same three options.

Breaking changes

AI Usage Statement

  • Harness: Claude Code, a coordinator session that delegated to subagents.
  • Model: Claude Opus 5.5 (claude-opus-5-5).
  • Effort: default.
  • Role: Drafted the change, the review follow-ups (content_language, RFC-8431, spec update,
    regenerated .NET bindings, the effective-capability check) and the tests under human direction. A human reviewed the change
    and submits it.
  • Assumptions and unknowns:
    • Verified on AWS S3, Silo, SeaweedFS and Garage as listed above.
    • Not checked: S3 Express One Zone, R2, Neon, Ceph and the other providers in
      compatible_services.md. The s3 service advertises the new flags for every endpoint; see
      RFC-8431 Unresolved questions.
    • The existing CorrectnessCheckLayer flags (copy_with_if_match, write_with_*, ...) are
      still checked below user layers, so CapabilityOverrideLayer does not gate them; this PR
      only moves the three new checks.

@dmxlol
dmxlol requested a review from Xuanwo as a code owner October 25, 2026 22:44
@github-actions github-actions Bot added core releases-note/feat The PR implements a new feature or has a title that begins with "feat" services/s3 size:L This PR changes 100-499 lines, ignoring generated files. labels Oct 25, 2026
@Xuanwo

Xuanwo commented Nov 20, 2026

Copy link
Copy Markdown
Member

AI-generated review: Thanks for testing same-key copy on AWS S3 and working on server-side metadata replacement (#8430).

For the public contract, OpenDAL should expose this as explicit whole-set replacement on server-side copy—backed by a short RFC and an update to the portable specifications—and advertise the corresponding capability only on services/configurations that can actually honor it (across single-request, multipart, and same-key copy, returning Unsupported before mutating when unsupported).

Two questions and follow-ups before moving forward with the implementation:

  1. Whole-set replace vs partial preservation: In this PR, calling .content_type(...) or passing only mtime in user_metadata replaces the entire metadata set on S3, clearing other user metadata and resetting omitted system headers (Cache-Control, etc.) to service defaults. Does your SETSTAT / PROPPATCH use case work with an explicit whole-set replace API (passing the full target metadata), or does it require preserving untouched fields?
  2. Scope & CI: Please add a short RFC + portable spec update specifying the replacement and same-key semantics, verify which S3-compatible services can safely advertise the capability (rather than enabling it unconditionally for all S3-like backends), and note that .NET capability generation and lua51 build checks are currently failing on this head.

@Mola-maker Mola-maker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ran the copy tests on this head. opendal-core copy tests: 13 passed, 0 failed. S3 copy tests: 11 passed, 0 failed. The new correctness test fails without the new capability guard, so it covers the change. The S3 request shape matches the documented REPLACE behavior. fmt is clean.

@Xuanwo

Xuanwo commented Nov 21, 2026

Copy link
Copy Markdown
Member

Friendly heads-up on metadata alignment! 📌

Standard Content-Language object metadata just landed in #8576 (WriteOptions.content_language, Metadata::content_language, Capability::write_with_content_language). Please keep content_language aligned with the whole-set metadata replacement semantics in this PR's RFC/spec/implementation as it moves forward.

Note: This comment was generated with AI assistance.

@dmxlol

dmxlol commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

On the first point, a whole-set replace is fine for us. Our file server only keeps two things on an object, the content type and an mtime user key, and when a client sets the mtime (SETSTAT or PROPPATCH) we stat the object and send both back anyway. So we never depend on other fields surviving. I made that explicit in the CopyOptions docs and content_language from #8576 now works the same way.

I pushed the rest you asked for (a short RFC (8431), the same rules in specs/metadata.md, a rebase on main (the lua51 failure went away with it) and the regenerated .NET files). The copy tests pass on Silo, SeaweedFS and Garage. Garage still fails the same 21 tests it fails on main, but none of them are metadata copies. I'll add an AWS run before it's ready to merge.

One thing I'm not sure about is advertising the flags. The s3 service has one capability set for all endpoints and the RFC 7948 presets aren't in yet, soI I can't turn the flags on per provider without adding new config. I could either leave them on like the other copy capabilities and document the providers I haven't tested in compatible_services.md (the way Neon is handled), or default them to off and let people opt in with CapabilityOverrideLayer. What do you think gonna be better? I'll update the RFC to match.


Also, the new flags made clippy flag large_enum_variant on the FuturesDeleteSink state, so I added an #[allow] like the one in buffer_stream.rs. Let me know if you'd rather handle that differently.

@dmxlol
dmxlol force-pushed the feat-copy-user-metadata branch from 685a652 to 3f8e63d Compare November 21, 2026 17:18
@dmxlol
dmxlol requested a review from tisonkun as a code owner November 21, 2026 17:18

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding RFC 8431, the specs/metadata.md update, content_language alignment with #8576, and the regenerated .NET bindings. Reviewing d50a8bf2, here are answers to both of your questions along with the remaining findings:

  1. S3 capability defaults: Keep copy_with_user_metadata, copy_with_content_type, and copy_with_content_language enabled by default on services/s3 (consistent with OpenDAL's maximum-capability-by-default principle and existing copy_with_if_match, copy_with_if_not_exists, and write_with_* flags), document the verified providers and known exceptions in compatible_services.md, and let users opt out with CapabilityOverrideLayer when needed. Keep explicit configuration distinctions such as is_s3_express where applicable.
  2. CapabilityOverrideLayer does not currently gate copy_with_* (blocking): Operator::new installs CorrectnessCheckLayer inside the stack (core/core/src/types/operator/builder.rs:44-49), while a user-added CapabilityOverrideLayer wraps it on the outside and only updates info().capability() while forwarding copy directly (core/core/src/layers/capability_override.rs:156-169). Because CorrectnessCheckLayer::copy reads its inner service's capability and OpCopy::from_options does not validate these three flags against the effective capability, overriding them to false still sends a mutating S3 CopyObject request (violating the Unsupported-before-mutation guarantee in specs/metadata.md), and overriding false -> true is still rejected by the inner CorrectnessCheckLayer. Please ensure the check observes the effective operator capability and add a regression test going through Operator::new(...).layer(CapabilityOverrideLayer::...) verifying Unsupported with zero requests sent when disabled.
  3. #[allow(clippy::large_enum_variant)] on FuturesDeleteSink::State is fine: Adding the third flag pushes Capability from 184 B to 192 B and Idle(Option<Deleter>) from 216 B to 224 B against the 16 B boxed-future variants (just crossing Clippy's 200 B threshold). Keeping the local #[allow(clippy::large_enum_variant)] on the private State enum (with a brief comment explaining we keep Deleter inline rather than boxing per sink) is preferable to extra allocation or unrelated Capability refactoring in this PR.
  4. Two wording tightenings for RFC 8431 and specs/metadata.md:
    • Clarify that passing the full desired set back only preserves metadata fields expressible on CopyOptions (user_metadata, content_type, content_language): other source headers such as custom Cache-Control, Content-Disposition, or Content-Encoding cannot currently be preserved through this API and reset to service defaults under S3 REPLACE.
    • For same-key copy combined with an explicit source_version, clarify that the destination receives the bytes of the selected source version rather than unconditionally preserving the current object's bytes.
  5. Behavior test & .NET doc gaps:
    • In core/tests/behavior/async_copy.rs:901-991, the first test calls .write_with(...).user_metadata(...) during setup, so its registration gate should also require write_with_user_metadata.
    • For the multipart copy metadata test, please pre-populate observable source metadata and assert content_type via stat so the test proves whole-set replacement (not only setting new values on a bare source object).
    • In bindings/dotnet/OpenDAL/Options/CopyOptions.cs:73-91, please note the whole-set replacement semantics in the property XML summaries as well (e.g., setting ContentType clears omitted user metadata).
  6. AWS S3 validation: as you noted, please include an AWS S3 run on the updated head (covering content_language and multipart replacement as well) before final merge.

(This review was generated by AI.)

Adds user_metadata and content_type to CopyOptions with matching capability flags. S3 sends x-amz-metadata-directive: REPLACE, so a same-key copy updates metadata in one zero-body CopyObject instead of a read and rewrite.
CorrectnessCheckLayer sits below user layers, so CapabilityOverrideLayer
could neither disable nor enable copy_with_user_metadata, content_type
or content_language. Run these checks in Operator instead.
Regenerate the .NET CopyOptions so the property summaries say it too.
@dmxlol
dmxlol force-pushed the feat-copy-user-metadata branch from d50a8bf to a33e593 Compare November 21, 2026 23:58
@dmxlol

dmxlol commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review, and for answering the defaults question.

I kept the three copy flags on by default for s3, like the other copy_with flags. There's a new section in the s3 compatible_services.md that lists where I actually ran the behavior tests (AWS S3, Garage v2.1.0, SeaweedFS 4.52 and Silo). It also says the other providers and S3 Express One Zone haven't been checked, and shows how to turn the flags off with CapabilityOverrideLayer. The RFC says the same now. is_s3_express doesn't change these flags because I don't know of anything Express does differently with REPLACE, and I haven't tested it, so it's listed as unverified.

You were right about CapabilityOverrideLayer. I moved the three checks out of CorrectnessService::copy into a small helper that Operator calls right after OpCopy::from_options, using the capability of the composed stack. Turning a flag off now gives Unsupported before any request, and turning one on is no longer rejected further down. The new test goes through Operator::new(...).layer(CapabilityOverrideLayer::...) with a mock service that counts copy calls, and checks both directions (zero copies when disabled). While doing this I noticed the existing CorrectnessCheckLayer flags have the same problem: copy_with_if_match=false through the override layer still sends the copy, and the write/read/stat ones are built the same way. I didn't touch those here to keep this PR focused, but I'm happy to open an issue or a follow-up if you want to fix it in general.

The large_enum_variant allow stays, with a comment that Deleter is kept inline rather than boxed per sink.

The RFC and specs/metadata.md now say that sending the set back only keeps what CopyOptions can carry (user_metadata, content_type, content_language), and that Cache-Control, Content-Disposition and Content-Encoding fall back to service defaults under REPLACE. They also say that a same-key copy with source_version gives the destination the bytes of that version.

For the tests, the in-place user metadata test now also needs write_with_user_metadata. The multipart test writes its source with user metadata and text/plain first, then checks via stat that the old key is gone and the content type is no longer text/plain. The .NET summaries come from the first paragraph of the Rust docs, so I reworded those and regenerated, and the C# properties now say the whole set is replaced.

I reran everything on the new head after rebasing on main. On a versioned AWS S3 bucket all the copy tests pass, including both source_version tests and the three metadata ones (multipart with content_language too). The only 8 failures there are delete and restore by version, because my IAM user isn't allowed s3:DeleteObjectVersion, and main fails the same 8 with the same config. SeaweedFS is 149 of 149 and Silo is 136 of 136. I didn't rerun Garage this time. The two red checks are the Label workflow, which is getting HTTP 410 from its endpoint on every PR right now, so they aren't from this change.

@Xuanwo
Xuanwo merged commit 1276b36 into apache:main Nov 22, 2026
124 of 127 checks passed
@dmxlol
dmxlol deleted the feat-copy-user-metadata branch November 22, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core releases-note/feat The PR implements a new feature or has a title that begins with "feat" services/s3 size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new feature: copy_with should be able to replace user metadata and content type (S3 x-amz-metadata-directive REPLACE)

3 participants