Skip to content

osd/PeeringState: don't clear PG rebuild latch on same-primary interval restart - #70835

Merged
sseshasa merged 2 commits into
ceph:mainfrom
sseshasa:wip-fix-pg-rebuild-stat-incorrect-reset
Aug 12, 2026
Merged

sseshasa merged 2 commits into
ceph:mainfrom
sseshasa:wip-fix-pg-rebuild-stat-incorrect-reset

Conversation

@sseshasa

@sseshasa sseshasa commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

clear_primary_state() unconditionally reset the rebuild-time latch (rebuild_start_time, rebuild_base_recovered, rebuild_had_redundancy_loss), and it runs on every start_peering_interval() call, including routine acting-set churn (e.g. a backfill peer joining or leaving) that leaves the primary OSD unchanged. On a PG that stays degraded/recovering across several such interval restarts under the same primary, the latch was wiped before prepare_stats_for_publish() ever reached the "recovered" branch, so pg_rebuild_duration/max_secs/min_secs stayed at 0 despite a real, ongoing rebuild.

Also, a publish landing in a narrow window involving a peering-interval restart, where clear_primary_state() wipes acting_recovery_backfill/missing_loc before peering repopulates them, sees num_objects_degraded == 0 and no DEGRADED/UNDERSIZED bit set. Publish stats can in this situation prematurely conclude that a recovery is complete. This can truncate the PG rebuild duration incorrectly. This is fixed by requiring the PG state to be PG_STATE_ACTIVE to filter out that transient situation.

Only clear the latch in start_peering_interval() when the primary role actually changes across the transition (!(was_old_primary && is_primary())). A genuine primary -> replica handover (or vice versa) still discards the latch, since a stale start time must not be reused across a role change.

Also, drop pg_rebuild_max_secs/min_secs from the interim rebuild-stats solution. See commits for more detail. pg_rebuild_duration's avgtime (sum/avgcount) is sufficient on its own to calculate the durability scores.

Tests:

  • Add a new unit test that reproduces the latch already set + interval restart + primary unchanged condition and confirms that the in-progress latch time is not cleared.
  • Harden an existing standalone test to deterministically reproduce the exact bug sequence instead of leaving it to timing. The previous version only asserted pg_rebuild_duration.avgcount>=1 and sum>0 after a full recovery cycle. Those checks pass even under the clear_primary_state() latch bug

Fixes: https://tracker.ceph.com/issues/79028
Signed-off-by: Sridhar Seshasayee [email protected]

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.

@sseshasa
sseshasa requested review from ronen-fr and rzarzynski August 4, 2026 19:24
@sseshasa
sseshasa requested a review from a team as a code owner August 4, 2026 19:24
@sseshasa
sseshasa removed the request for review from a team August 4, 2026 19:26
@sseshasa

sseshasa commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@rzarzynski @ronen-fr Could you please review this bug fix related to PG rebuild stats? Thanks!

@batrick
batrick requested a review from a team August 5, 2026 23:26
@ronen-fr

ronen-fr commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@sseshasa - I assume that the fact that clear_primary_state() is called unconditionally is not a problem?

@ronen-fr ronen-fr 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 with one minor nit

Comment thread src/test/osd/TestPeeringState.cc Resolved
@sseshasa

sseshasa commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@sseshasa - I assume that the fact that clear_primary_state() is called unconditionally is not a problem?

@ronen-fr The reset of the rebuild start time was earlier being done unconditionally in clear_primary_state() and that was a problem. That is now moved to PeeringState::start_peering_interval() and is only done if there was a role change. The clear_primary_state() after this shouldn't be a problem since we now detect any role change before that and either reset the start time or retain it as is.

@ronen-fr

ronen-fr commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

@sseshasa

The clear_primary_state() after this shouldn't be a problem since we now detect any role change before that and either reset the start time or retain it as is.

What I meant was: are you losing, when clear_primary_state() is called, any information (not the latch) that is important for determining/calculating the counter times?

@sseshasa

sseshasa commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

What I meant was: are you losing, when clear_primary_state() is called, any information (not the latch) that is important for determining/calculating the counter times?

Yes, information related to the number of degraded objects/acting_recovery_backfill/missing_loc is wiped and this was caught during testing. This lead to the logic prematurely concluding that the rebuild is done. This narrow window is now fixed by an additional check to confirm that the PG is in PG_STATE_ACTIVE before considering that the rebuild is complete. The commit description outlines this scenario.

Forgot to mention that peering repopulates the wiped information eventually.

…al restart

clear_primary_state() unconditionally reset the rebuild-time latch
(rebuild_start_time, rebuild_base_recovered, rebuild_had_redundancy_loss),
and it runs on every start_peering_interval() call, including routine
acting-set churn (e.g. a backfill peer joining or leaving) that leaves
the primary OSD unchanged. On a PG that stays degraded/recovering
across several such interval restarts under the same primary, the latch
was wiped before prepare_stats_for_publish() ever reached the
"recovered" branch, so pg_rebuild_duration/max_secs/min_secs stayed at
0 despite a real, ongoing rebuild.

Also, a publish landing in a narrow window involving a peering-interval
restart, where clear_primary_state() wipes acting_recovery_backfill/missing_loc
before peering repopulates them, sees num_objects_degraded == 0 and no
DEGRADED/UNDERSIZED bit set. Publish stats can in this situation prematurely
conclude that a recovery is complete. This can truncate the PG
rebuild duration incorrectly. This is fixed by requiring the PG state to be
PG_STATE_ACTIVE to filter out that transient situation.

Only clear the latch in start_peering_interval() when the primary role
actually changes across the transition (!(was_old_primary &&
is_primary())). A genuine primary -> replica handover (or vice versa) still
discards the latch, since a stale start time must not be reused across a role
change.

Tests:
- Add a new unit test that reproduces the latch already set + interval restart
  + primary unchanged condition and confirms that the in-progress latch time
  is not cleared.

- Harden an existing standalone test to deterministically reproduce the
  exact bug sequence instead of leaving it to timing. The previous version
  only asserted pg_rebuild_duration.avgcount>=1 and sum>0 after a full
  recovery cycle. Those checks pass even under the clear_primary_state()
  latch bug

Fixes: https://tracker.ceph.com/issues/79028
Signed-off-by: Sridhar Seshasayee <[email protected]>
@sseshasa
sseshasa force-pushed the wip-fix-pg-rebuild-stat-incorrect-reset branch from ad4e7ea to 6dcdaa0 Compare August 6, 2026 06:26
@ronen-fr

ronen-fr commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

jenkins test make check

@ronen-fr

ronen-fr commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

jenkins test make check arm64

…rebuild-stats solution

pg_rebuild_duration's avgtime (sum/avgcount) is sufficient on its own
for the durability-score use case these counters were added for; the
max/min-seconds counters are just supplementary statistics, not required
for that calculation.

Since recoverystate_perf is a single OSD-wide PerfCounters object shared
by every PG shard, and the max/min update logic used a caller-side
get()+compare+set() sequence that is not atomic as a whole (unlike
tinc()'s true atomic accumulation for sum/avgcount), so concurrently
recording PGs could race and silently lose an update to these min/max
counters. These can be fixed, but is deferred until the full solution.

Remove rs_pg_rebuild_max_secs/rs_pg_rebuild_min_secs (enum entries and
registration), the counter updates in prepare_stats_for_publish(), and
the corresponding assertions in TestPeeringState.cc. Only
rs_pg_rebuild_duration remains.

Fixes: https://tracker.ceph.com/issues/79028
Signed-off-by: Sridhar Seshasayee <[email protected]>
@ronen-fr

ronen-fr commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

LGTM (even after the last commit was added)

@sseshasa

sseshasa commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test api

@sseshasa

sseshasa commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@sseshasa

sseshasa commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath7-testing-20260807.105153-main.

@sseshasa

sseshasa commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Teuthology Test Results

https://pulpito.ceph.com/sseshasa-2026-08-07_09:41:41-rados-wip-sseshasa-pg-rebuild-stats-testing-2026-08-06-distro-default-trial/
294/305 Passed, 8 Failed and 3 Dead Jobs.

Failures, unrelated:

  1. ['442207', '442314', '442442'] - https://tracker.ceph.com/issues/77106 - rados/cephadm/rm-zap-add - reached maximum tries (15) after waiting for 15 seconds - nvme list -o json failed
  2. ['442220', '442376'] - https://tracker.ceph.com/issues/70669 - ERROR: test_list_enabled_module: cephfs resource temporarily unavailable
  3. ['442298'] - https://tracker.ceph.com/issues/59079 - AssertionError: timeout expired in wait_for_all_osds_up
  4. ['442318'] - https://tracker.ceph.com/issues/76470 - rados/test_crash.sh: Induced crashes are not properly posted
  5. ['442364'] - https://tracker.ceph.com/issues/70714 - rados/cephadm/test_mgmt_gateway - Timeout after 300 seconds - Failed to extract uid/gid for path xxxx - CEPHADM_DAEMON_PLACE_FAIL Health check failed:
  6. ['442204', '442343'] - https://tracker.ceph.com/issues/68586 - rados/cephadm/test_iscsi_container - rm-cluster hung after stopped OSD - hits max timeout
  7. ['442274'] - https://tracker.ceph.com/issues/77739 rados/verify/valgrind - api_lock/api_snapshots/api_misc_pp etc hung for 1.5 hours

Additional Tests - Recovery/Backfill to Validate Perfcounters

Recovery/backfill tests were performed on a node with 8 OSDs and with EC4+2 profile and the results of that test is discussed here: https://tracker.ceph.com/issues/79028#note-3

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test API

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@ljflores

Copy link
Copy Markdown
Member

@sseshasa feel free to merge if this is QA approved (scrub note)

@sseshasa

Copy link
Copy Markdown
Contributor Author

Merging based on the tests performed on a single node(see https://tracker.ceph.com/issues/79028#note-3) with 8 OSDs and the teuthology results mentioned in my previous comment.

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.

5 participants