Repository navigation
Conversation
Once a completion writes the head, it deletes the upload's meta object. If RGW dies between the two, or the delete fails, the meta object survives with its part list. A retried completion then writes the head again and sends the replaced manifest, the same parts, to GC, and an abort, or lifecycle's, sends the parts to GC directly. Either way the completed object loses its data. In a non-versioned bucket, write the completion's tag, the ID tag its head will carry, to the meta object (user.rgw.mp_completion_tag) before the head write, and remove it if the head write fails for sure. A completion or abort that finds a record reads the head: - if the head carries the tag, the earlier completion took effect. A completion with the same part list answers success, and the caller deletes the meta object; an abort deletes only the meta object. - otherwise the head was never written, or was replaced and its parts sent to GC. A completion answers NoSuchUpload rather than write a head over those parts, and an abort proceeds as before. The cost: a retry after a crash between the record and the head write is refused, and the upload has to be aborted and uploaded again. Versioned buckets are left as they are. Fixes: https://tracker.ceph.com/issues/80896 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Kyle Bader <[email protected]>
The completion record was skipped when bucket->versioned() is true, which is so with versioning enabled and with it suspended, and it was checked against the current version of the key. Both leave the data of a completed upload exposed in a versioned bucket: - with versioning suspended, a retry replaces the null version and sends its parts to GC, as in a bucket that is not versioned; - with versioning enabled, a retry writes a second version that shares the first one's parts, so deleting either version loses the other, and an abort sends the parts of the completed version to GC; - a check against the current version misses a completed version that a later write made noncurrent, and an abort then sends its parts to GC. Record the completion in every bucket, with the version instance it writes: its own instance with versioning enabled, which RGWCompleteMultipart generates before complete(), and "null" otherwise, which names the key's head object and is read without following the olh. Check the record against that instance. A replay answers with the version id the earlier completion wrote. A record without an instance is read as "null". Tested on vstart with rgw_debug_inject_mp_meta_delete_err: a retry followed by a delete of the first version, an abort, and an abort after a later PutObject, with versioning enabled; a retry and an abort with it suspended. Each loses the object's data without this change and keeps it with it. The P model (PR 72110) checks the same scenarios. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Kyle Bader <[email protected]>
|
jenkins test make check |
…rt lock Complete takes radosgw's exclusive lock on the meta object with assert_exists in the same op, validates the parts in lockstep with the stored ones page by page, appends their manifests, merges compressed parts' block maps, and writes the ETag-of-ETags head atomically under the request's tag with the meta object's attrs and v20.2.4's conditions on both releases. A lock that meets no meta object answers a re-sent completion as each release does: without an ETag on Squid, with the stored one on Tentacle. A bucket whose versioning is enabled or suspended, or that has object lock, answers 501 before the store is touched, as the other writes do until versioning is served. The parts stay whole until the head is written: their index entries go with the meta object's removal rather than the head write's index change, whose cancel would drop them (tracker #80907), and their history is queued for the GC after the head write. Before writing, the completion stats each part head and renews the lock with MUST_RENEW, failing closed when it is gone (tracker #75375). The renewal's op also writes the completion record of ceph/ceph#72103, the head's tag and instance, which a head write that certainly failed takes back. A completion that finds a record finishes the earlier one only when the key's head still carries the tag and the ETag, and otherwise answers NoSuchUpload, so a retry after the completed object was overwritten or deleted writes no head over parts queued for the GC (tracker #80896); a meta object without a record is checked against the head's manifest instead. The meta object's removal retries behind cls_version_check and collects parts that raced in, keeping the completed parts out of that cleanup. A completion that loses its head write's race answers success as radosgw does, with the time its head would have carried, and leaves its parts unqueued, since the winner may be another completion of the same upload. op.SortCompleteParts sorts and de-duplicates the parts as radosgw's std::map does, for the driver and the memstore, which also honors the conditions and keeps the write tag; op.Upload gains WriteTag, IfMatch and IfNoneMatch, and Open reads rgw_mp_lock_max_time and rgw_multipart_min_part_size. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A refused completion drops its parts' index entries (tracker #80907); a completion whose meta object outlives its head write lets a retry or an abort delete the object's data (tracker #80896), which rgw-go closes with the completion record of ceph/ceph#72103; the completion lock is not kept past rgw_mp_lock_max_time at the floor releases (tracker #75375, fixed on main by ceph/ceph#67696); several GC chains sent under one tag leave only the last on a gc shard still on the omap log; and a completion that loses its head write's race answers success and leaks its parts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…osgw The completion records itself on the meta object in ceph/ceph#72103's format, a coexistence obligation with radosgw. It checks the part heads, keeps the parts' index entries and history until its head is written, finishes rather than rewrites an earlier completion of its upload, and renews its lock before the head write, with the window that leaves. It honors If-Match and If-None-Match on Squid too, answers 501 in a versioned or object-lock bucket, refuses a stored part ETag that is not an MD5 and an upload holding an explicit part manifest, and reads its two options once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This is @jhoblitt's AI agent. On the complete-replay path this PR can send the completed object's own parts to GC, reintroducing the #80896 data loss in a narrower window. Pinned to the current head When a retried Because the first completion left the meta object behind, its part index entries were never removed, so
Suggested fix, two options:
This is a narrow window (meta object left behind, then a part upload races the replay's meta delete), and the data lost is the actor's own just-completed object, so it isn't cross-tenant — but it is the same data loss this PR is meant to prevent, so it seemed worth flagging. Not reproduced on a running cluster; this is from reading the current head. |
thanks @jhoblitt. this check for RGW_ATTR_MP_COMPLETION_TAG happens before the do-while-list-parts loop can initialize processed_prefixes for cleanup_orphaned_parts(). can we move the check just below the loop instead? since this fix is for a crash recovery case between the head object write and the meta object's deletion, it's possible that cleanup_orphaned_parts() already did some of this cleanup in between. we'd need to make sure it's safe to re-run cleanup_orphaned_parts() in this new case where RadosMultipartUpload::complete() returns success because of RGW_ATTR_MP_COMPLETION_TAG |
|
for test coverage to reproduce the above, i think we'd need a multipart upload where one or more parts are re-uploaded before completion |
it looks like that is safe. another call to cleanup_orphaned_parts() may resubmit part objects for gc with send_chain_to_gc() or delete_objs_inline(), but they'll use the same refcount tag (the multipart upload id) so only a single ref would be removed |
cbodley
left a comment
There was a problem hiding this comment.
identified some additional issues, will start working through them
| const std::string& instance = target_obj->get_instance(); | ||
| bufferlist tag_bl; | ||
| tag_bl.append(tag.c_str(), tag.size() + 1); | ||
| ret = set_completion_record(dpp, y, &tag_bl, instance.empty() ? "null" : instance); |
There was a problem hiding this comment.
there's a window between get_info()'s check for RGW_ATTR_MP_COMPLETION_TAG and this later call to set_completion_record() that assigns it, so multiple racing callers could succesfully set it here. set_completion_record() should use cmpxattr to detect those races, ex
+ // assert that we haven't set a completion tag yet
+ op.cmpxattr(RGW_ATTR_MP_COMPLETION_TAG, LIBRADOS_CMPXATTR_OP_EQ, bufferlist());
op.setxattr(RGW_ATTR_MP_COMPLETION_TAG, *tag);| const auto record = meta_attrs.find(RGW_ATTR_MP_COMPLETION_TAG); | ||
| if (record != meta_attrs.end()) { | ||
| std::unique_ptr<rgw::sal::Object> head = recorded_head(meta_attrs); | ||
| ret = head_carries(dpp, y, head.get(), record->second); |
There was a problem hiding this comment.
RadosMultipartUpload::abort() checks for this RGW_ATTR_MP_COMPLETION_TAG in an attempt to detect races with complete(), but doesn't itself call set_completion_record() to signal an abort. shouldn't complete() have a way to detect races with abort()?
There was a problem hiding this comment.
note that CompleteMultipartUpload may have written this RGW_ATTR_MP_COMPLETION_TAG, but not yet written the head object
if abort() runs in between those writes, head_carries() would return 0 and we'd garbage collect the tail objects that CompleteMultipartUpload will end up pointing to
we don't know for sure that RGW_ATTR_MP_COMPLETION_TAG signifies a crash, so i don't think we can safely run any recovery logic here. instead, i think we just need to use the atomic set_completion_record() to prevent any later abort/complete calls from proceeding
There was a problem hiding this comment.
quoting the pr description:
The cost: a retry after a crash between the record and the head write is refused, and the upload has to be aborted and uploaded again.
i don't see how AbortMultipartUpload can handle this case when it finds an upload with RGW_ATTR_MP_COMPLETION_TAG set. if it can't prove that the original request will not eventually succeed, it can't safely schedule any tail objects for garbage collection without risk of data loss
it may be able to remove the multipart meta object so it's no longer displayed by ListMultipartUploads, but that risks leaking some tail objects that the original request would have handled in cleanup_orphaned_parts()
| rgw::sal::Attrs meta_attrs; | ||
| ret = get_info(dpp, y, nullptr, &meta_attrs); |
There was a problem hiding this comment.
as previously mentioned:
this check for RGW_ATTR_MP_COMPLETION_TAG happens before the do-while-list-parts loop can initialize processed_prefixes for cleanup_orphaned_parts(). can we move the check just below the loop instead?
we're already calling get_info() below this loop, so we don't need to send an additional read here
| // the part list must be the one the earlier completion used | ||
| for (const auto& [num, part_etag] : part_etags) { | ||
| char petag[CEPH_CRYPTO_MD5_DIGESTSIZE]; | ||
| hex_to_buf(rgw_string_unquote(part_etag).c_str(), petag, CEPH_CRYPTO_MD5_DIGESTSIZE); | ||
| hash.Update((const unsigned char *)petag, sizeof(petag)); | ||
| } | ||
| hash.Final((unsigned char *)final_etag); | ||
| std::string want; | ||
| buf_to_hex(final_etag, std::back_inserter(want)); | ||
| fmt::format_to(std::back_inserter(want), "-{}", part_etags.size()); |
There was a problem hiding this comment.
the do-while-list-parts loop is already summing up the part etags, and the result is stored in attrs[RGW_ATTR_ETAG]. once this logic moves below, we can just compare against that
| // the head was not written, so a retry may still complete the upload | ||
| std::ignore = set_completion_record(dpp, y, nullptr, {}); |
There was a problem hiding this comment.
clearing the completion tag here is probably important, but racing requests could observe this intermediate RGW_ATTR_MP_COMPLETION_TAG and, because the head object wasn't written successfully, return ERR_NO_SUCH_UPLOAD even though a later request to Abort/Complete may succeed
| del_op->params.bucket_owner = bucket->get_info().owner; | ||
| del_op->params.versioning_status = 0; | ||
| del_op->params.objv_tracker = &objv_tracker; | ||
| ret = del_op->delete_obj(dpp, y, 0); |
There was a problem hiding this comment.
if a racing call to CompleteMultipartUpload successfully wrote the head object but is still looping through cleanup_orphaned_parts(), deleting this meta object prematurely would leak part objects
when reading attributes from the multipart meta object, treat errors as fatal to the upload Signed-off-by: Casey Bodley <[email protected]>
detect racing calls to set_completion_record() so that only one can succeed Signed-off-by: Casey Bodley <[email protected]>
in the case where RadosMultipartUpload::complete() finds an already-completed upload and returns success, we'll go on to call cleanup_orphaned_parts(). however, that function depends on the set of processed_prefixes initialized in the do-while-list-parts loop below. so the RGW_ATTR_MP_COMPLETION_TAG check needs to happen after that loop to make this RGW_ATTR_MP_COMPLETION_TAG check atomic with respect to its assignment, we now only do this check in response to an ECANCELED error from set_completion_record(). there, we re-read the updated RGW_ATTR_MP_COMPLETION_TAG to determine whether or not to return success Signed-off-by: Casey Bodley <[email protected]>
if AbortMultipartUpload starts before CompleteMultipartUpload writes a head object, it would garbage collect the tail objects even though CompleteMultipartUpload could go on to succeed to prevent this case, Abort also needs to write this RGW_ATTR_MP_COMPLETION_TAG to prevent a racing Complete from assigning one itself on any failure to set this RGW_ATTR_MP_COMPLETION_TAG, Abort fails with NoSuchUpload. this means that Abort cannot reliably clean up after Complete requests that crash after setting that tag Signed-off-by: Casey Bodley <[email protected]>
|
i pushed some commits trying to improve on this design, but i'm still not convinced that it's workable |
thinking more on this, cleanup_orphaned_parts() probably isn't safe in this already-completed case the do-while-list-parts loop selects the processed_prefixes of the parts it will include in the final upload, so that cleanup_orphaned_parts() can remove any listed parts that weren't included. this is mainly for individual parts that were uploaded more than once - the final upload will only use the latest one, and we rely on cleanup_orphaned_parts() to remove the others for a retried CompleteMultipartUpload, there's a risk that other racing part reuploads happened in the meantime. so this do-while-list-parts loop may select a different set of parts for processed_prefixes, causing cleanup_orphaned_parts() to remove some parts that were actually included in the original complete when a retried CompleteMultipartUpload finds a RGW_ATTR_MP_COMPLETION_TAG, it relies on tag/etag comparisons to ensure that it's completing the same upload. but the etag comparison doesn't catch this case where the same part was reuploaded with a different prefix. but we should be able to learn which part prefixes the original upload used from the head object's manifest |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
Once a completion writes the head, it deletes the upload's meta object. If RGW dies between the two, or the delete fails, the meta object survives with its part list. A retried completion then writes the head again and sends the replaced manifest, the same parts, to GC; an abort, or lifecycle's, sends the parts to GC directly. Either way the completed object loses its data.
In every bucket, write the completion's tag, the ID tag its head will carry, and the version instance it writes to the meta object (
user.rgw.mp_completion_tag,user.rgw.mp_completion_instance) before the head write, and remove them if the head write fails for sure. The instance is the completion's own with versioning enabled, which RGWCompleteMultipart generates before complete(), and "null" otherwise, which names the key's head object and is read without following the olh. A completion or abort that finds a record reads that instance's head:The cost: a retry after a crash between the record and the head write is refused, and the upload has to be aborted and uploaded again. It does not help a holder whose lock lapses before its head write.
The s3-tests
test_multipart_complete_retry_after_meta_delete_errorandtest_multipart_abort_after_meta_delete_error(https://github.com/mmgaggle/s3-tests/tree/wip-rgw-overwrite-races), which make the meta delete fail with the debug option in #72096, fail on main and pass with this change on a vstart cluster. The design was checked with a formal model (https://github.com/mmgaggle/ceph/tree/cdbbbb09245535782e91503ad45b0cc7a423e10d/src/test/formal/p/rgw_overwrite) with a crash, or a failed meta delete, in the multipart scenarios.Versioned buckets
The first version of this change skipped versioned buckets, and checked the record against the current version. With versioning suspended, a retry then replaced the null version and sent its parts to GC. With versioning enabled, a retry wrote a second version that shared the first one's parts, and an abort sent the parts of the completed version to GC; a check against the current version also missed a completed version that a later write made noncurrent. The record now names the instance, and every bucket records it.
The s3-tests
test_multipart_complete_retry_after_meta_delete_error_versioned,test_multipart_abort_after_meta_delete_error_versionedandtest_multipart_abort_after_overwrite_versioned, and the retry and abort tests with_suspended, fail without the record and pass with it. The P model (#72110) checks the record skipped, checked against the current version, and naming the instance, with versioning enabled and suspended: only naming the instance holds in every scenario.Fixes: https://tracker.ceph.com/issues/80896
Checklist