Repository navigation
feat(core): copy_with can replace user metadata and content type - #8431
Conversation
|
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 Two questions and follow-ups before moving forward with the implementation:
|
Mola-maker
left a comment
There was a problem hiding this comment.
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.
|
Friendly heads-up on metadata alignment! 📌 Standard Note: This comment was generated with AI assistance. |
|
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. |
685a652 to
3f8e63d
Compare
Xuanwo
left a comment
There was a problem hiding this comment.
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:
- S3 capability defaults: Keep
copy_with_user_metadata,copy_with_content_type, andcopy_with_content_languageenabled by default onservices/s3(consistent with OpenDAL's maximum-capability-by-default principle and existingcopy_with_if_match,copy_with_if_not_exists, andwrite_with_*flags), document the verified providers and known exceptions incompatible_services.md, and let users opt out withCapabilityOverrideLayerwhen needed. Keep explicit configuration distinctions such asis_s3_expresswhere applicable. CapabilityOverrideLayerdoes not currently gatecopy_with_*(blocking):Operator::newinstallsCorrectnessCheckLayerinside the stack (core/core/src/types/operator/builder.rs:44-49), while a user-addedCapabilityOverrideLayerwraps it on the outside and only updatesinfo().capability()while forwardingcopydirectly (core/core/src/layers/capability_override.rs:156-169). BecauseCorrectnessCheckLayer::copyreads its inner service's capability andOpCopy::from_optionsdoes not validate these three flags against the effective capability, overriding them tofalsestill sends a mutating S3CopyObjectrequest (violating theUnsupported-before-mutation guarantee inspecs/metadata.md), and overridingfalse->trueis still rejected by the innerCorrectnessCheckLayer. Please ensure the check observes the effective operator capability and add a regression test going throughOperator::new(...).layer(CapabilityOverrideLayer::...)verifyingUnsupportedwith zero requests sent when disabled.#[allow(clippy::large_enum_variant)]onFuturesDeleteSink::Stateis fine: Adding the third flag pushesCapabilityfrom 184 B to 192 B andIdle(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 privateStateenum (with a brief comment explaining we keepDeleterinline rather than boxing per sink) is preferable to extra allocation or unrelatedCapabilityrefactoring in this PR.- 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 customCache-Control,Content-Disposition, orContent-Encodingcannot currently be preserved through this API and reset to service defaults under S3REPLACE. - 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.
- Clarify that passing the full desired set back only preserves metadata fields expressible on
- Behavior test &
.NETdoc 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 requirewrite_with_user_metadata. - For the multipart copy metadata test, please pre-populate observable source metadata and assert
content_typeviastatso 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., settingContentTypeclears omitted user metadata).
- In
- AWS S3 validation: as you noted, please include an AWS S3 run on the updated head (covering
content_languageand 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.
d50a8bf to
a33e593
Compare
|
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. |
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?
CopyOptionsgetsuser_metadata,content_typeandcontent_language, named as inWriteOptions.copy_withandcopier_withget matching builder methods, andOpCopygets matching getters.
values and every unset field takes the service default. Documented on
CopyOptions, inRFC-8431 and in
specs/metadata.md.copy_with_user_metadata,copy_with_content_typeandcopy_with_content_language.Operatorchecks them against the effective capability of thecomposed stack and returns
Unsupportedbefore any request, so aCapabilityOverrideLayercan 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 andshows the
CapabilityOverrideLayeropt-out.Operator::copy*acceptsfrom == towhen one of the options is set.x-amz-metadata-directive: REPLACEwithContent-Type,Content-Languageandx-amz-meta-*; a multipart copy sets them on CreateMultipartUpload.specs/metadata.md, one line inspecs/conditional-operations.md).CopyOptions).#[allow(clippy::large_enum_variant)]on theFuturesDeleteSinkstate: the largerCapabilitypushed it over clippy's threshold.OpCopyoptions round trip; correctness-check tests (Unsupported, same-path copy);capability_override_gates_copy_metadata(throughOperator::new(...).layer(...), zero copycalls 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_placeandtest_copy_with_metadata_multipart.Tested against (AWS, Silo and SeaweedFS rerun on the current head; Garage on the previous one):
aws_s3_with_versioningoverrides): 151 of 159. All copytests pass, including the
source_versiontests and the three new metadata tests. The 8 failuresare versioned delete and restore tests, denied
s3:DeleteObjectVersionfor the test IAM user;they fail the same way on
main.fixtures/s3): full suite 136 of 136.fixtures/s3/docker-compose-seaweedfs.yml): full suite 149 of 149.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 anyof 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
claude-opus-5-5).regenerated .NET bindings, the effective-capability check) and the tests under human direction. A human reviewed the change
and submits it.
compatible_services.md. Thes3service advertises the new flags for every endpoint; seeRFC-8431 Unresolved questions.
CorrectnessCheckLayerflags (copy_with_if_match,write_with_*, ...) arestill checked below user layers, so
CapabilityOverrideLayerdoes not gate them; this PRonly moves the three new checks.