Skip to content

mgr/DaemonState: prune empty DeviceState in with_device_create - #72170

Open
stzuraski898 wants to merge 2 commits into
ceph:mainfrom
stzuraski898:wip-sz-80655-daemonstateindex-prune-empty-device
Open

stzuraski898 wants to merge 2 commits into
ceph:mainfrom
stzuraski898:wip-sz-80655-daemonstateindex-prune-empty-device

Conversation

@stzuraski898

@stzuraski898 stzuraski898 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

with_device_create created a DeviceState and ran a callback but never checked whether the device was still empty() afterward, unlike its sibling with_device_write, which erases the device in that case.

In the current codebase, this asymmetry is dormant: the only two callers—set-life-expectancy in DaemonServer.cc and the startup device/* key loader in Mgr.cc—always populate the device before returning, so the new check never fires in practice. The fix is therefore a consistency cleanup: it makes with_device_create honor the same post-callback invariant as with_device_write, ensuring that any future caller that passes a no-op or emptying callback does not leave a stale entry in the devices map.

Fixes: https://tracker.ceph.com/issues/80655
Assisted-by: Claude Code (Opus)

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.

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

@stzuraski898 , The fix is fine, but I don't see the bug happening today.

  1. with_device_create has only two callers:
  • device set-life-expectancy: set_life_expectancy() always adds 3 metadata keys, so the device is never empty after it.

  • Mgr startup, loading device/* keys: the device is empty only if the stored value is {}. Ceph never writes that, because rm-life-expectancy removes the key when the metadata becomes empty.

So in practice the new if (d->empty()) check never fires.

  1. Please update the description. The claim that an empty DeviceState stays in the map "forever" doesn't match the current code. Can you share how to reproduce it? If this is only a consistency cleanup with with_device_write, please say that.

  2. Please keep the code change and add a unit test. For example: call with_device_create with a callback that does nothing, then check that the device was removed from the map. The test fails without your fix and passes with it, and it keeps future callers of with_device_create covered.

@github-actions github-actions Bot added the tests label Sep 29, 2026
with_device_create created a DeviceState and ran a callback but never
checked whether the device was still empty() afterward, unlike its
sibling with_device_write which erases the device in that case.

In the current codebase the asymmetry is dormant: the only two callers
(set-life-expectancy in DaemonServer.cc and the startup device/* key
loader in Mgr.cc) always populate the device before returning, so the
new check never fires in practice.  The fix is a consistency cleanup:
it makes with_device_create honour the same post-callback invariant as
with_device_write, ensuring any future caller that passes a no-op or
emptying callback does not leave a stale entry in the devices map.

Fixes: https://tracker.ceph.com/issues/80655
Assisted-by: Claude Code (Opus)
Signed-off-by: Steven Zuraski <[email protected]>
Add DaemonStateIndex.WithDeviceCreateNopPrunesDevice to
test_daemonstate.cc.  The test calls with_device_create with a no-op
callback, then asserts that with_device returns false, confirming the
empty DeviceState was removed from the map.

The test fails without the if (d->empty()) _erase_device(d) block added
to with_device_create in the preceding commit, and passes with it.

Fixes: https://tracker.ceph.com/issues/80655
Signed-off-by: Steven Zuraski <[email protected]>
@stzuraski898
stzuraski898 force-pushed the wip-sz-80655-daemonstateindex-prune-empty-device branch 2 times, most recently from 18d6b24 to 6f7650f Compare September 29, 2026 16:09
@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

1 similar comment
@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath37-testing-20261124.044935-main.

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.

4 participants