Bug #78340
closedosd: Zero op across full object + Truncate to 2k in same transaction causes assert
0%
Description
I have added a ZeroAndTruncateOp to ceph_test_rados_io_sequence that performs a zero op and a truncate op in a single transaction.
When the zero covers the whole object, and the truncate is non-zero, multiple OSDs assert.
Here is the sequence that causes the asserts:
2026-07-17T13:24:31.048+0100 7f47231efb00 0 test Step 9145: Create (size=64K)
2026-07-17T13:24:31.056+0100 7f47231efb00 0 test Step 9146: Barrier
2026-07-17T13:24:31.056+0100 7f47231efb00 0 test Step 9147: ZeroAndTruncate (zero_offset=0,zero_length=64K,truncate_size=2K)
Here is the assert:
/work/ceph/src/osd/ECTransaction.cc: 896: FAILED ceph_assert(!op.is_fresh_object())
MW Updated by Matty Williams 5 months ago
- Subject changed from osd: Zero covering full object + Truncate to 2k in same transaction causes assert to osd: Zero op across full object + Truncate to 2k in same transaction causes assert
LF Updated by Laura Flores 4 months ago
Bump up
RZ Updated by Radoslaw Zarzynski 4 months ago
- Assignee set to Bill Scales
Hi @Bill Scales, would you nind taking a look?
BS Updated by Bill Scales 4 months ago
PrimaryLogPG detects a ZERO op that extends to the end of the object and converts this into a TRUNCATE op
dout(10) << " munging ZERO " << op.extent.offset << "~" << op.extent.length
<< " -> TRUNCATE " << op.extent.offset << " (old size is " << oi.size << ")" << dendl;
So this op turns into a pair of truncates - firstly to 0 and then to 2K.
EC is expected to be able to handle this.
The assert !op.is_fresh_object() is suspect - I think you can issue a pair of truncates to either an object that already exists or an object that doesn't yet exist, so we need to be able to cope with both eventualities. However this test case is trying to issue a pair of truncates to an object that already exists, so don't understand why we think this is a freshly created object.
Matty is going to re-run the test and collect an OSD log so we can debug further.
BS Updated by Bill Scales 4 months ago
Note that the same assert exists in classic EC as well as Fast EC and appears to have been there since the EC code was extended to support overwrites.
BS Updated by Bill Scales 4 months ago
Here's the OSD log for the request:
do_op: op osd_op(client.4323.0:8341 2.15s0 2:ad551702:::test:head [zero 0~65536,truncate 2048] snapc 0=[] ondisk+write+known_if_redirected+supports_pool_eio e77)
op_has_sufficient_caps session=0x1791b900 pool=2 (rbd_erasure ) pool_app_metadata={rbd={}} need_read_cap=0 need_write_cap=1 classes=[] -> yes
do_op osd_op(client.4323.0:8341 2.15s0 2:ad551702:::test:head [zero 0~65536,truncate 2048] snapc 0=[] ondisk+write+known_if_redirected+supports_pool_eio e77) may_write -> write-ordered flags ondisk+write+known_if_redirected+supports_pool_eio
get_object_context: found obc in cache: obc(2:ad551702:::test:head rwstate(none n=0 w=0))
get_object_context: obc(2:ad551702:::test:head rwstate(none n=0 w=0)) oi: 2:ad551702:::test:head(77'13641 client.4323.0:8340 dirty|data_digest s 65536 uv 13641 dd a0e60eb6 alloc_hint [0 0 0]) exists: 1 ssc(2:ad551702:::test:snapdir snapset: 0={} ref: 1 registered: 1 exists: 1)
find_object_context 2:ad551702:::test:head @head oi=2:ad551702:::test:head(77'13641 client.4323.0:8340 dirty|data_digest s 65536 uv 13641 dd a0e60eb6 alloc_hint [0 0 0])
maybe_handle_manifest_detail: 2:ad551702:::test:head is not manifest object
do_op_impl obc obc(2:ad551702:::test:head rwstate(write n=1 w=0))
execute_ctx 0x17c1ad00
execute_ctx 2:ad551702:::test:head [zero 0~65536,truncate 2048] ov 77'13641 av 77'13642 snapc 0=[] snapset 0={}
do_osd_op 2:ad551702:::test:head [zero 0~65536,truncate 2048]
do_osd_op zero 0~65536
munging ZERO 0~65536 -> TRUNCATE 0 (old size is 65536)
do_osd_op truncate 2048
make_writeable 2:ad551702:::test:head snapset=0={} snapc=0=[]
make_writeable 2:ad551702:::test:head done, snapset=0={}
finish_ctx 2:ad551702:::test:head 0x17c1ad00 op modify
set mtime to 2026-07-17T13:24:31.057889+0100
final snapset 0={} in 2:ad551702:::test:head
finish_ctx object 2:ad551702:::test:head marks clean_regions clean_offsets: [65536~18446744073709486079], clean_omap: true, new_object: false
execute_ctx alloc reply 0x17925180 result 0
PeeringState::calc_trim_to_aggressive limit = 77'13641
PeeringState::calc_trim_to_aggressive approx pg log length = 9141
PeeringState::calc_trim_to_aggressive num_to_trim = 51
op order client.4323 tid 8341 last was 8340
new_repop rep_tid 31951 on osd_op(client.4323.0:8341 2.15s0 2:ad551702:::test:head [truncate 0,truncate 2048] snapc 0=[] ondisk+write+known_if_redirected+supports_pool_eio e77) v9
new_repop: repgather(0x17bd3800 0'0 rep_tid=31951 committed?=0 r=0)
issue_repop rep_tid 31951 o 2:ad551702:::test:head
get_write_plan plans= plans: [{{hoid: 2:ad551702:::test:head to_read: -- will_write: {} orig_size: 65536 projected_size: 2048 invalidates_cache: 1 do_pdw: 0}}]
submit_transaction plans= plans: [{{hoid: 2:ad551702:::test:head to_read: -- will_write: {} orig_size: 65536 projected_size: 2048 invalidates_cache: 1 do_pdw: 0}}]
start_rmw op=Op(2:ad551702:::test:head v=77'13642 tt=47'4500 tid=31951 reqid=client.4323.0:8341 client_op=osd_op(client.4323.0:8341 2.15s0 2:ad551702:::test:head [truncate 0,truncate 2048] snapc 0=[] ondisk+write+known_if_redirected+supports_pool_eio e77) pg_committed_to=77'13641 temp_added= temp_cleared= remote_read_result={} pending_commit>
PeeringState::apply_op_stats apply_op_stats 2:ad551702:::test:head d.objs=0 d.clns=0 d.bytes=-63488 -> objs=1 clns=0 bytes=2048
Generate: 2:ad551702:::test:head partial_extents={} written_map={}
Generate: 2:ad551702:::test:head{hoid: 2:ad551702:::test:head to_read: -- will_write: {} orig_size: 65536 projected_size: 2048 invalidates_cache: 1 do_pdw: 0} fresh_object: 0
Generate: truncate is 0,2048
generate_transactions: oid: 2:ad551702:::test:head to_write shard_extent_map: ({18446744073709551615~18446744073709551615}, maps={})
generate_transactions: plan: {hoid: 2:ad551702:::test:head to_read: -- will_write: {} orig_size: 65536 projected_size: 2048 invalidates_cache: 1 do_pdw: 0}
There are two transformations that occur:
1. The zero request op gets converted to a truncate op to length 0 by PrimaryLogPG
2. The truncate to length 0 gets converted to a delete + create by ECTransaction::zero_truncate_to_delete
is_fresh_object is therefore true because of the delete+create, we are left to perform a "truncate" to 2K which is actually growing the object from 0 to 2K. However the code is using this predicate to determine if it needs to shrink the object:
if (op.truncate && op.truncate->first < plan.orig_size) {
truncate();
}
In this case the original size was 64K and we are truncating to 2K so we try to shrink the object even though we've just deleted and recreated it. The truncate code asserts because it says we shouldn't be calling this for an object we've just created.
The desired behavior for this op is to skip the call to truncate() as the object isn't getting smaller at this point. One way of fixing this might be to update orig_size when we do the delete + create, another might be to simply not call truncate() if !is_fresh_object().
Scenarios to test:
1. Object exists. Zero for whole object + Truncate to X < existing object size (this bug)
2. Object exists. Zero for whole object + Truncate to X >= existing object size
3. Object exists. Truncate to 0 + Truncate to X < existing object size (should be the same as scenario 1)
4. Object exists. Truncate to 0 + Truncate to X >= existing object size (should be the same as scenario 2)
5. Object !exists. Truncate to 0
6. Object !exists. Truncate to X
7. Object !exists. Truncate to 0 + Truncate to X
Same bug looks like it exists in classic EC so need to test that too.
BS Updated by Bill Scales 4 months ago
- Status changed from New to In Progress
Slightly unexpected behavior from some of the new tests - a truncate on an object that doesn't exist returns success but doesn't create the object. Maybe there
is justification for a truncate to 0 to behave like this, but as you can use truncate to extend the size of an object too this seems a little odd when you
truncate a non-existent object to 4K and get success and no object.
Its appears to have behaved like this since 2010 with commit 86cab4aecc40, so not going to change the API behavior now and will just make the new tests police
the current implementation.
BS Updated by Bill Scales 4 months ago
- Status changed from In Progress to Fix Under Review
- Backport set to tentacle umbrella
- Pull request ID set to 70751
Testing showed the problem only occurs with Fast EC and only for the cases:
1. Zero whole object + Truncate to X
2. Truncate to 0 + Truncate to X
where 0 < X < original object size.
Classic EC has very similar code but avoids the bug because the hinfo attribute is deleted when the object gets deleted and created again and it is using the length from this (which defaults to 0 if the attribute doesn't exist) when processing the second truncate. In contrast Fast EC was using the original object size when processing the second truncate.
Both Classic EC and Fast EC generate a spurious "append" operation in the mod_desc for these transactions. This is not required because the "delete" and "create" operations are sufficient to restore the prior object status if the request is rolled back. In the case of Classic EC the "append" would always
truncate the object to 0 before deleting it. In the case of Fast EC the "append" has a wrong value. Both are however harmless, but result in larger than necessary PGLog entries.
The fix removes the unnecessary and wrong "append" from Fast EC, Classic EC is not changed.
UB Updated by Upkeep Bot 3 months ago
- Status changed from Fix Under Review to Pending Backport
- Merge Commit set to 28aee763b1eb4e87fb296c96b9df803792219695
- Fixed In set to v21.3.0-2509-g28aee763b1
- Upkeep Timestamp set to 2026-08-22T10:27:27+00:00
UB Updated by Upkeep Bot 3 months ago
- Copied to Backport #79736: umbrella: osd: Zero op across full object + Truncate to 2k in same transaction causes assert added
UB Updated by Upkeep Bot 3 months ago
- Copied to Backport #79737: tentacle: osd: Zero op across full object + Truncate to 2k in same transaction causes assert added
UB Updated by Upkeep Bot 3 months ago
- Tags (freeform) set to backport_processed
UB Updated by Upkeep Bot 3 months ago
- Status changed from Pending Backport to Backporting
- Tags (freeform) deleted (
backport_processed) - Upkeep Timestamp changed from 2026-08-22T10:27:27+00:00 to 2026-08-27T18:46:37+00:00