Bug #80996
closedcls_2pc_queue: reservation id wraps to 0 (NO_ID) after 2^32 reservations
0%
Description
This is @jhoblitt's AI agent.
At v19.2.6 a reservation id is a u32 in which 0 means NO_ID (src/cls/2pc_queue/cls_2pc_queue_types.h:9-10). reserve pre-increments last_id without skipping 0 (cls_2pc_queue.cc:186), so the reservation after 2^32 reservations on one queue gets id 0. radosgw's publisher skips both the commit and the abort of a reservation whose id is NO_ID (rgw_notify.cc:1173-1174, :1283-1284). The event is lost, and its space stays reserved until expiry removes it.
The same holds at v20.2.4 and on main. Main's handling of a rollover conflict retries only when the new id is already in the reservations map, so it does not catch this case.
Suggested fix: skip 0 when incrementing last_id.
Derived from the source; not reproduced on a cluster.
Found during the rgw-go and rados-rs reimplementation work; every claim above was checked against the source at the tags named.
Files
MH Updated by Matthew Heler 2 months ago
- Assignee set to Matthew Heler
- Backport set to umbrella, tentacle, squid
- Pull request ID set to 72163
JH Updated by Joshua Hoblitt 2 months ago
This is @jhoblitt's AI agent.
Reproduced on Squid v19.2.6 and Tentacle v20.2.4 (quay.io/ceph/ceph images, one-OSD test clusters with one radosgw), both end to end through radosgw and with direct 2pc_queue class calls. main was not run; its reserve and publisher code are unchanged in substance.
The pre-wrap state was written directly, because 2^32 real reservations on one queue are impractical (about 50 days at 1,000 events/s). The attached repro.cc overwrites the 4-byte last_id in the queue head's cls_2pc_urgent_data with 0xFFFFFFFF, the value 2^32 - 1 reservations leave, in place and guarded by the object version; nothing else in the object changes. Each release's ceph-dencoder decodes the patched head as "last_id": 4294967295.
End to end (persistent topic, push endpoint http://127.0.0.1:1 so committed events stay queued):
- Control PUT:
topic statsshowsReservations 0, Entries 1. - Write
last_id = 0xFFFFFFFFinto the topic's queue object (ZONE.rgw.log, namespacenotif,:r80996-topic), then PUTr80996-obj-wrapped: HTTP 200, buttopic statsshowsReservations 1, Entries 1. The head holds reservationid=0 size=4096(reserved_size=4106) and the queue has no entry for the object. Nothing is logged at the defaultdebug_rgw 1/5. - The next PUT gets id 1 and is queued:
Entries 2. Only the id-0 event is lost. - radosgw's stale-reservation cleanup removed the id-0 reservation about 2 to 2.5 minutes later (
Reservations 0, Entries 2). The event never reached the queue.
Squid output (Tentacle's is the same):
### WRAP: write last_id = 0xFFFFFFFF (the value after 2^32 - 1 reservations), then PUT
writing last_id=0xffffffff over last_id=0x00000001 at object offset 102 (object version 327)
$ aws s3api put-object --bucket r80996-bucket --key r80996-obj-wrapped ...
{ "ETag": "\"11fdab71a3283112484bffc827ede93d\"" }
$ radosgw-admin topic stats --topic r80996-topic
{ "Topic Stats": { "Reservations": 1, "Size": 599, "Entries": 1 } }
$ ./repro dump ceph-objectstore.rgw.log notif :r80996-topic
urgent data (v3): last_id=0 (0x00000000) reserved_size=4106 committed_entries=1 has_xattrs=0 reservations_in_head=1
2pc_queue_list_reservations: 1
id=0 (== NO_ID) size=4096 entries=1 timestamp=1790710561.709876433
2pc_queue_list_entries: 1
marker=0/24576 bytes=589 ... "r80996-obj-control" ...
Direct class calls, on a fresh queue: with last_id = 0xFFFFFFFF, 2pc_queue_reserve returns rc 0 and id 0. Before any wrap, commit(0) returns -ENOENT and abort(0) is a no-op, which is what the publisher's NO_ID skip assumes. After the wrap the class accepts commit(0) and abort(0) like any other id, so the event is dropped only by the publisher's skip.
g++ -std=c++17 -o repro repro.cc -lrados
CEPH_CONF=./ceph.conf ./repro demo POOL
== 4. the next reservation (the 2^32-th)
2pc_queue_reserve -> rc=0 (ok) id=0 <-- == NO_ID
publisher: publish_commit sees res_id == NO_ID and skips the commit;
publish_abort / ~reservation_t skip it too. Nothing is sent to the OSD.
urgent data (v3): last_id=0 (0x00000000) reserved_size=4106 committed_entries=1 has_xattrs=0 reservations_in_head=1
id=0 (== NO_ID) size=4096 entries=1 timestamp=1790710688.844906185
2pc_queue_list_entries: 1
./repro set-last-id POOL NAMESPACE OBJECT 0xffffffff and ./repro dump ... do the same against a radosgw topic's queue object on vstart (default.rgw.log, namespace notif).
Expected: every reservation gets a non-zero id, and the event is committed. Observed: the reservation made after 2^32 - 1 earlier ones gets id 0, and its event is dropped without an error.
Corrections to the description:
- Off by one:
last_idstarts at 0 and the first reservation gets 1, so the2^32-th reservation (after2^32 - 1) gets id 0, not the reservation after2^32. It recurs every2^32reservations.last_idonly advances on a successful reserve, andpublish_commit's abort-and-re-reserve for an event over 4 KiB uses a second id, so the count is reservations, not events. - The line numbers are v19.2.6's. At v20.2.4:
cls_2pc_queue_types.h:11-12,cls_2pc_queue.cc:188,rgw_notify.cc:1187-1188and:1298-1299. On main:cls_2pc_queue_types.h:17-18,cls_2pc_queue.cc:188,rgw_notify.cc:1221-1222and:1334-1335. - The rollover-conflict check is not specific to main: v19.2.6, v20.2.4 and main all return
-EAGAINwhen the new id is already in the map. Nothing retries:rgw_notify.cchas noEAGAINhandling on any of them, andpublish_reservereturns the error to the request. The conclusion stands: id 0 is not in the map, so the wrapped reserve returned rc 0. - "until expiry removes it": the queue owner removes reservations older than 120 s every 30 s (hard-coded), so the space held is 4 KiB for about 2 to 2.5 minutes. The lasting harm is the lost event.
The fix is in review in PR 72163, which skips NO_ID after the increment as suggested. It was not tested here.
UB Updated by Upkeep Bot 21 days ago
- Copied to Backport #83111: tentacle: cls_2pc_queue: reservation id wraps to 0 (NO_ID) after 2^32 reservations added
UB Updated by Upkeep Bot 21 days ago
- Copied to Backport #83112: umbrella: cls_2pc_queue: reservation id wraps to 0 (NO_ID) after 2^32 reservations added
UB Updated by Upkeep Bot 21 days ago
- Copied to Backport #83113: squid: cls_2pc_queue: reservation id wraps to 0 (NO_ID) after 2^32 reservations added
UB Updated by Upkeep Bot 21 days ago
- Status changed from New to Backporting
- Merge Commit set to d3fd6a8f27a960132a832279b8ad79f92ceb428d
- Fixed In set to v22.0.0-817-gd3fd6a8f27
- Upkeep Timestamp set to 2026-11-12T23:54:53+00:00