Skip to content

mon: preserve log acknowledgements and release rejected requests - #72555

Merged
ljflores merged 1 commit into
ceph:mainfrom
yulongshi0816:wip-mon-log-routing-81604
Nov 4, 2026
Merged

ljflores merged 1 commit into
ceph:mainfrom
yulongshi0816:wip-mon-log-routing-81604

Conversation

@yulongshi0816

@yulongshi0816 yulongshi0816 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

The unconditional no_reply() in preprocess_log() introduced by 56cb53d releases a forwarded request before its log entries are committed. The later MLogAck is then dropped by the peon because the routed request no longer exists, leaving the client log queue untrimmed.

Restore the preprocessing flow so new log entries retain their routed request until _updated_log() sends the acknowledgement. Call no_reply() in prepare_log() when rejecting an MLog with a mismatched fsid, so the peon can release the routed request on the path that originally leaked.

Fixes: https://tracker.ceph.com/issues/81604
Related PR: #61933

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.

The unconditional no_reply() in preprocess_log() introduced by
56cb53d releases a forwarded request
before its log entries are committed. The later MLogAck is then dropped
by the peon because the routed request no longer exists, leaving the
client log queue untrimmed.

Restore the preprocessing flow so new log entries retain their routed
request until _updated_log() sends the acknowledgement. Call no_reply()
in prepare_log() when rejecting an MLog with a mismatched fsid, so the
peon can release the routed request on the path that originally leaked.

Fixes: https://tracker.ceph.com/issues/81604
Signed-off-by: yulong shi <[email protected]>
@yulongshi0816
yulongshi0816 requested a review from a team as a code owner October 10, 2026 06:10
@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

@yulongshi0816

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@tchaikov tchaikov 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

@tchaikov

Copy link
Copy Markdown
Contributor

@NitzanMordhai and @rzarzynski this change looks good to me, could you take a look as well?

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

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

Comment thread src/mon/LogMonitor.cc
}

done:
mon.no_reply(op);

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.

Ouch, I see – there was a work to do (preprocess_log() returning false to avoid the early exit at PaxosService::dispatch()) but no_reply()-at-leader generates too-early MRoute.

Comment thread src/mon/LogMonitor.cc
done:
mon.no_reply(op);
return (!num_new);
return false;

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.

Yes, for num_new > 0 we shall not early exit in PaxosService::dispatch().

Comment thread src/mon/LogMonitor.cc
if (m->fsid != mon.monmap->fsid) {
dout(0) << "handle_log on fsid " << m->fsid << " != " << mon.monmap->fsid
<< dendl;
mon.no_reply(op);

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.

The above just reverts the original @NitzanMordhai's patch entirely.
This line becomes the actual fix for https://tracker.ceph.com/issues/54489 (or perhaps a partial fix).
The conclusion is the original problem has been caused by LogClient passing wrong fsid to the constructor of MLog. @kamoltat, do we have a bug there that pops out in stretch mode?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rzarzynski
I can confirm that mon.monmap->fsid is the same through out stretch mode

@Jayaprakash-ibm

Copy link
Copy Markdown
Contributor

@ljflores
ljflores merged commit 7d8e945 into ceph:main Nov 4, 2026
22 of 23 checks passed
@nh2

nh2 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

I believe I hit this on 20.2.1 in our production Ceph cluster. I observed:

  • OSDs connected to two peon mons were being marked down ("no beacon for 900 seconds") and PGs got stuck peering.
  • The cause was that the peons' single ms_dispatch thread was at 100% CPU, with perf showing 96-98% of samples in LogClient::_get_mon_log_message().
  • After 97 days, a peon's own log_queue held about 27 million never-acked entries (13 GB RSS); beacons, pg_temp and up_thru requests waited up to 37 minutes in its dispatch queue. The leader was unaffected.

I used an LLM agent for the investigation.
It wrote an offline repro of 20.2.1 (3 mons and 2 memstore OSDs as local processes on loopback), which reproduced the dropped acks and the queue growth described here.
It pinned the regression to commit 56cb53d, and with that I found issue 81604 and this PR.
I expect it will fix our case.

Along the way, the agent found two related client-side issues that this PR doesn't touch.
Since I'm not an expert in the Ceph code, I thought I'd share them with you here.

Happy to open separate tracker issues for these if that's preferred.

LLM output below; suggested diff sketches are not tested. They are against current main (after commit faaeb89).

LLM output

1. _get_mon_log_message() is O(queue length) per new entry, so lost acks cost O(n^2) in total; unnecessarily quadratic

On a mon, this runs for every new cluster/audit log entry (queue() -> _send_to_mon()).
On current Ceph main it is still a linear std::find_if from the front.
With this PR the queue stays short again, but any future loss of acks (or the unbounded resend that issue 81511 describes) turns into CPU saturation again.
The queue is ordered by seq (gaps are possible, see commit faaeb89), so a binary search should work to make each lookup O(log n) instead of O(n); for our 27 million entries, that is about 25 comparisons per new entry instead of 27 million:

--- a/src/common/LogClient.cc
+++ b/src/common/LogClient.cc
@@ ceph::ref_t<Message> LogClient::_get_mon_log_message()
-  auto p = std::find_if(log_queue.begin(), log_queue.end(),
-			[this](const LogEntry& e) {
-			  return e.seq > last_log_sent;
-			});
+  // log_queue is ordered by seq (with gaps), so binary search
+  auto p = std::upper_bound(log_queue.begin(), log_queue.end(), last_log_sent,
+			    [](version_t sent, const LogEntry& e) {
+			      return sent < e.seq;
+			    });

A cap on log_queue (drop the oldest entries, warn once) would also bound memory and the reconnect resend storm from issue 81511.

2. Clients still send zero-fsid MLogs at startup, and their entries are silently lost

This PR releases the routed request when the leader rejects such an MLog, but the client still sends it.
As issue 81604 describes, MonMap::build_initial() returns before reading the conf fsid in the mon_host_override and "cct?" branches.
The conf fsid is set by then (get_monmap_and_config() copies it).
Entries queued before the first mon session are flushed by _finish_hunting() with fsid 0 before the real MMonMap arrives, and the leader rejects them.
The next (cumulative) ack then trims them from the queue, so they never reach the cluster log.

In addition, get_mon_log_message(true) sets last_log_sent = front().seq, so the oldest queued entry is never (re)sent on a new session.
That's why all the stuck/resent ranges in issue 54489, issue 81604 and issue 81511 start at "seq 2".

Possible fix: Don't build an MLog until the monmap has an fsid (tick() resends within mon_client_log_interval), and fix the off-by-one:

--- a/src/common/LogClient.cc
+++ b/src/common/LogClient.cc
@@ ceph::ref_t<Message> LogClient::get_mon_log_message(bool flush)
     // reset session
-    last_log_sent = log_queue.front().seq;
+    last_log_sent = log_queue.front().seq - 1;
@@ ceph::ref_t<Message> LogClient::_get_mon_log_message()
   if (log_queue.empty())
     return {};

+  // Until the first MMonMap arrives, MonClient's monmap may have a zero
+  // fsid, and the leader drops such an MLog; keep the entries queued.
+  if (monmap->get_fsid().is_zero())
+    return {};
+

Alternatively (or additionally), move the "fsid from conf?" block in MonMap::build_initial() before the early returns.

@yulongshi0816

Copy link
Copy Markdown
Contributor Author

I believe I hit this on 20.2.1 in our production Ceph cluster. I observed:

  • OSDs connected to two peon mons were being marked down ("no beacon for 900 seconds") and PGs got stuck peering.
  • The cause was that the peons' single ms_dispatch thread was at 100% CPU, with perf showing 96-98% of samples in LogClient::_get_mon_log_message().
  • After 97 days, a peon's own log_queue held about 27 million never-acked entries (13 GB RSS); beacons, pg_temp and up_thru requests waited up to 37 minutes in its dispatch queue. The leader was unaffected.

I used an LLM agent for the investigation. It wrote an offline repro of 20.2.1 (3 mons and 2 memstore OSDs as local processes on loopback), which reproduced the dropped acks and the queue growth described here. It pinned the regression to commit 56cb53d, and with that I found issue 81604 and this PR. I expect it will fix our case.

Along the way, the agent found two related client-side issues that this PR doesn't touch. Since I'm not an expert in the Ceph code, I thought I'd share them with you here.

Happy to open separate tracker issues for these if that's preferred.

LLM output below; suggested diff sketches are not tested. They are against current main (after commit faaeb89).

LLM output

1. _get_mon_log_message() is O(queue length) per new entry, so lost acks cost O(n^2) in total; unnecessarily quadratic

On a mon, this runs for every new cluster/audit log entry (queue() -> _send_to_mon()). On current Ceph main it is still a linear std::find_if from the front. With this PR the queue stays short again, but any future loss of acks (or the unbounded resend that issue 81511 describes) turns into CPU saturation again. The queue is ordered by seq (gaps are possible, see commit faaeb89), so a binary search should work to make each lookup O(log n) instead of O(n); for our 27 million entries, that is about 25 comparisons per new entry instead of 27 million:

--- a/src/common/LogClient.cc
+++ b/src/common/LogClient.cc
@@ ceph::ref_t<Message> LogClient::_get_mon_log_message()
-  auto p = std::find_if(log_queue.begin(), log_queue.end(),
-			[this](const LogEntry& e) {
-			  return e.seq > last_log_sent;
-			});
+  // log_queue is ordered by seq (with gaps), so binary search
+  auto p = std::upper_bound(log_queue.begin(), log_queue.end(), last_log_sent,
+			    [](version_t sent, const LogEntry& e) {
+			      return sent < e.seq;
+			    });

A cap on log_queue (drop the oldest entries, warn once) would also bound memory and the reconnect resend storm from issue 81511.

2. Clients still send zero-fsid MLogs at startup, and their entries are silently lost

This PR releases the routed request when the leader rejects such an MLog, but the client still sends it. As issue 81604 describes, MonMap::build_initial() returns before reading the conf fsid in the mon_host_override and "cct?" branches. The conf fsid is set by then (get_monmap_and_config() copies it). Entries queued before the first mon session are flushed by _finish_hunting() with fsid 0 before the real MMonMap arrives, and the leader rejects them. The next (cumulative) ack then trims them from the queue, so they never reach the cluster log.

In addition, get_mon_log_message(true) sets last_log_sent = front().seq, so the oldest queued entry is never (re)sent on a new session. That's why all the stuck/resent ranges in issue 54489, issue 81604 and issue 81511 start at "seq 2".

Possible fix: Don't build an MLog until the monmap has an fsid (tick() resends within mon_client_log_interval), and fix the off-by-one:

--- a/src/common/LogClient.cc
+++ b/src/common/LogClient.cc
@@ ceph::ref_t<Message> LogClient::get_mon_log_message(bool flush)
     // reset session
-    last_log_sent = log_queue.front().seq;
+    last_log_sent = log_queue.front().seq - 1;
@@ ceph::ref_t<Message> LogClient::_get_mon_log_message()
   if (log_queue.empty())
     return {};

+  // Until the first MMonMap arrives, MonClient's monmap may have a zero
+  // fsid, and the leader drops such an MLog; keep the entries queued.
+  if (monmap->get_fsid().is_zero())
+    return {};
+

Alternatively (or additionally), move the "fsid from conf?" block in MonMap::build_initial() before the early returns.

Thanks @nh2 for the report. This is useful confirmation of the production impact.

Please let us know whether the merged fix resolves your case once you can run a build that includes it. Backports are tracked in https://tracker.ceph.com/issues/81604.

The two client-side issues look independent of this PR, so separate tracker issues make sense. Please feel free to open them.

One note on the sketch: _send_to_mon() currently sends the returned message unconditionally. If _get_mon_log_message() can return an empty reference while the fsid is unavailable, the monitor loopback path needs a corresponding null check as well.

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.

8 participants