Repository navigation
feat: add URMA unified connection resource framework and exclusive backend - #3788
Open
CarbonadoR wants to merge 4 commits into
Open
CarbonadoR wants to merge 4 commits into
CarbonadoR wants to merge 4 commits into
Conversation
added 4 commits
November 28, 2026 11:20
Introduce the internal UrmaConnection / UrmaConnectionProvider interfaces under src/brpc/urma/ together with the per-connection exclusive backend (UrmaExclusiveConnection and UrmaExclusiveConnectionProvider). This commit is purely additive (aside from friend declarations in socket.h) and leaves existing UrmaEndpoint / UrmaTransport behavior untouched so the subsequent migration diff stays focused on existing classes. Ref: apache#3778
Switch UrmaEndpoint, UrmaTransport, and urma_helper to the UrmaConnection / UrmaConnectionProvider boundary: - Remove per-connection Jetty/JFR/JFC resources, ring buffers, credit windows, CQ polling, and SocketUser inheritance from UrmaEndpoint. - Delegate UrmaTransport::WaitEpollOut to UrmaEndpoint::WaitWritable and allocate per-socket UrmaConnect instances for cloned sockets. - Preserve existing v2/v3 handshake wire format, internal InputMessageClosure last_msg scope, and safe GlobalRelease teardown order. - Hand TCP fallback reads back to the socket event owner via Socket::OnInputEvent. Ref: apache#3778
…fecycle Extend the URMA link-time mock with deterministic fault injection and add unit tests covering UrmaConnection prefix sends, writable waits, early RX caching, stale-callback filtering, exclusive last_msg=nullptr behavior, TCP fallback handoff, Close/Shutdown ordering, and v2/v3 multi-connection RPCs. Ref: apache#3778
Sync docs/cn/urma.md and docs/en/urma.md with the UrmaConnection / UrmaExclusiveConnection architecture split and document the startup-only --urma_resource_mode flag. Ref: apache#3778
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Three critical concurrency and ownership bugs remain in connection publication, TCP fallback callback handling, and carrier cleanup.
3 open issues
What changed in this PR
Refactors URMA around a unified connection/provider abstraction while preserving the exclusive backend and existing handshake, polling, fallback, and data-flow behavior.
Changes:
- Adds connection/provider interfaces and startup resource-mode selection.
- Migrates exclusive resource management into a dedicated backend.
- Updates endpoint integration, tests, and documentation.
| File | Description |
|---|---|
| test/brpc_urma_unittest.cpp | Adds URMA lifecycle, callback, fault-injection, and multi-connection tests. |
| src/brpc/urma/urma_helper.cpp | Integrates provider initialization and global resource release. |
| src/brpc/urma/urma_exclusive_connection.h | Declares the exclusive URMA connection backend interfaces. |
| src/brpc/urma/urma_exclusive_connection.cpp | Implements exclusive resources, polling, flow control, and connection lifecycle. |
| src/brpc/urma/urma_endpoint.h | Updates endpoint state and connection ownership declarations. |
| src/brpc/urma/urma_endpoint.cpp | Integrates endpoint handshake, callbacks, connection delegation, and TCP fallback. |
| src/brpc/urma/urma_connection.h | Defines unified URMA connection, provider, callback, and option interfaces. |
| src/brpc/urma/urma_connection.cpp | Implements provider selection and connection lifecycle behavior. |
| src/brpc/urma/mock_urma.cpp | Adds deterministic mock fault-injection hooks for URMA tests. |
| src/brpc/urma_transport.cpp | Adapts transport connection creation and writable-wait delegation. |
| src/brpc/socket.h | Adds URMA connection friendship declarations. |
| docs/en/urma.md | Documents the revised URMA architecture and resource-mode flag. |
| docs/cn/urma.md | Documents the revised URMA architecture and resource-mode flag in Chinese. |
Review effort: Lite
Comment on lines
+378
to
+381
| UrmaConnectionHandle UrmaEndpoint::PinConnection() const { | ||
| // An acquire load makes the immutable owner visible. Normal RX/TX uses | ||
| // BorrowConnection to avoid touching the shared reference count. | ||
| return BorrowConnection() ? _connection : UrmaConnectionHandle(); |
Comment on lines
+460
to
+462
| if (ep && expected_connection && | ||
| expected_connection.get() == ep->BorrowConnection()) { | ||
| socket->SetFailed(error, "URMA connection failure"); |
Comment on lines
+372
to
+375
| if (Socket::Create(options, &_cq_sid) < 0) { | ||
| PLOG(ERROR) << "Fail to create CQ socket"; | ||
| return -1; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What problem does this PR solve?
Issue Number: Part of #3778, related to #3707
Problem Summary:
Currently
UrmaEndpointcouples TCP handshake/fallback andInputMessengerstream integration directly with per-connection URMA Jetty/JFR/JFC/JFCE lifecycle, send/recv ring buffers, credit windows, and CQ polling. This PR implements PR 1 of the staged plan in #3778: introducing an internalUrmaConnection/UrmaConnectionProviderboundary undersrc/brpc/urma/and migrating the existing per-connection exclusive implementation intoUrmaExclusiveConnection/UrmaExclusiveConnectionProvider, preparing for follow-up shared JFS/JFR pooled backend PRs (#3707 / #3778) without duplicatingUrmaEndpointor changing existing exclusive behavior.What is changed and the side effects?
Changed:
src/brpc/urma/urma_connection.{h,cpp}):UrmaConnection,UrmaConnectionProvider,UrmaConnectionCallbacks,UrmaConnectionOptions, andUrmaConnectionDescription.--urma_resource_modeflag (default"exclusive";"pooled"currently returnsENOTSUPuntil follow-up PRs).src/brpc/urma/urma_exclusive_connection.{h,cpp}):UrmaResource(asUrmaExclusiveResources),_sbuf/_rbuf, SQ/RQ credit windows, CQ event/polling handlers, andUrmaPollerGroupout ofUrmaEndpoint.urma_handshake.*unchanged), event/polling/bonding behavior, and zero-copyIOBufownership.src/brpc/urma/urma_endpoint.{h,cpp},src/brpc/urma_transport.cpp,src/brpc/urma/urma_helper.cpp,src/brpc/socket.h):UrmaEndpointno longer inheritsSocketUser; it holds a stableUrmaConnectionHandle, validates callback source identity (OnReceivedBytes/OnConnectionError), caches early RX bytes untilESTABLISHED, preserves the original internalInputMessageClosurelast_msgscope whenon_input_readyreceivesnullptr, and delegatesWaitWritablefromUrmaTransport::WaitEpollOut.GlobalReleasenow waits forUrmaEndpoint::GlobalRelease()and verifies outstanding registered pool blocks before unregistering memory and destroying the URMA context.src/brpc/urma/mock_urma.cpp,test/brpc_urma_unittest.cpp):Close/Shutdownordering, early RX caching & stale-callback rejection, exclusivelast_msg == nullptrcontract, and v2/v3 multi-connection RPCs.docs/cn/urma.md,docs/en/urma.md):UrmaConnection/UrmaExclusiveConnectionand documents--urma_resource_mode.Side effects:
masterin exclusive mode. Verified on two openEuler 24.03 aarch64 URMA nodes (URMA_CTP, 14-point matrix covering QPS 1000/500 and payload sizes 1 KiB–8 MiB, 0% error rate): 1 KiB avg/P9928/37 usvsmaster28/38 us; 8 MiB 4-run interleaved A/B mean1230.4 MB/svsmaster1234.0 MB/s(-0.29%, within run-to-run variance).Verification
-DWITH_URMA=OFF:brpc-staticbuilds cleanly.-DWITH_URMA=ON -DURMA_USE_MOCK=ON:brpc_urma_unittestpasses in event mode (42/42, 2 polling/multi-tag skipped) and with--urma_use_polling=true --task_group_ntags=2(44/44, plus--gtest_repeat=20on shutdown/delete fault tests).-DWITH_URMA=ON -DURMA_USE_MOCK=OFF(realliburma.so):brpc_urma_unittest: 13 passed, 31 mock-only skipped, 0 failed.ub_test: event mode, polling mode, 8-connection concurrency,bonding_dev_0, TCP fallback, bidirectional PR 1 ↔masterinterop, and 14-point matrix (1 KiB–8 MiB) all passed with 0 errors.Check List: