Skip to content

rgw: stop leaving refcount tags behind on shared tails - #72314

Merged
anrao19 merged 7 commits into
ceph:mainfrom
mheler:wip-rgw-refcount-src-tag
Oct 19, 2026
Merged

anrao19 merged 7 commits into
ceph:mainfrom
mheler:wip-rgw-refcount-src-tag

Conversation

@mheler

@mheler mheler commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Every time an object is copied and the copy deleted, cls_refcount keeps the copy's tag in a retired list on every tail object, forever. On EC pools that whole xattr goes into each pg log entry, so osd_pglog grows quickly once an object has been copied many times.

This series has cls_refcount remember which tag owns the tails. Copies get unique tags, which are removed outright when the copy is deleted. CopyObject and dedup pass the source tail tag. Objects fetched by sync get a tail tag of their own instead of keeping the source's. Objects without a tail tag, and appendable objects, have their data copied (CopyObject) or are skipped (dedup) instead of sharing tails.

Tracker: https://tracker.ceph.com/issues/81312

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

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)
Show available Jenkins commands

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

An appendable object writes each new part under its manifest's prefix.
A copy or dedup target that shares another object's tails would append
under that object's prefix. Copy the data when the source is appendable,
and skip appendable objects at dedup ingress.

Signed-off-by: Matthew N. Heler <[email protected]>
@mheler
mheler marked this pull request as ready for review October 1, 2026 22:02
@mheler
mheler requested review from a team as code owners October 1, 2026 22:02

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

Docs lgtm

Comment thread src/cls/refcount/cls_refcount.cc Outdated

objr.refs[op.tag] = true;
// a tag that another object may get again must stay retired after its put
objr.refs[op.tag] |= !op.unique;

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.

can you help me understand the need for this new op.unique argument? it looks like the CopyObject path was changed to pass unique=true, but not the dedup path. i thought dedup was using the same refcount strategy as server-side copy, so why does it need special treatment here?

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.

yes, it's the same strategy, the difference is the tag. unique says the tag will never come back, so its put doesn't have to retire it. that's true for copy, which makes a new tag each time, but dedup reuses the target's tail tag, and other objects can have that same tag.

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.

cc @benhanokh

how is it safe for multiple objects to share the same refcount tag? if you then delete those, doesn't that mean cls_refcount_put() would only deref once, so orphan tails from the other copies?

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.

or maybe the issue is that multiple calls to cls_refcount_get() would only add a single ref for that tag, so the first cls_refcount_put() could remove the tails while other copies still reference them

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.

it isn't, that's a dedup bug, and this pr works around it by not marking dedup tags unique so they stay retired

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.

Can you please explain the problem?
How does dedup share ref_tag between objects?
What does it mean "...dedup reuses the target's tail tag" ?

Can you please point me to the code where it happens?

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.

rgw: give fetched and restored objects a tail tag of their own

@mheler am i correct in assuming that it was these cases that would cause a problem with dedup?

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.

@cbodley yes. fetched and restored objects could keep the tail tag of an older object, and this PR gives them their own. the other case is swift bulk upload, which gives every file in one upload the same tail tag, so that's where tracker 81574 could hit. it can't happen today only because bulk upload saves the etag with an extra null byte, so dedup's etag check fails and it never shares tails for those files. If the swift behavior is fixed (imho it probably should be fixed), then this is a legitimate concern.

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.

Should I add a sanity check the SRC and TGT reftag are different ?

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.

@benhanokh I added 71755a9 which can prevent this scenario for new writes if the ETag issue is ever fixed for swift bulk uploads (I will likely put a follow-up PR for that once this PR merges).

// a source with a ref of its own, live or retired, doesn't own the wildcard
if (objr.refs.count(wildcard_tag) && objr.wildcard_owner.empty() &&
!objr.refs.count(op.src_tag) && !objr.retired_refs.count(op.src_tag)) {
objr.wildcard_owner = op.src_tag;

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 this case where we can assign a wildcard owner, might we also
a) clear existing retired_refs? and
b) convert other preexisting refs to false?

this seems like a good opportunity to clean up existing objects effected by this issue

@mheler mheler Oct 2, 2026 •

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.

how would we know which retired tags are safe to drop? retired_refs is what stops a replayed put from gc from dropping a newer ref with the same tag, so we can only clear a tag that nothing will add again. a dedup tag can be added again, and the xattr doesn't say which tags came from dedup. converting refs to false has the same problem.

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.

i was assuming that retired_refs was only protecting that wildcard ref

@mheler
mheler requested a review from cbodley October 2, 2026 21:19
@mheler
mheler force-pushed the wip-rgw-refcount-src-tag branch 2 times, most recently from c47ab64 to 293d404 Compare October 8, 2026 21:04
@mheler
mheler force-pushed the wip-rgw-refcount-src-tag branch 2 times, most recently from 459a326 to 146445d Compare October 9, 2026 22:40
@benhanokh

Copy link
Copy Markdown
Contributor

Adding my old PR as reference.
PR aimed at removing the wildcard ref
#66009

fetch_remote_obj() and restore_obj_from_cloud() write new tail objects
but keep the tail tag from the attrs they copy. An object fetched by
sync can carry the tag of a copy in this zone, and every restore of a
cloud object reuses the tag of its stub. Dedup can then add that tag
back to older tails after a delete already removed it.

Drop the tail tag from those attrs so the object keeps the tag its own
write made.

Signed-off-by: Matthew N. Heler <[email protected]>
@mheler
mheler force-pushed the wip-rgw-refcount-src-tag branch from 146445d to f67b76c Compare October 11, 2026 14:28
RGWBulkUploadOp and RGWPostObj write every file in a request with
s->req_id as its tag, so all of those files share one tail tag. When
dedup points two of them at the same tails they share a single ref, and
deleting one of them and the source frees tails the other still uses.

Add a random suffix to the request id so each file gets its own tag.
Bulk upload files that are already written keep their shared tag. Dedup
skips them only because their etag attr ends in a null byte.

Signed-off-by: Matthew N. Heler <[email protected]>
Copying and deleting an object repeatedly keeps adding retired tags to
its tails. We need those tags to stop a repeated put from removing the
source object's wildcard reference.

Record which source tag owns the wildcard. A put for another tag can
then leave it alone, so tags only need to stay retired while the
wildcard has no owner. Drop the retired tags once it has one or is gone,
which also cleans up tails that already have them.

An older osd would drop the owner when it rewrites the xattr, so encode
with compat 3 once the owner is set and make it fail to decode instead.

Signed-off-by: Matthew N. Heler <[email protected]>
Check that only the first eligible source becomes the wildcard owner. A
source with a live or retired reference must not become the owner.

Exercise repeated puts with and without an owner, check that retired
tags are dropped once the wildcard has an owner or is gone, and that an
owner forces compat 3.

Signed-off-by: Matthew N. Heler <[email protected]>
Pass the source's tail tag to cls_refcount_get() so it can own the
wildcard on the source's tails. This lets deleted copies release their
references without leaving a retired tag on every tail.

Fall back to copying data when the source has no tail tag. Without one
the wildcard gets no owner, and deleted copies would still leave retired
tags on the source's tails.

Signed-off-by: Matthew N. Heler <[email protected]>
Pass the source's tail tag to cls_refcount_get(), like a copy does.
Dedup and copies of a dedup target can then drop their references
without leaving retired tags. A record without a tail tag holds the id
tag instead, which can change on a self-copy or attribute update, so
pass the tag only when it came from the tail tag.

Signed-off-by: Matthew N. Heler <[email protected]>
@mheler
mheler force-pushed the wip-rgw-refcount-src-tag branch from f67b76c to f133d55 Compare October 13, 2026 12:25
Comment on lines 140 to +143
void encode(ceph::buffer::list& bl) const {
ENCODE_START(2, 1, bl);
// require decoders to recognize v3 when the owner is set
const uint8_t compat = wildcard_owner.empty() ? 1 : 3;
ENCODE_START(3, compat, bl);

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.

so if an upgraded osd sets a wildcard_owner and removes refs without recording them in retired_refs, and then an old osd takes over as primary, this prevents it from treating a repeated put() as the wildcard ref

instead, the old osd would return -EIO on decode failure. what does rgw do with these errors?

for CopyObject, the cls_refcount_get() errors would cause it to roll back any successful gets with puts and fail the copy request

for garbage collection, the cls_refcount_put() errors are treated as fatal to RGWGC::process(), so it leaves that entry in the queue and refuses to process later entries. this will resolve itself once the upgrade completes. if the cluster is left this way for an extended period, the gc queue will fill up and we'll rely on inline deletes

overall i think this is reasonable 👍

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.

@cbodley yes, that's right

@yuriw

yuriw commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to wip-yuri12-testing-20261013.170323-main.

@anrao19

anrao19 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to wip-yuri12-testing-20261013.170323-main.

pr testing completed and approved by @ivancich, more details in : https://tracker.ceph.com/issues/81731
@mheler , if no further testing is needed then this can be merged

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.

6 participants