Skip to content

Fall back from SRQ to a dedicated RQ before TCP - #3782

Open
chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:rdma-handshake-srq-fallback
Open

chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:rdma-handshake-srq-fallback

Conversation

@chenBright

@chenBright chenBright commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

A client that requests a shared receive queue (SRQ) can fall back to TCP even when both peers support RDMA with a dedicated receive queue (RQ).

What is changed and the side effects?

Changed:

  • Try a dedicated RQ before falling back to TCP. If local SRQ allocation fails before the first hello, the client uses the original TCP connection for the dedicated-RQ hello. If a v3 peer declines SRQ, replies with dedicated-RQ parameters, or local SRQ activation fails, the client sends ACK=0 and allocates a dedicated QP. It reconnects only if allocation succeeds. Otherwise, it can send the pending RPC over the original TCP connection.
  • Recognize both the current all-zero v3 refusal and the early v3 refusal with qp_num=0 and valid dedicated-RQ parameters. Peers that only support v2 can still negotiate a dedicated RQ. Each logical connection gets at most two hello exchanges under the original connect deadline. A scheduling delay after the final ACK no longer turns a completed handshake into a timeout.
  • Add rdma_connect_srq for outgoing connections (default false) and rdma_accept_srq for incoming connections (default true). Turning off server admission through /flags declines new SRQ requests before allocating resources. Established SRQ connections continue serving RPCs.

Handshake fallback:

A is the original TCP connection. B is opened only for a second handshake. Before sending any hello, the client can switch from SRQ to a dedicated RQ on A. If neither QP can be allocated and the connection is still usable, the RPC goes directly over TCP on A.

sequenceDiagram
    participant C as Client
    participant S as Server

    C->>S: A · v3 hello with SRQ or dedicated RQ
    alt Matching queue mode and local QP activation succeeds
        S-->>C: A · matching RDMA parameters
        C->>S: A · ACK=1
        C->>S: RPC over RDMA
    else Retryable SRQ failure
        S-->>C: A · v3 reply
        C->>S: A · ACK=0
        C->>C: Allocate a dedicated QP while A is still usable
        alt QP allocated
            C->>S: Open B
            C->>S: B · v3 hello with dedicated RQ
        else QP unavailable
            C->>S: RPC over TCP on A
        end
    else Peer closes early, resets, or replies with v2 magic
        C->>S: Open B
        C->>C: Reuse or allocate a dedicated QP
        alt QP ready
            C->>S: B · v2 hello with dedicated RQ
        else QP unavailable
            C->>S: RPC over TCP on B
        end
    else Other complete but unusable reply
        S-->>C: A · unusable RDMA parameters
        C->>S: A · ACK=0
        C->>S: RPC over TCP on A
    end

    opt A second hello was sent on B
        alt Matching parameters and local QP activation succeeds
            S-->>C: B · dedicated RQ parameters
            C->>S: B · ACK=1
            C->>S: RPC over RDMA
        else Complete reply but RDMA cannot be established
            S-->>C: B · hello reply
            C->>S: B · ACK=0
            C->>S: RPC over TCP on B
        else Another version retry is requested
            C->>C: Fail the connection
        end
    end
Loading

A retryable SRQ failure is an explicit or historical refusal, a valid dedicated-RQ reply to an SRQ offer, or a local SRQ QP activation failure. A legacy all-zero refusal gives no indication whether the server supports a dedicated RQ. Cancellation, deadline expiry during negotiation, a failed reconnect, or a fatal I/O or framing error ends the handshake with an error.

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

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.

🟡 Changes recommended

A critical RDMA initialization issue remains: eager preallocation of the default resource pool can exhaust HCA or system resources and cause startup failure before the SRQ path can operate.

1 open issue
What changed in this PR

This PR updates RDMA connection negotiation so SRQ-preferring clients can fall back to a dedicated receive queue before using TCP, while adding runtime SRQ admission control and broader compatibility coverage.

Changes:

  • Adds client-side dedicated-RQ retry, bounded reconnects, v2/v3 handshake compatibility, deadline handling, and TCP fallback.
  • Adds rdma_connect_srq and rdma_accept_srq flags with cached SRQ capability validation and server admission control.
  • Expands SRQ/RDMA resource and handshake tests and updates English and Chinese documentation.
File Description
test/​brpc_srq_unittest.cpp Updates SRQ option and device tests and adds worker recovery and admission-control coverage.
test/​brpc_rdma_unittest.cpp Adds handshake fallback, refusal, deadline, queue-mode, and resource-failure tests.
src/​brpc/​rdma/​srq_worker.h Exposes SRQ device capability validation and removes the obsolete SRQ flag declaration.
src/​brpc/​rdma/​srq_worker.cpp Refactors SRQ capability validation and rate-limits resource allocation diagnostics.
src/​brpc/​rdma/​srq_receive_pool.cpp Rate-limits receive-pool allocation and registration errors.
src/​brpc/​rdma/​rq_connection.cpp Enables dedicated-QP resource precreation regardless of SRQ preference.
src/​brpc/​rdma/​rdma_helper.h Declares the SRQ availability query interface.
src/​brpc/​rdma/​rdma_helper.cpp Caches and exposes SRQ hardware and configuration availability.
src/​brpc/​rdma/​rdma_handshake.proto Adds the optional v3 refusal indicator.
src/​brpc/​rdma/​rdma_handshake.h Adds the declined handshake result and updates refusal semantics.
src/​brpc/​rdma/​rdma_handshake.cpp Recognizes explicit and legacy v3 refusals during client negotiation.
src/​brpc/​rdma/​rdma_handshake_server.h Declares shared v3 refusal-message construction.
src/​brpc/​rdma/​rdma_handshake_server.cpp Emits explicit refusal responses for RDMA and TCP-only paths.
src/​brpc/​rdma/​rdma_endpoint.h Declares client negotiation, queue allocation, and handshake-finalization helpers.
src/​brpc/​rdma/​rdma_endpoint.cpp Implements SRQ/private-RQ negotiation, reconnect fallback, server admission, and deadline-aware handshake completion.
docs/​en/​rdma.md Documents the new SRQ flags, fallback behavior, and resource implications in English.
docs/​cn/​rdma.md Documents the new SRQ flags, fallback behavior, and resource implications in Chinese.

Review effort: Lite

Comment thread src/brpc/rdma/rq_connection.cpp Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants