Repository navigation
Conversation
In a versioning-enabled bucket, a write goes to a new instance head, which nothing guards: set_attr_id_tag requires an empty instance. A conditional write checks its condition against the current version, as get_current_version_state reads it, then writes its instance and makes it current with set_olh. Another write can become current in between, so two PutObjects with If-None-Match: * on a new key both succeed, and so do two If-Match writes on one ETag, a completion with either header, and two conditional deletes that each write a delete marker. S3 lets the first succeed and refuses the others. Check the condition again where the new version becomes current: rgw_bucket_link_olh, the one cls op on the index shard that holds the key's olh entry, and already the place that refuses a stale link (unmod_since). rgw_cls_link_olh_op gains an optional condition, and its encoding goes to v6: - NO_CURRENT: the key has no current version, or a delete marker. A key without an olh entry but with a plain entry from before versioning has one. - CURRENT_IS: the current version is the given instance, which the write checked its condition against. A link that fails its condition is refused with CLS_RGW_ERR_PRECONDITION_FAILED, which is rgw's ERR_PRECONDITION_FAILED and is answered 412; set_olh does not retry it. _do_write_meta passes the condition for a conditional write to a versioned key, and delete_obj for a conditional delete marker. The refused instance is left as any failed link leaves one, not listed, for "bucket check unlinked" to remove, and its data objects are deleted as for any failed write. An OSD that has not been upgraded decodes the v6 op as v5 and links without the condition, as before. Fixes: https://tracker.ceph.com/issues/80925 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Kyle Bader <[email protected]>
| // against the current version the check above saw (tracker #80925) | ||
| cls_rgw_link_olh_cond link_cond; | ||
| if ((meta.if_match || meta.if_nomatch) && | ||
| (!target->obj.key.instance.empty() || is_olh)) { |
There was a problem hiding this comment.
in a suspended bucket, don't both writes hit the same head before the link check runs? if so, couldn't the one that gets precondition failed still overwrite the winner's data?
There was a problem hiding this comment.
Yes. Coming up with a fix.
| if (current_state == &no_current_version || !current_state->exists) { | ||
| link_cond.type = cls_rgw_link_olh_cond::NO_CURRENT; | ||
| } else { | ||
| link_cond.type = cls_rgw_link_olh_cond::CURRENT_IS; |
There was a problem hiding this comment.
doesn't this fail If-Match: * whenever another put replaces the object in between, even though the object still exists?
| if (versioned_op && meta.olh_epoch) { | ||
| bool add_log = log_op && store->svc.zone->need_to_log_data(); | ||
| r = store->set_olh(rctx.dpp, target->get_ctx(), target->get_bucket_info(), obj, false, NULL, *meta.olh_epoch, real_time(), false, rctx.y, meta.zones_trace, add_log); | ||
| r = store->set_olh(rctx.dpp, target->get_ctx(), target->get_bucket_info(), obj, false, NULL, *meta.olh_epoch, real_time(), false, rctx.y, meta.zones_trace, add_log, |
There was a problem hiding this comment.
won't the losing version stick around counting against quota until someone runs bucket check unlinked?
A conditional write or delete in a versioned bucket checks its condition against the current version, then links its version or delete marker only over that version. cls_rgw refuses a link whose current version changed since, with CLS_RGW_ERR_PRECONDITION_FAILED, and rgw answered it 412 PreconditionFailed. But the condition held when it was checked: a concurrent write or delete changed the current version before the link. S3's API model answers a conditional PutObject, CopyObject or CompleteMultipartUpload that meets a conflicting operation during the upload 409 ConditionalRequestConflict, and 412 only when the condition does not hold. Its User Guide answers a conditional delete that loses to a concurrent PUT or DELETE 409 too. Answer a refused link 409 ConditionalRequestConflict. A condition that fails when it is checked is still answered 412. The error is defined as in PR 72100, which answers a conditional write that loses the head race the same way, so the two merge cleanly. Tested on vstart: a DeleteObject with If-Match on the current version, held before it links its delete marker, while a PutObject links a newer version. The delete marker is refused and answered 409; it was 412. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Kyle Bader <[email protected]>
In a bucket whose versioning is suspended, a write of the null version over a key with an olh writes the olh's own head, then links. With If-None-Match: * the head write took no guard. Two such writes, with the key's current version a delete marker, could both pass the check and both write the head. The first to link was answered success, and the other, refused at its link, had already replaced the first's head and then deleted its own tail. The key read back as neither object. Guard the head write on the ID tag it read for these writes too, and answer a write that loses the guard 409 ConditionalRequestConflict, as its link would. A write that reads the head only after another's head write, but before that write links, still passes its guard. The window is the other write's index completion and link. Tested on vstart: two PutObjects with If-None-Match: * held before their head writes. Without this change the key reads back as neither object; with it one is answered success and reads back whole, and the other is answered 409. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Kyle Bader <[email protected]>
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
I tested this without fault injection: 8 clients racing conditional PUTs on one key in a versioning-enabled bucket had more than one winner in 659 of 660 rounds on main, and exactly one winner in 660 of 660 with this PR (losers answered 409, a few 412). Details and setup in #72096 (comment). |
In a versioning-enabled bucket a conditional write is not atomic. The write goes to a new instance head, which nothing guards (set_attr_id_tag requires an empty instance), and its condition is checked only against the current version as get_current_version_state read it, before set_olh makes the new version current. Another write can become current in between, so two PutObjects with If-None-Match: * on a new key both succeed, and so do two If-Match writes on one ETag, a completion with either header, and two conditional deletes that each write a delete marker. S3 lets the first succeed and refuses the others. Applications that use If-None-Match: * for a lock or to create exactly once get two winners.
This checks the condition again where the new version becomes current: rgw_bucket_link_olh, the one cls op on the index shard that holds the key's olh entry, and already the place that refuses a stale link (unmod_since). rgw_cls_link_olh_op gains an optional condition, and its encoding goes to v6:
A link that fails its condition is refused with CLS_RGW_ERR_PRECONDITION_FAILED; set_olh does not retry it. The condition held when the write checked it, so a concurrent request changed the current version: rgw answers the refusal 409 ConditionalRequestConflict, as S3's API model answers a conflicting operation during a conditional write. A condition that fails when it is checked is still answered 412. The error is defined as in #72100, so the two merge cleanly. _do_write_meta passes the condition for a conditional write to a versioned key, and delete_obj for a conditional delete marker.
Points for review:
Versioning suspended
With versioning suspended, a write of the null version over a key with an olh writes the olh's own head, then links. With If-None-Match: * that head write took no guard, so two such writes could both write the head, and the one refused at its link had already replaced the head of the one answered success; the key read back as neither object. The head write is now guarded on the ID tag it read for these writes too, and a write that loses the guard is answered 409. A write that reads the head only after another's head write, but before that write links, still passes its guard.
Validated on vstart with the injection points of #72096:
test_suspended_if_none_match_puts_racefails without the guard and passes with it, and it andtest_versioned_cond_delete_racing_putfail with the earlier 412 answers and pass with 409.Fixes: https://tracker.ceph.com/issues/80925
Validated on a single-host vstart cluster, with the injection points of #72096: the s3-tests reproducers test_versioned_put_object_if_none_match_racing and test_versioned_put_object_if_match_racing (ceph/s3-tests#763) fail on main, where both writes answer 200, and pass with this change; the new cls_rgw test link_olh_cond passes (Replicated; the FastEC variants cannot run on one OSD); and test_s3.py as the rgw suite runs it shows no new failures.
Checklist