Skip to content

rgw: link a conditional write's version only over the version it checked - #72118

Open
mmgaggle wants to merge 3 commits into
ceph:mainfrom
mmgaggle:wip-rgw-versioned-cond-atomic
Open

mmgaggle wants to merge 3 commits into
ceph:mainfrom
mmgaggle:wip-rgw-versioned-cond-atomic

Conversation

@mmgaggle

@mmgaggle mmgaggle commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

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:

  • NO_CURRENT: the key has no current version, or its current version is a delete marker. A key with no olh entry but a plain entry from before versioning has a current version.
  • CURRENT_IS: the current version is the given instance, the one the write checked its condition against.

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:

  • The refused instance is left as any failed link leaves one: not listed, found and removed by "radosgw-admin bucket check unlinked", with its data objects deleted by the writer. Removing it at once instead would be a follow-up.
  • Multisite: the refused write logs the instance's ADD in the bilog but no LINK_OLH. A secondary that syncs the ADD writes the instance without linking it, waiting for a LINK_OLH that never comes (fetch_remote_obj), so no zone makes the refused version current; if it fetched before the source deleted the data, it holds the same kind of unlinked instance. As for any condition, only the zone that accepted the request enforces it.
  • Mixed versions: an OSD that has not been upgraded decodes the v6 op as v5 and links without the condition, as today.

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_race fails without the guard and passes with it, and it and test_versioned_cond_delete_racing_put fail 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

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

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)) {

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.

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?

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.

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;

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.

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,

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.

won't the losing version stick around counting against quota until someone runs bucket check unlinked?

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.

Also yes.

@mheler
mheler marked this pull request as ready for review September 27, 2026 11:48
@mheler
mheler requested a review from a team as a code owner September 27, 2026 11:48
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]>
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@dvanders

Copy link
Copy Markdown
Contributor

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).

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.

4 participants