Skip to content

msg/async/ProtocolV2: Speed up connection logic when peer restarts & Added Netsplit Grace Period - #64122

Merged
ljflores merged 11 commits into
ceph:mainfrom
kamoltat:wip-ksirivad-fix-msg-v2
Nov 4, 2025
Merged

ljflores merged 11 commits into
ceph:mainfrom
kamoltat:wip-ksirivad-fix-msg-v2

Conversation

@kamoltat

@kamoltat kamoltat commented Jun 23, 2025 •

Copy link
Copy Markdown
Member

When a client restarts, it loses its state including global_seq and
gets a new client_cookie. This creates an issue during reconnection
because the server has an existing connection with a higher
global_seq value, causing it to reject the new connection as "stale"
with the error:

"this is a stale connection, peer_global_seq="

This commit adds detection logic in
ProtocolV2::handle_existing_connection() to identify client restarts
by checking:

  - exproto->peer_global_seq > peer_global_seq
    (global_seq should only increase during a session; a decrease
    strongly suggests a restart)
  - client_cookie has changed (client generated a new cookie)
  - existing connection state is not Ready or not Standby

When all three conditions are met, the server drops the existing connection
and accepts the new one. This leads to faster reconnection, especially
in cases like Monitor restarts, helping clients rejoin the quorum
without delay and avoiding spurious MON_NETSPLIT warnings.

It also prevents reliance on server-side reconnect attempts or waiting
for the client's global_seq to catch up.

Note: without this patch, it'll take longer
for the reconnection to happen, eventually the server will
also act as a client and send_reconnect since it has server_cookie.
However, this could be 15 seconds later, since, the server probably
was hit with a _fault max_back_off when it was trying to connect
to the client when the client was still down and has not yet
restart. This patch basically does not wait for the reconnection
to happen and intelligently make decisions in dropping existing
connection or not based on 3 conditions.

Fixes: https://tracker.ceph.com/issues/71344

Note: Originally raised as #63413, but this one was merged prematurely and was reverted in #64047.

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

@kamoltat
kamoltat requested a review from a team as a code owner June 23, 2025 20:02
@github-actions github-actions Bot added the core label Jun 23, 2025
@kamoltat kamoltat changed the title msg: Fix client reconnection issues after restart msg/async/ProtocolV2: Fix client reconnection issues after restart Jun 23, 2025
@kamoltat
kamoltat force-pushed the wip-ksirivad-fix-msg-v2 branch from 6b91097 to df9255a Compare June 23, 2025 20:09
@kamoltat kamoltat changed the title msg/async/ProtocolV2: Fix client reconnection issues after restart msg/async/ProtocolV2: Drop existing connection when client restarts Jun 23, 2025
@kamoltat
kamoltat force-pushed the wip-ksirivad-fix-msg-v2 branch from df9255a to 9344158 Compare June 23, 2025 20:10
@kamoltat kamoltat changed the title msg/async/ProtocolV2: Drop existing connection when client restarts msg/async/ProtocolV2: Server drops existing connection when client restarts Jun 23, 2025
@github-actions github-actions Bot added the tests label Jun 23, 2025
@ljflores

Copy link
Copy Markdown
Member

Clone of #63413, which was merged too early.

@ljflores
ljflores requested a review from rzarzynski June 24, 2025 15:57
@kamoltat

kamoltat commented Jun 24, 2025 •

Copy link
Copy Markdown
Member Author

Clone of #63413, which was merged too early.

Not exact clone since the solution is different now 😅, but yes tackling the same problem!

@kamoltat

Copy link
Copy Markdown
Member Author

@kamoltat

kamoltat commented Jun 26, 2025 •

Copy link
Copy Markdown
Member Author

there are 2 failures out of 30 ... investigating.

I know why we had the failures ...

(EDIT, I just corrected the PR to check for peer_global_seq=1 instead of peer_global_seq=0, in the server side) This is because when we do ProtocolV2::start_client_banner_exchange() we are actually incrementing global_seq since

CtPtr ProtocolV2::start_client_banner_exchange() {
  ldout(cct, 20) << __func__ << dendl;

  INTERCEPT(1);

  state = BANNER_CONNECTING;

  global_seq = messenger->get_global_seq();

  return _banner_exchange(CONTINUATION(post_client_banner_exchange));
}

In AsyncMessenger.h:

 __u32 get_global_seq(__u32 old=0) {
    std::lock_guard<ceph::spinlock> lg(global_seq_lock);

    if (old > global_seq)
      global_seq = old;
    __u32 ret = ++global_seq;

    return ret;
  }

Therefore, the server should check for peer_global_seq == 1, instead since there is no way the server will get peer_global_seq == 0 from the client since they have to start_client_banner_exchange() in which the client side will increment the global_seq to 1 even if it is freshly started

Comment thread src/msg/async/ProtocolV2.cc Outdated
if (peer_global_seq == 0 &&
exproto->client_cookie && client_cookie &&
exproto->client_cookie != client_cookie) {
ldout(cct, 1) << __func__ << " client has clearly restarted (global_seq=0, cookie changed), "

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.

Yeah, for the client-reset case we aren't choosing the reconnect path as the server_cookie should be zero.

CtPtr ProtocolV2::start_session_connect() {
  if (!server_cookie) {
    ceph_assert(connect_seq == 0);
    state = SESSION_CONNECTING;
    return send_client_ident();               
  } else {  // reconnecting to previous session
    state = SESSION_RECONNECTING;
    ceph_assert(connect_seq > 0);
    return send_reconnect();
  }
}

A client restart (in contrast to a connection reset alone) thrashes the entire state-at-client. I don't see business in trying to ressurrect the exproto in such conditions. @idryomov, what do you think?

@rzarzynski
rzarzynski requested a review from idryomov July 2, 2025 11:58
@kamoltat
kamoltat force-pushed the wip-ksirivad-fix-msg-v2 branch 2 times, most recently from e07dffa to 854fe32 Compare July 3, 2025 05:31
@kamoltat

kamoltat commented Jul 3, 2025

Copy link
Copy Markdown
Member Author

Will run 1 more test once we finished building in shaman with the new code

@kamoltat

kamoltat commented Jul 3, 2025

Copy link
Copy Markdown
Member Author

@kamoltat

kamoltat commented Jul 3, 2025

Copy link
Copy Markdown
Member Author

jenkins test make check arm64

1 similar comment
@ronen-fr

ronen-fr commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

jenkins test make check arm64

@kamoltat
kamoltat force-pushed the wip-ksirivad-fix-msg-v2 branch 4 times, most recently from 3496db3 to 435c56e Compare July 9, 2025 19:40
@kamoltat

kamoltat commented Jul 9, 2025 •

Copy link
Copy Markdown
Member Author

Just pushed some new changes, hopefully this should pass all tests now,

my initial understanding of how AsyncMessenger and ProtocolV2 was flawed.
global_seq is part of AsyncMessenger and ProtocolV2 also holds a copy of global_seq. However,
Each Ceph daemon (MON, MGR, OSD) instantiates a single AsyncMessenger object where the object
can have multiple connections, mon.b can have connection to [mon.a, mon.c] through AsyncConnection object, each connection either uses ProtocolV1 or ProtocolV2. Therefore, it is impossible to use global_seq starting num to determine whether a connection has restarted or not, since what if mon.b (the restarted client) starts connecting to [mon.a, mon.d, mon.c] and then mon.c gets the connection request last from mon.b .... mon.b global_seq would be = 2 already and so mon.c would reject mon.b ... and as you increase the number of monitors, the starting global_seq will get higher for the last monitor that gets connected.

What we can do instead is compare the current global_seq number of a client against the existing global_seq number that the server has saved for that client.

Therefore, on the server side apart from seeing a cookie mismatch between the client's previous and current connection, we can just check "peer_global_seq < exproto->peer_global_seq" , since global_seq should only increase during a
session. A decrease strongly indicates a restart from the client.

@kamoltat

kamoltat commented Oct 7, 2025

Copy link
Copy Markdown
Member Author

jenkins test make check

@kamoltat

kamoltat commented Oct 7, 2025

Copy link
Copy Markdown
Member Author

jenkins test api

@@ -12,3 +12,4 @@ overrides:
debug monc: 10
log-ignorelist:
- \(OSD_SLOW_PING_TIME
- \(MON_NETSPLIT)

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.

ACK.

Comment thread src/mon/Elector.cc
@@ -560,7 +564,9 @@ void Elector::ping_check(int peer)
}
}

dout(30) << "schedule " << __func__ << " against peer: "<< peer << dendl;
dout(30) << "Scheduling next ping_check for peer "

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.

Hmm, 30 is a bit unusual and its existence might be missed (people intuitively assume 20 as the "most verbose" IMHO). On the other hand, it's not new... – fine.

__u32 updated_to = 0;
bool did_update_to_old = false;

{ // acquire lock

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.

OK!

@rzarzynski

rzarzynski commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor

Let's bake this in main for awhile.

@kamoltat

Copy link
Copy Markdown
Member Author

jenkins test make check

In ProtocolV2::send_server_ident(), the global_seq was being fetched
from messenger->get_global_seq() and used in the ServerIdentFrame,
however, it is stored in a local var and not the private class var
ProtocolV2::global_seq. This causes problems like
where the receiving peer sees a peer_global_seq that
appears older than expected, triggering a false-positive reconnect logic:

```
2025-07-15T11:40:50.927+0000 mon.c handle_existing_connection client has clearly restarted
(peer_global_seq < ex_peer_global_seq && cookie changed), dropping existing connection=0x563ffe9a9000 in favor of new one
```

In this case, mon.c received a peer_global_seq=75, which was already logged by mon.d as gs=79 in
its send_server_ident()—but ProtocolV2::global_seq was never updated, resulting in inconsistent state and premature connection teardown.

This commit fixes the issue by assigning the freshly incremented messenger->get_global_seq() value to the local global_seq field in ProtocolV2 as well,
ensuring consistency in the protocol.

Fixes: https://tracker.ceph.com/issues/71344

Signed-off-by: Kamoltat Sirivadhna <[email protected]>
Some existing netsplit test in 3az + stretch mode
needed white listing and check for netsplit details

Make qa/tasks/mon_thrash.py set
mon_netsplit_grace_period to 30 seconds
when we try to freeze monitors instead of killing them.

Make qa/tasks/stretch_mode_disable_enable.py set
mon_netsplit_grace_period to 30 seconds
during `teardown` phase only.

Fixes: https://tracker.ceph.com/issues/71344

Signed-off-by: Kamoltat Sirivadhna <[email protected]>
Update the MON_NETSPLIT health check documentation to reflect the
introduction of the configurable mon_netsplit_grace_period option.

Fixes: https://tracker.ceph.com/issues/71344

Signed-off-by: Kamoltat Sirivadhna <[email protected]>
@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

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@kamoltat - The PR has been tested. Please feel free to merge it after resolving the configuration changes check.

@ljflores

ljflores commented Nov 4, 2025

Copy link
Copy Markdown
Member

Config Diff Tool Output

+ added: mon_netsplit_grace_period (mon.yaml.in)
! changed: nvmeof_mon_client_connect_panic: old: ['mon'] (mon.yaml.in)
! changed: nvmeof_mon_client_connect_panic: new: None (mon.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary. Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

The new config was documented here: https://github.com/ceph/ceph/pull/64122/files#diff-47d8f55f7cd60b595629a31ccc8284c87adf4d44c15d5c84966db2a6ddec8e4d

I'm going to dismiss the bot.

@ljflores

ljflores commented Nov 4, 2025

Copy link
Copy Markdown
Member

/config check ok

@ljflores
ljflores merged commit 9f54ab3 into ceph:main Nov 4, 2025
@rzarzynski

Copy link
Copy Markdown
Contributor

Let's bake this in main for awhile (2 months?) before backporting.

@anthonyeleven

Copy link
Copy Markdown
Contributor

I hope the & in the title doesn't cause problems. I've seen non-alphanumerics cause problems in e.g. release note formatting in the past.

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.

6 participants