Skip to content

rgw: CompleteMultipartUpload renews cls_lock on multipart meta object - #67696

Merged
cbodley merged 10 commits into
ceph:mainfrom
cbodley:wip-75375
Mar 23, 2026
Merged

cbodley merged 10 commits into
ceph:mainfrom
cbodley:wip-75375

Conversation

@cbodley

@cbodley cbodley commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

when a client retries a CompleteMultipartUpload request, it's possible that the earlier request had successfully written the head object. in that case, the retried request will overwrite that head object and schedule all of its tail objects for garbage collection

because the retried CompleteMultipartUpload request is likely using most/all of the same part objects as the initial request, this new object will become corrupted once garbage collection takes effect

to address this, store the multipart upload id in an xattr of the head object, and prevent multipart uploads from overwriting an existing head object with the same upload id

to address this, prevent the 'multipart meta' object's cls_lock from expiring by spawning a lock renewal coroutine. as long as the lock is held, racing CompleteMultipartUpload requests won't be able to observe the upload in an intermediate state and write a conflicting update to its head object

Fixes: https://tracker.ceph.com/issues/75375

Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@github-actions github-actions Bot added the rgw label Mar 6, 2026
@cbodley
cbodley force-pushed the wip-75375 branch 2 times, most recently from 3a73a6d to b63d7ae Compare March 6, 2026 17:56
because the lock renewal request is sent every half interval, don't
allow the lock duration to get small enough that rados request latency
becomes significant

Signed-off-by: Casey Bodley <[email protected]>
@github-actions

github-actions Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

Config Diff Tool Output

+ added: rgw_mp_lock_inject_renewal_error (rgw.yaml.in)
+ added: rgw_mp_lock_inject_delay (rgw.yaml.in)
! changed: rgw_mp_lock_max_time: old:  (rgw.yaml.in)
! changed: rgw_mp_lock_max_time: new: 2_min (rgw.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

@cbodley

cbodley commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

i've replaced the old strategy based on cmpxattr(), but preserved that commit in https://github.com/cbodley/ceph/commits/wip-75375-cmpxattr

@cbodley cbodley changed the title rgw/rados: detect and prevent racing CompleteMultipartUpload rgw: CompleteMultipartUpload renews cls_lock on multipart meta object Mar 12, 2026
@cbodley
cbodley marked this pull request as ready for review March 12, 2026 15:23
@cbodley
cbodley requested a review from a team as a code owner March 12, 2026 15:23
Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved

@adamemerson adamemerson 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.

This looks good and well-thought-out.

Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved
Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved
Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved
@cbodley

cbodley commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

i added a commit with some config options that i'm using to test this. i'm currently debugging some crashes from stop_renewal() under ~MPRadosSerializer() from that reproducer

@cbodley

cbodley commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

i'm currently debugging some crashes from stop_renewal() under ~MPRadosSerializer() from that reproducer

the crash came from coroutine cancellation, which was forwarding the cancellation signal to its timer. but that timer was on the coroutine's stack, and was already destroyed when the coroutine returned:

 ceph version Development (no_version) tentacle (dev - Debug)
 1: /home/cbodley/ceph/build/bin/radosgw(+0x9b1a05) [0x559d16ff6a05]
 2: /lib64/libc.so.6(+0x1a290) [0x7f5596e27290]
 3: (boost::asio::detail::timer_queue<boost::asio::detail::chrono_time_traits<ceph::coarse_mono_clock, boost::asio::wait_traits<ceph::coarse_mono_clock> > >::cancel_timer_by_key(boost::asio::detail::timer_queue<boost::asio::detail::chrono_time_traits<ceph::coarse_mono_clock, boost::asio::wait_traits<ceph::coarse_mono_clock> > >::per_timer_data*, boost::asio::detail::op_queue<boost::asio::detail::scheduler_operation>&, void*)+0xa7) [0x559d16702d95]
 4: (void boost::asio::detail::epoll_reactor::cancel_timer_by_key<boost::asio::detail::chrono_time_traits<ceph::coarse_mono_clock, boost::asio::wait_traits<ceph::coarse_mono_clock> > >(boost::asio::detail::timer_queue<boost::asio::detail::chrono_time_traits<ceph::coarse_mono_clock, boost::asio::wait_traits<ceph::coarse_mono_clock> > >&, boost::asio::detail::timer_queue<boost::asio::detail::chrono_time_traits<ceph::coarse_mono_clock, boost::asio::wait_traits<ceph::coarse_mono_clock> > >::per_timer_data*, void*)+0x63) [0x559d16702e8d]
 5: (boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<ceph::coarse_mono_clock, boost::asio::wait_traits<ceph::coarse_mono_clock> > >::op_cancellation::operator()(boost::asio::cancellation_type)+0x25) [0x559d16702f57]
 6: (boost::asio::detail::cancellation_handler<boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<ceph::coarse_mono_clock, boost::asio::wait_traits<ceph::coarse_mono_clock> > >::op_cancellation>::call(boost::asio::cancellation_type)+0xd) [0x559d16702f69]
 7: (boost::asio::cancellation_signal::emit(boost::asio::cancellation_type)+0x11) [0x559d1668bfa1]

i'm not sure why the cancellation slot still refers to the timer - i've seen this pattern work fine elsewhere. but moving the timer into a member variable so it's still in scope during the destructor seems to resolve the crash

Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved
@cbodley

cbodley commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor Author

for testing, i ran vstart with these arguments:

~/ceph/build $ MON=1 OSD=1 RGW=1 MDS=0 MGR=0 ../src/vstart.sh -n -d -o rgw_mp_lock_max_time=120 -o rgw_mp_lock_inject_delay=90 -o rgw_mp_lock_inject_renewal_error=-5

then started a single multipart upload:

~/ceph/build $ s3cmd put 32m.iso s3://testbucket

log trace of that CompleteMultipartUpload request shows the request failing with 500 before calling upload->complete():

2026-03-13T15:03:29.213-0400 7f3543b3c6c0 10 req 2971880474634148460 0.004000127s s3:complete_multipart MPSerializer injecting delay after lock...

2026-03-13T15:04:29.214-0400 7f35483456c0  0 req 2971880474634148460 60.004901886s s3:complete_multipart MPSerializer lock renewal on 33d99774-f0f5-43e9-a70e-90c47b6c7d57.4179.1__multipart_32m.iso.2~WxvNVM2xvrHHvZPqNWk_LIrsyckaRCI.meta failed with injected error -5

2026-03-13T15:04:59.214-0400 7f353b32b6c0 10 req 2971880474634148460 90.004898071s s3:complete_multipart MPSerializer waking up after injected delay

2026-03-13T15:04:59.217-0400 7f3538b266c0  2 req 2971880474634148460 90.007896423s s3:complete_multipart completing
2026-03-13T15:04:59.217-0400 7f3538b266c0  2 req 2971880474634148460 90.007896423s s3:complete_multipart op status=-2200
2026-03-13T15:04:59.217-0400 7f3538b266c0  2 req 2971880474634148460 90.007896423s s3:complete_multipart http status=500
2026-03-13T15:04:59.217-0400 7f3538b266c0  1 ====== req done req=0x7f344c92c5f0 op=complete_multipart bucket=testbucket status=-2200 http_status=500 latency=90.007896423s request_id=tx00000293e3d8bc57cda6c-0069b45f81-4179-default ======

the same test without rgw_mp_lock_inject_renewal_error shows a lock renewal request after 60 seconds, ultimately leading to successful completion:

2026-03-13T15:08:49.559-0400 7fd5ed80c6c0 10 req 5920454612185578595 0.012000400s s3:complete_multipart MPSerializer injecting delay after lock...

2026-03-13T15:09:49.560-0400 7fd5f20156c0  1 -- 192.168.245.130:0/2015141479 --> [v2:192.168.245.130:6800/1798756718,v1:192.168.245.130:6801/1798756718] -- osd_op(unknown.0.0:1000 6.0 6:05ca866a:::996fba6d-33db-4105-a4f5-3334c59e6503.4179.1__multipart_32m.iso.2~iZEgc_fK5dDzg1HGTGRadmkZ0qEEtnq.meta:head [stat,call lock.lock in=60b] snapc 0=[] ondisk+write+known_if_redirected+full_try+supports_pool_eio e21) -- 0x55efd3b1e000 con 0x55efd0f66000
2026-03-13T15:09:49.562-0400 7fd6821356c0  1 -- 192.168.245.130:0/2015141479 <== osd.0 v2:192.168.245.130:6800/1798756718 1003 ==== osd_op_reply(1000 996fba6d-33db-4105-a4f5-3334c59e6503.4179.1__multipart_32m.iso.2~iZEgc_fK5dDzg1HGTGRadmkZ0qEEtnq.meta [stat,call] v21'6 uv6 ondisk = 0) ==== 287+0+0 (crc 0 0 0) 0x55efd0f88900 con 0x55efd0f66000

2026-03-13T15:10:19.560-0400 7fd5e88026c0 10 req 5920454612185578595 90.012992859s s3:complete_multipart MPSerializer waking up after injected delay

2026-03-13T15:10:19.572-0400 7fd5e80016c0  2 req 5920454612185578595 90.024993896s s3:complete_multipart completing
2026-03-13T15:10:19.572-0400 7fd5e80016c0  2 req 5920454612185578595 90.024993896s s3:complete_multipart op status=0
2026-03-13T15:10:19.572-0400 7fd5e80016c0  2 req 5920454612185578595 90.024993896s s3:complete_multipart http status=200
2026-03-13T15:10:19.572-0400 7fd5e80016c0  1 ====== req done req=0x7fd55b6a55f0 op=complete_multipart bucket=testbucket status=0 http_status=200 latency=90.024993896s request_id=tx000005229ae1a1424fc63-0069b460c1-4179-default ======
2026-03-13T15:10:19.572-0400 7fd5db7e86c0 20 req 5920454612185578595 90.024993896s s3:complete_multipart MPSerializer lock renewal canceled

Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved
Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved
cbodley added 3 commits March 17, 2026 14:05
if lock renewal fails, is_locked() will return false. check that just
before upload->complete() goes on to write/overwrite the head object,
and return the same ERR_INTERNAL_ERROR from lock contention

Fixes: https://tracker.ceph.com/issues/75375

Signed-off-by: Casey Bodley <[email protected]>
make it safe for other threads to call clear_locked() and is_locked()

Signed-off-by: Casey Bodley <[email protected]>
this duration ultimately gets passed down to cls_lock's set_duration()
function, which has overloads for both utime_t and ceph::timespan.
prefer ceph::timespan because it also works with boost asio timers

Signed-off-by: Casey Bodley <[email protected]>
@cbodley

cbodley commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

updated to replace the blocking waits on std::future with optional-yielding waits on ceph::async::async_cond. the testing shown above with rgw_mp_lock_inject_delay and rgw_mp_lock_inject_renewal_error still works correctly, with and without rgw_beast_enable_async

cbodley added 3 commits March 17, 2026 18:52
CompleteMultipartUpload depends on this lock to ensure consistency of
uploads and protect against data loss, so we should try very hard to
hold this lock as long as it takes to complete successfully

MPRadosSerializer accomplishes this by spawning a background lock
renewal coroutine. this coroutine is started during a successful call to
try_lock(), and stopped before unlock() releases the lock

Fixes: https://tracker.ceph.com/issues/75375

Signed-off-by: Casey Bodley <[email protected]>
rgw_mp_lock_inject_delay can inject delays in multipart complete to make
sure lock renewal requests get issued

rgw_mp_lock_inject_renewal_error can inject lock renewal errors to test
the error handling

Signed-off-by: Casey Bodley <[email protected]>
Comment thread src/rgw/rgw_op.cc
Comment on lines +7555 to +7559
if (!serializer->is_locked()) {
// lock renewal failed, it's not safe to commit the head object
op_ret = -ERR_INTERNAL_ERROR;
s->err.message = "This multipart completion is already in progress";
return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added commits to set/clear is_locked() for dbstore and posix backends (cc @dang)

@cbodley

cbodley commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

passed qa after reruns for dead jobs:
https://pulpito.ceph.com/cbodley-2026-03-19_17:30:12-rgw-wip-75375-distro-default-trial/
https://pulpito.ceph.com/cbodley-2026-03-19_19:57:43-rgw-wip-75375-distro-default-trial/
https://pulpito.ceph.com/cbodley-2026-03-20_13:37:48-rgw-wip-75375-distro-default-trial/

2 rgw/multisite jobs failed with:

FAIL: rgw_multi.tests.test_bucket_remove
FAIL: rgw_multi.tests.test_period_update_commit
FAIL: rgw_multi.tests.test_bucket_log_trim_after_delete_bucket_secondary_reshard
FAIL: rgw_multi.tests.test_copy_object_same_bucket
FAIL: rgw_multi.tests.test_copy_object_different_bucket

17 other jobs failed with "valgrind error: SyscallParam" tracked in https://tracker.ceph.com/issues/73437

@cbodley

cbodley commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

@cbodley

cbodley commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@adamemerson adamemerson 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.

This is a good PR.

Comment thread src/rgw/driver/rados/rgw_sal_rados.cc Resolved
@cbodley
cbodley merged commit c1f7de9 into ceph:main Mar 23, 2026
5 of 6 checks passed
@cbodley
cbodley deleted the wip-75375 branch March 23, 2026 15:19
jhoblitt added a commit to jhoblitt/rgw-go that referenced this pull request Oct 6, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants