Skip to content

osd: Do not remove objects with divergent logs if only partial writes. - #66698

Merged
aainscow merged 1 commit into
ceph:mainfrom
aainscow:partial_write_with_clone_fix
Feb 2, 2026
Merged

aainscow merged 1 commit into
ceph:mainfrom
aainscow:partial_write_with_clone_fix

Conversation

@aainscow

@aainscow aainscow commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

In the scenario we are fixing here, there is a divergent log, which needs to
be rolled back. The non-primary does not participate in the transaction to
the object, but the log exists describing the transaction. The primary has
a different transaction and has correctly detected the divergence.

The primary correctly concludes that no recovery is needed for the object, since
only partial writes exist on the non-primary.

The non-primary observes its divergent log and incorrectly concludes that
recovery IS needed for the divergent write and prepares by removing that
object.

The consequence of this depends on the next operation:

  1. A read will fail with -EIO
  2. A RMW involving a read from the removed object will detect the failure
    and reconstruct the necessary data.
  3. A RMW not involve the write or an append will recreate the object, but with
    zeros, so will cause data corruption. A

It is unusual for such a log entry to exist on the non-primary because
normally those are omitted from the non-primary log. The scenario that causes
this when a partial write triggers a clone due to copy on write. We now have
a clone operation which affects ALL shards and so the log entry is sent to
all shards.

This is unusual to see in the field. We must have all of the following:

  1. A clone operation (these are infrequent)
  2. A partial write.
  3. A peering cycle must happen before this write is complete.

The combination of 1 and 3 make this a very unusual operation in teuthology
and will be even rarer in the field.

The fix ensures we skip divergent log entries for partial writes that the shard
did not participate in.

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.

@aainscow
aainscow requested a review from a team as a code owner December 19, 2025 10:14
@github-actions github-actions Bot added the core label Dec 19, 2025
@aainscow
aainscow force-pushed the partial_write_with_clone_fix branch from 34c2711 to 0c51dbd Compare December 19, 2025 14:28
@github-actions github-actions Bot added the tests label Dec 19, 2025

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

I think this is right -- I'd like to see a unit test for this case specifically in TestPGLog though.

@athanatos

Copy link
Copy Markdown
Contributor

PGBackend::rollback_extents has specific support for skipping rollback on non-participating shards, so this fix to the !can_rollback case is sufficient. Does that sound right? I'm guessing that further narrows the conditions necessary to actually see this?

@aainscow
aainscow force-pushed the partial_write_with_clone_fix branch from 0c51dbd to a3e6c7c Compare December 19, 2025 21:05
@aainscow

Copy link
Copy Markdown
Contributor Author

I think this is right -- I'd like to see a unit test for this case specifically in TestPGLog though.

Added.

@aainscow

Copy link
Copy Markdown
Contributor Author

PGBackend::rollback_extents has specific support for skipping rollback on non-participating shards, so this fix to the !can_rollback case is sufficient. Does that sound right? I'm guessing that further narrows the conditions necessary to actually see this?

This is referring to Case 5, I think. So yes, there is logic in RollbackVisitor::rollback_extents to ignore non-participating shards. and where we can roll back, this is safe.

It was case 1, however, that I have been able to recreate... and looking again, I wonder if this fix is complete? What I have done will stop us from removing the object, but we still add to the missing list, which seems like a strange thing to do. I think we should be behaving like the entry did not exist in the first place.

I would like to discuss this with @bill-scales a bit more on Monday morning, when I have a fresh head.

@athanatos

Copy link
Copy Markdown
Contributor

Mmm, I don't think it needs to be added to the missing set either -- I didn't notice that part. The local copy of the object is presumably exactly as it should be already with no further intervention, right?

@aainscow
aainscow force-pushed the partial_write_with_clone_fix branch 2 times, most recently from 5793f7a to d807c52 Compare December 22, 2025 10:55
@aainscow
aainscow requested a review from athanatos December 22, 2025 10:56
@aainscow

Copy link
Copy Markdown
Contributor Author

Latest commit changes the implementation to one which is both simpler and correctly updates the missing list.

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test make check

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

Note: An AI was used to assist generating unit tests for this commit.
      The production code was written by the author.

In the scenario we are fixing here, there is a divergent log, which needs to
be rolled back. The non-primary does not participate in the transaction to
the object, but the log exists describing the transaction.  The primary has
a different transaction and has correctly detected the divergence.

The primary correctly concludes that no recovery is needed for the object, since
only partial writes exist on the non-primary.

The non-primary observes its divergent log and incorrectly concludes that
recovery IS needed for the divergent write and prepares by removing that
object.

The consequence of this depends on the next operation:
1. A read will fail with -EIO
2. A RMW involving a read from the removed object  will detect the failure
   and reconstruct the necessary data.
3. A RMW not involve the write or an append will recreate the object, but with
   zeros, so will cause data corruption. A

It is unusual for such a log entry to exist on the non-primary because
normally those are omitted from the non-primary log. The scenario that causes
this when a partial write triggers a clone due to copy on write.  We now have
a clone operation which affects ALL shards and so the log entry is sent to
all shards.

This is unusual to see in the field. We must have all of the following:

1. A clone operation (these are infrequent)
2. A partial write.
3. A peering cycle must happen before this write is complete.

The combination of 1 and 3 make this a very unusual operation in teuthology
and will be even rarer in the field.

The fix ensures we skip divergent log entries for partial writes that the shard
did not participate in.

The following is a minimal script to recreate:

set -e -x

MDS=0 MON=1 OSD=4 MGR=1 ../src/vstart.sh --debug --new -x --localhost -o timeout=10000 -o session_timeout=10000 -o debug_osd=20

ceph osd pool set noautoscale
ceph balancer off
ceph osd set nodeep-scrub
ceph osd set noscrub
ceph osd set noout

ceph config set global bluestore_debug_inject_read_err true

dd if=/dev/random of=file_8k bs=8k count=1
dd if=/dev/random of=file_4k bs=4k count=1

ceph osd erasure-code-profile set alex k=2 m=2
ceph osd pool create mypool --pg_num=1 --pool_type=erasure alex
ceph osd pool set mypool allow_ec_overwrites true
ceph osd pool set mypool allow_ec_optimizations true
ceph osd pool set mypool min_size 2

rados put -p mypool test1 file_8k

acting_set=$(ceph osd map mypool test1 --format=json | jq -r '.acting[]')
acting_array=($acting_set)

shard_0_osd=${acting_array[0]}
shard_1_osd=${acting_array[1]}

echo "Shard 0 OSD: $shard_0_osd"
echo "Shard 1 OSD: $shard_1_osd"

ceph daemon osd.$shard_0_osd injectecwriteerr mypool "*" 2 1 0 1

rados -p mypool mksnap test1_snap
rados put -p mypool test1 file_4k --offset 0 &

ceph osd set noup
ceph osd down $shard_1_osd

wait

ceph osd unset noup

rados -p mypool mksnap test1_snap2
rados put -p mypool test1 file_4k --offset 0

Signed-off-by: Alex Ainscow <[email protected]>
@aainscow
aainscow force-pushed the partial_write_with_clone_fix branch from d807c52 to 65dce5e Compare December 22, 2025 15:26

@bill-scales bill-scales 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.

2nd version of the change is much neater. The change boils down to ignoring log entries for partial writes that did not update the shard in _merge_object_divergent_entries when reversing out divergent entries. In particular the object isn't deleted and the missing list isn't modified.

I reviewed an earlier iteration of the unit tests and found a few places where we could assert that objects had been added to the missing list. This version of the unit tests looks fine.

Comment thread src/osd/PGLog.h
ldpp_dout(dpp, 20) << __func__ << ": ignoring " << *i << dendl;
} else if (!i->written_shards.empty() && !i->written_shards.contains(orig_shard)) {
ldpp_dout(dpp, 20) << __func__ << ": ignoring partial write " << *i << dendl;
last = i->version;

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.

ACK.

@ljflores

Copy link
Copy Markdown
Member

jenkins test make check arm64

@ljflores

Copy link
Copy Markdown
Member

jenkins test windows

@ljflores

Copy link
Copy Markdown
Member

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@bill-scales

Copy link
Copy Markdown
Contributor

jenkins test make check arm64

@aainscow
aainscow merged commit 4a107d3 into ceph:main Feb 2, 2026
@Naveenaidu

Copy link
Copy Markdown
Contributor

@aainscow aainscow added the backport-complete A backport was necessary, but all work has been completed. label Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-complete A backport was necessary, but all work has been completed. core needs-qa tests wip-yuri12-testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants