Skip to content

mgr/MgrOpRequest: fix mark_finish_mon_command to pass flag_finish_mon_command - #72357

Open
stzuraski898 wants to merge 2 commits into
ceph:mainfrom
stzuraski898:wip-sz-81340-mgropquest-mark-finish-mon-command
Open

stzuraski898 wants to merge 2 commits into
ceph:mainfrom
stzuraski898:wip-sz-81340-mgropquest-mark-finish-mon-command

Conversation

@stzuraski898

Copy link
Copy Markdown
Contributor

mark_finish_mon_command() was copy-pasted from mark_start_mon_command()
without updating the flag constant: it passed flag_start_mon_command
(0x08) to mark_flag_point() instead of flag_finish_mon_command (0x10).

As a result the finish bit (0x10) was never set in the op-tracker flag
word and latest_flag_point was left at the start value, so after a mon
command completed:

  • op-tracker dumps reported "start mon command" instead of
    "mon command finished" for the finishing op, and
  • any code checking the flag_finish_mon_command bit to detect command
    completion never fired.

The method is reachable in production via DaemonServer.cc (mark_finish_mon_command
is called at DaemonServer.cc:1043). The one-line fix passes the
already-defined flag_finish_mon_command constant; the switch statements in
the header already map that bit to the correct "mon command finished"
string.

The copy-paste was introduced in 66efcaa ("mgr: integrate optracker
in ceph-mgr") and never corrected.

Fixes: https://tracker.ceph.com/issues/81340
Assisted-by: Claude Opus 4.8

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.

@stzuraski898
stzuraski898 requested a review from a team as a code owner October 2, 2026 22:06
@stzuraski898
stzuraski898 requested a balanced review from Copilot and removed request for a team October 2, 2026 22:08

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 review overview

🟢 Approval recommended

The targeted fix is correct and its production-observable behavior is covered by a focused regression test.

Review effort: Balanced
Findings: None

What changed in this PR

Corrects mon-command completion tracking in MgrOpRequest and adds regression coverage.

Changes:

  • Uses the finish flag when marking completed mon commands.
  • Adds a focused unit test and build target.
File Description
src/​mgr/​MgrOpRequest.h Corrects the completion flag.
src/​test/​mgr/​test_mgroprequest.cc Tests flag and state transitions.
src/​test/​mgr/​CMakeLists.txt Registers the new unit test.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@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, please check my comments

Comment thread src/mgr/MgrOpRequest.h Resolved
Comment thread src/test/mgr/CMakeLists.txt Resolved
Comment thread src/test/mgr/test_mgroprequest.cc Resolved
@stzuraski898
stzuraski898 force-pushed the wip-sz-81340-mgropquest-mark-finish-mon-command branch 3 times, most recently from 0b0742e to acc40c3 Compare October 30, 2026 21:18
@stzuraski898
stzuraski898 force-pushed the wip-sz-81340-mgropquest-mark-finish-mon-command branch from acc40c3 to 0b5b6fc Compare November 2, 2026 21:26
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Nov 2, 2026
…nish()

ReplyOnFinish::ReplyOnFinish() previously called mark_finish_mon_command()
in the constructor body, which runs as soon as the Context is allocated --
before monc dispatches the command and before any mon reply is received.
This caused the op-tracker to report "mon command finished" for ops that
were still waiting on the mon (e.g. during a mon election).

Move the call into ReplyOnFinish::finish(), which is invoked by MonClient
when the mon reply arrives, so the finish flag is set only after the
command has actually completed.

The same change is also part of ceph#72357
(main commit "mgr: fix MgrOpRequest mon-command flag tracking", tracked
as https://tracker.ceph.com/issues/81340), which additionally fixes
mark_finish_mon_command() passing flag_start_mon_command instead of
flag_finish_mon_command. The two PRs are related and should be fixed in
tandem.

Fixes: https://tracker.ceph.com/issues/82136
Assisted-by: Claude Opus 4.8
Signed-off-by: Steven Zuraski <[email protected]>
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

mark_finish_mon_command() was passing flag_start_mon_command to
mark_flag_point() — a copy-paste error.  The finish flag (1 << 4)
was never set; dump_ops_in_flight always showed "start mon command"
regardless of whether the mon had replied.

ReplyOnFinish also called op->mark_finish_mon_command() in its
constructor, before monc->start_mon_command() dispatched the command.
dump_ops_in_flight therefore reported "mon command finished" for ops
still waiting on the mon (e.g. during an election).  Move the call
into ReplyOnFinish::finish() so the flag advances only when the mon
has actually replied.

The ReplyOnFinish change in DaemonServer.cc is the same change made by
ceph#73120 (main commit "mgr/DaemonServer:
move mark_finish_mon_command into ReplyOnFinish::finish()", tracked as
https://tracker.ceph.com/issues/82136). The two PRs are related and
should be fixed in tandem.

Fixes: https://tracker.ceph.com/issues/81340
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>

@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 please see my comments below

Comment thread src/test/mgr/test_mgroprequest.cc Outdated
// kFlagStartMonCommand, not kFlagFinishMonCommand. Any code that calls
// mark_finish_mon_command() too early (e.g. in a constructor executed before
// the mon command is dispatched) would make this test fail.
TEST_F(MgrOpRequestTestHelper, FinishFlagNotSetBeforeFinish) {

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.

This test doesn't go through ReplyOnFinish. It only calls mark_start_mon_command() and then mark_finish_mon_command(), which is what MarkFinishMonCommandSetsCorrectFlag already does above. If someone moved the call back into the ReplyOnFinish constructor, this test would still pass, so the comment at line 93 ("would make this test fail") isn't true. I'd drop this test. If we want real coverage of the ordering,
ReplyOnFinish would have to be reachable from a test, and I don't think that's worth it for this fix. Please open a new tracker for that gap like we talked about.

Comment thread src/test/mgr/test_mgroprequest.cc Outdated
<< req->_get_state_string() << "\"";
}

// private flag_*_mon_command values from MgrOpRequest.h

@NitzanMordhai NitzanMordhai Nov 10, 2026 •

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.

Please don't copy the flag values here. MgrOpRequestTestAccess is already a friend of MgrOpRequest, so you can add the real constants to it next to mark_reached_module():

struct MgrOpRequestTestAccess {
   static constexpr uint8_t flag_start_mon_command =
     MgrOpRequest::flag_start_mon_command;
   static constexpr uint8_t flag_finish_mon_command =
     MgrOpRequest::flag_finish_mon_command;

   static void mark_reached_module(MgrOpRequest* op, const std::string& s) {
     op->mark_flag_point_string(MgrOpRequest::flag_reached_module, s);
   }
 };

Then use MgrOpRequestTestAccess::flag_start_mon_command and flag_finish_mon_command in the test instead of 1 << 3 and 1 << 4. That way the test can't drift if the flags get renumbered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed

mark_finish_mon_command() previously passed flag_start_mon_command to
mark_flag_point(), so the finish flag was never recorded and
dump_ops_in_flight kept reporting "start mon command" after the mon
replied.

Add a new test binary (scaffolded from PR ceph#71237) covering:

- BasicSetup: sanity-check request creation via OpTracker
- MarkFinishMonCommandSetsCorrectFlag: regression test for the
  flag_start_mon_command copy-paste bug; fails on unfixed code. It
  checks that mark_start_mon_command() and mark_finish_mon_command()
  set the start and finish flags respectively and that
  _get_state_string() reports "mon command finished" afterwards.

The tests reach MgrOpRequest's private flag constants through the
MgrOpRequestTestAccess friend struct, so they use the real values
rather than copies and cannot drift if the flags are renumbered.

Fixes: https://tracker.ceph.com/issues/81340
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
@stzuraski898
stzuraski898 force-pushed the wip-sz-81340-mgropquest-mark-finish-mon-command branch from e60b446 to 1cb2c96 Compare November 20, 2026 20:25
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath11-testing-20261201.061332-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