Skip to content

crimson/os/seastore/omap: check only live log keys in the trim walk - #72668

Merged
shraddhaag merged 3 commits into
ceph:mainfrom
shraddhaag:wip-shraddhaag-fix-pglog-trim
Oct 22, 2026
Merged

shraddhaag merged 3 commits into
ceph:mainfrom
shraddhaag:wip-shraddhaag-fix-pglog-trim

Conversation

@shraddhaag

@shraddhaag shraddhaag commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Primary OSD asks for a replica's pg_query_t::LOG since X. While building the dup list from the replica's pglog entries older than X, the OSD aborts. It asserts as the oldest pglog entry version is less than what is expected by the OSD's pglog. And so it asserts with ceph_assert(i->version > other.tail).

Why is there a mismatch between what the OSD expects the pglog to be and what it really is?

When a client write comes along with a trim to a replica, the OSD trims the pglog in the memory heap and requests the same from seastore. Due to a bug in seastore's remove_kvs, it does not mark those entries as removed on disk. A divergence is created between the in memory pglog and the one on disk.

The problem only becomes noticeable when the OSD is restarted and the pglog is loaded from disk and doesn't match what the OSD expects. Initially it only results in a log bound mismatch log but ultimately results in an assert when the primary requests for pg_query_t::LOG since pglog version X.

Full RCA for https://pulpito.ceph.com/xuxuehan-2026-04-27_04:29:46-crimson-rados:thrash-wip-new-128-distro-debug-trial/179259/

There is a peering request for PG 3.a from primary OSD.0 to OSD.1 asking for pg_query_t::LOG since 50'0:

DEBUG 2026-04-27 05:58:17,188 [shard 0:main] ms - [0x7c36b01e0840 osd.1(cluster) v2:10.20.193.125:6805/2658048002@51993 >> osd.0 v2:10.20.193.125:6802/1684756780] <== #17,14 === pg_query2(3.a 3.a query(log 50'0 ec=19/19 lis/c=49/45 les/c/f=50/46/0 sis=53 epoch_sent 53) e53/53) v1 (131)

In the replica OSD.1, PeeringState::fulfill_log is triggered to build the reply:

DEBUG 2026-04-27 05:58:17,365 [shard 0:main] osd -  pg_epoch 53 pg[3.a( v 50'80 (46'71,50'80] local-lis/les=49/50 n=23 ec=19/19 lis/c=49/45 les/c/f=50/46/0 sis=53) [0,2,1] r=2 lpr=53 pi=[45,53)/1 (log bound mismatch, actual=[34'38,50'80]) crt=50'80 lcod 0'0 unknown NOTIFY PeeringState::fulfill_log log request from 0
DEBUG 2026-04-27 05:58:17,365 [shard 0:main] osd -  pg_epoch 53 pg[3.a( v 50'80 (46'71,50'80] local-lis/les=49/50 n=23 ec=19/19 lis/c=49/45 les/c/f=50/46/0 sis=53) [0,2,1] r=2 lpr=53 pi=[45,53)/1 (log bound mismatch, actual=[34'38,50'80]) crt=50'80 lcod 0'0 unknown NOTIFY PeeringState::fulfill_log  sending info+missing+log since 50'0

Notice the pg[3.a( v 50'80 (46'71,50'80] and (log bound mismatch, actual=[34'38,50'80]). This means OSD.1 expects the pglog to start from beyond the tail 46'71, but we see that the actual pglog is [34'38,50'80], ie it starts way before the expected 46'71.

PeeringState::fulfill_log invokes copy_after, which is responsible for building the reply with log entries since 50'0 and dups (pg's complete dup list + pg log entries that are less than 50'0 also get added as dups).

DEBUG 2026-04-27 05:58:17,365 [shard 0:main] osd - copy_after v 50'0 dups.size()=0 other.dups.size()=71

In the reply, the only pglog entry greater than 50'0 is 50'80, which gets added. Then _handle_dups is invoked to build the dup list for reply.

First, all the dups in PG 3.a get copied over. We see dups being copied from 22'1 to 46'71:

DEBUG 2026-04-27 05:58:17,365 [shard 0:main] osd - _handle_dups earliest_dup_version 0
DEBUG 2026-04-27 05:58:17,365 [shard 0:main] osd - copy_up_to/copy_after copy dup version 22'1
....
DEBUG 2026-04-27 05:58:17,366 [shard 0:main] osd - copy_up_to/copy_after copy dup version 46'71

Now, from the PG 3.a's pglog (which the OSD expects to start from beyond 46'71 but in reality starts from 34'38), pglog entries before 50'0 need to be added as dups. It starts iterating from the oldest entry, 34'38, finds it to be smaller than expected 46'71 and asserts:

ERROR 2026-04-27 05:58:17,366 [shard 0:main] osd - /ceph/rpmbuild/BUILD/ceph-21.0.0-817-g56f6ccd8/src/osd/osd_types.cc:5470 : In function 'void _handle_dups(crimson::common::CephContext*, pg_log_t&, const pg_log_t&, unsigned int)', ceph_assert(i->version > other.tail)

So the problem is the badly formed pglog of the replica OSD.1 for PG 3.a. Why does it have entries starting from 34'38 instead of 46'71?

This is a thrasher test so OSDs are restarted many times. The first log bound mismatch happens after the 4th restart when pg log is loaded from disk.

INFO  2026-04-27 05:58:13,949 [shard 0:main] osd -  pg_epoch 50 pg[3.a( v 50'80 (46'71,50'80] local-lis/les=49/50 n=23 ec=19/19 lis/c=49/45 les/c/f=50/46/0 sis=49) [0,2,1] r=2 lpr=0 pi=[45,49)/1 (log bound mismatch, actual=[34'38,50'80]) crt=50'80 lcod 0'0 unknown exit Initial 0.384466 0 0.000000

The restart before the above, the 3rd one, was clean. No log bound mismatch logged after pglog is loaded from disk:

INFO  2026-04-27 05:56:50,490 [shard 0:main] osd -  pg_epoch 34 pg[3.a( v 34'41 (34'37,34'41] local-lis/les=33/34 n=12 ec=19/19 lis/c=33/25 les/c/f=34/26/0 sis=33) [0,2,1] r=2 lpr=0 pi=[25,33)/1 crt=34'41 lcod 0'0 unknown exit Initial 0.541000 0 0.000000

This means something goes wrong between the third and fourth restart which leaves the pglog on disk corrupt.

Investigating further, on OSD 1, PG 3.a receives a replicate client operation with a trim operation.

DEBUG 2026-04-27 05:56:54,730 [shard 0:main] osd -  pg_epoch 38 pg[3.a( v 38'43 (34'37,38'43] local-lis/les=37/38 n=13 ec=19/19 lis/c=37/37 les/c/f=38/38/0 sis=37) [0,2,1] r=2 lpr=37 pct=34'42 lua=34'42 crt=38'43 active  PG::handle_rep_op: osd_repop(client.4258.0:1095 3.a e38/37 3:55fae1df:::trial12525230-243:head v 38'44, pct=34'42) v3
...
DEBUG 2026-04-27 05:56:54,731 [shard 0:main] osd - trim proposed trim_to = 34'40

The pglog at this state from the logs above is (34'37,38'43] and it is proposing to trim the tail to 34'40. We see 3 pglog entries, 34'38, 34'39 and 34'40 are trimmed in the heap:

DEBUG 2026-04-27 05:56:54,731 [shard 0:main] osd - trim 34'38 (34'37) modify   3:5ac8ebf6:::trial12525230-225:head by client.4258.0:1009 2026-04-27T05:56:21.885568+0000 0 ObjectCleanRegions clean_offsets: [0~3394740,3764768~18446744073705786847], clean_omap: true, new_object: false
DEBUG 2026-04-27 05:56:54,731 [shard 0:main] osd - trim 34'39 (0'0) modify   3:5d35ebbb:::trial12525230-239:head by client.4258.0:1077 2026-04-27T05:56:30.853931+0000 0 ObjectCleanRegions clean_offsets: [0~400066,1116271~18446744073708435344], clean_omap: true, new_object: false
DEBUG 2026-04-27 05:56:54,731 [shard 0:main] osd - trim 34'40 (34'39) modify   3:5d35ebbb:::trial12525230-239:head by client.4258.0:1078 2026-04-27T05:56:30.857902+0000 0 ObjectCleanRegions clean_offsets: [0~1860832,2000066~18446744073707551549], clean_omap: true, new_object: false

Now, the same trim needs to be committed on the ondisk structure in seastore. This is where the problem happens.

We see that remove_kvs is invoked to remove contiguous entries from 34'38 to 34'40.

DEBUG 2026-04-27 05:56:54,808 [shard 0:main] seastore_omap - 0x7d0e38c19480 trans.1426 LogManager::remove_kvs: first=0000000034.00000000000000000038, last=0000000034.00000000000000000040, dst=L0x7e006a0000000377c97000000fe34924(ffffffff,3,50000000,6ef92e,0,1,7e34924000)

But no keys are actually removed. This is where the mismatch happens between the in memory heap pglog and the ondisk pglog.

Root Cause

When remove_kvs needs to remove contiguous entries, it performs 2 checks without checking if the keys are live or removed:

  1. Does the LogNode start with a key that is greater than the one that needs to be removed?
  2. Does the LogNode end with a key that is smaller than the one that needs to be removed?

The above two conditions work when all log keys are in order, first log key is the oldest and the last log key is the newest. This breaks when pglog is rewritten and all older keys were marked removed. The same LogNode can start with newer but removed log entries, followed by an older but live log entries.

Fix

If the 2 check are performed on live entires then we will not run into this error and the keys will be removed properly. The same problem exists in has_between and remove_entries, which will be handled in a separate followup PR.

Apart from fixing the above, I also added a succinct unit test to ensure we will catch this problem in a unit test in the future.

Prexisiting bug: get_live_bitmap, responsible for fetching the current state of the bitmap in both cases committed and mutation pending state, had an issue when the LogNode is mutation pending but with no remove delta. In this case, an empty bitmap is returned instead of the committed one. This means all keys looked live instead of their actual state. This is fixed by simply starting from the committed bit map and incase the remove delta is present, bitmap is replaced.

This prexisiting bug is relevant for this PR as without this fix we would not be able to correctly check for live log entries in the LogNode at the time of removal.

Testing

The unit test added is passing in CI.

QA:

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.

@shraddhaag

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@shraddhaag
shraddhaag force-pushed the wip-shraddhaag-fix-pglog-trim branch from 2048db7 to adffed6 Compare October 16, 2026 05:19
@shraddhaag

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@shraddhaag

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@shraddhaag
shraddhaag marked this pull request as ready for review October 20, 2026 16:49
@shraddhaag
shraddhaag requested a review from a team as a code owner October 20, 2026 16:49
@shraddhaag
shraddhaag marked this pull request as draft October 20, 2026 16:55
@shraddhaag
shraddhaag force-pushed the wip-shraddhaag-fix-pglog-trim branch from adffed6 to 2b7aca9 Compare October 20, 2026 17:11
@shraddhaag
shraddhaag marked this pull request as ready for review October 21, 2026 06:40
@Matan-B
Matan-B requested a review from xxhdx1985126 October 21, 2026 06:41
@Matan-B Matan-B added this to Crimson Oct 21, 2026
@Matan-B Matan-B moved this to Awaits review in Crimson Oct 21, 2026
@Matan-B
Matan-B self-requested a review October 21, 2026 06:42

@Matan-B Matan-B 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.

lgtm

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

LGTM, the following suggested items may be part of a follow-up (if strictly required):

  1. add/expand targeted coverage for the restart scenario where in-memory pglog bounds diverge from on-disk state, followed by a primary pg_query_t::LOG since X request. Specifically validate we no longer hit the dup-building/assert path regression.
  2. In the trim-walk key filtering path, please make the “live log keys only” behavior explicit in tests (including a negative case for non-live/tombstoned keys).
    Many thanks

@shraddhaag
shraddhaag force-pushed the wip-shraddhaag-fix-pglog-trim branch from 2b7aca9 to b1856f2 Compare October 22, 2026 03:54
@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

remove_kvs() walks the log chain from the tail and uses two checks to
skip work: log_has_larger_than() skips a node whose first log key is
after the range, and log_less_than() stops the walk at a node whose log
keys are all before the range. Both read removed entries too.

On crimson, PGLog::merge_log rewrites the whole pg log: it removes all
log keys and appends the live entries to the tail again. The tail then
starts with removed log keys that are newer than the live copies after
them. A later trim skips the tail because of the removed keys, and the
trimmed keys stay. When the OSD starts again, it reads them back and
reports a log bound mismatch, and a peer that asks for the log hits the
assert in _handle_dups.

Make both checks read only the live entries. The live log keys of a
node are in order, so log_less_than() still reads only the last entry
when that entry is a live log key, and scans the node otherwise. Read
the keys as string_view, and use a constant for the length of a pg log
key in is_log_key() and is_pg_log_key(), so that the scans do not
allocate.

Fixes: https://tracker.ceph.com/issues/76287
Signed-off-by: Shraddha Agrawal <[email protected]>
get_live_bitmap() reads the bitmap of the latest REMOVE delta when the
node is mutation pending, and the committed bitmap otherwise. When the
node is mutation pending but has no REMOVE delta yet, for example after
a log write in the same transaction, it returns an empty bitmap. Then
all entries look live, also the entries that earlier transactions
removed.

SeaStore merges the queued transactions of a collection into one, so a
pg log trim can find the newest LogNode already changed by a log write.
for_each_live_entry() then reads the removed log keys again, and the
trim walk skips the node as before the previous commit. Reads in the
same transaction, get_value() and list(), return removed entries too.

Start from the committed bitmap, as get_cur_bitmap() does. A REMOVE
delta holds the full bitmap, so it still replaces the committed one.
get_cur_bitmap() is then the same as get_live_bitmap(), so remove it
and use get_live_bitmap() in its place.

Fixes: https://tracker.ceph.com/issues/76287
Signed-off-by: Shraddha Agrawal <[email protected]>
On crimson, PGLog::merge_log rewrites the whole pg log: it removes all
log keys and writes the log entries again in the same transaction. The
removed copies stay in their LogNode, so the newest LogNode can start
with removed log keys that are newer than the live copies appended
after them.

trim_after_log_rewrite makes the log (first - 3, first + 1], where first
is the oldest log entry of the newest LogNode, rewrites it, then trims
first - 2 and first - 1. Those keys must be gone after a replay.

live_checks_after_log_rewrite also removes first and first + 1 after
the rewrite, so the newest LogNode starts and ends with removed log
keys. log_has_larger_than() and log_less_than() must answer for the
live first - 2 and first - 1 only.

trim_after_log_rewrite_in_merged_txn writes a log entry and trims in
one transaction, as SeaStore does when it merges queued transactions.
The newest LogNode is then mutation pending with no removal yet, and
the trim must still see the committed removals.

Each test checks that the rewrite keeps the newest LogNode, because the
test reads that LogNode.

Signed-off-by: Shraddha Agrawal <[email protected]>
@shraddhaag
shraddhaag force-pushed the wip-shraddhaag-fix-pglog-trim branch from b1856f2 to 5cead5a Compare October 22, 2026 03:56
@shraddhaag

Copy link
Copy Markdown
Contributor Author

add/expand targeted coverage for the restart scenario where in-memory pglog bounds diverge from on-disk state, followed by a primary pg_query_t::LOG since X request. Specifically validate we no longer hit the dup-building/assert path regression.

The assert was just a symptom. The actual cause, the divergence of pglog in heap and on disk, is tested properly in the two unit tests added: trim_after_log_rewrite and trim_after_log_rewrite_in_merged_txn. Both tests rewrite the log, trim the entries and then replay the log (similar to what happens on an OSD restart) and check if the trimmed entries are gone.

In the trim-walk key filtering path, please make the “live log keys only” behavior explicit in tests (including a negative case for non-live/tombstoned keys).

The unit test added live_checks_after_log_rewrite, calls the two helpers directly on a LogNode with both removed and live entries. And asserts that the correct keys are read and fails if removed keys are read.

@shraddhaag
shraddhaag merged commit a0bc160 into ceph:main Oct 22, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged (Main)

Development

Successfully merging this pull request may close these issues.

4 participants