Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f318a68
Unify transport handshakes on current upstream master
Spicy-cream Oct 9, 2026
d9fc07d
Merge current upstream master and preserve IPC V2 handshake compatibi…
Spicy-cream Oct 16, 2026
2e51361
Fix certificate name extraction with const OpenSSL accessors
Spicy-cream Oct 16, 2026
7ebd2f2
Merge pull request #75 from Spicy-cream/review/pr3535-sync-master-oct15
zchuango Oct 16, 2026
3da2dde
Merge current master and retain shared memory name validation
Spicy-cream Oct 19, 2026
d819d93
Merge pull request #79 from Spicy-cream/review/pr3535-shm-conflict-oct18
zchuango Oct 19, 2026
ebcb46d
Merge modular CMake master and preserve handshake proto generation
Spicy-cream Oct 20, 2026
29f3185
Merge pull request #82 from Spicy-cream/review/pr3535-cmake-conflict-…
zchuango Oct 20, 2026
0d5aeb5
Integrate URMA with the common transport handshake (#88)
Spicy-cream Oct 23, 2026
6afd001
Merge Apache master into URMA handshake
Spicy-cream Oct 23, 2026
bacfda1
Merge Apache master and preserve handshake source discovery
Spicy-cream Oct 23, 2026
96babbd
Retrigger community CI
Spicy-cream Oct 23, 2026
9ae366f
Rename the common transport handshake protocol
Spicy-cream Oct 23, 2026
0b9a6fd
Apply handshake review style and test cleanup
Spicy-cream Oct 23, 2026
822d5de
Fix transport handshake cleanup and dispatch
Spicy-cream Oct 26, 2026
cebd46c
Handle handshake startup errors and preserve failure causes
Spicy-cream Oct 26, 2026
9ab0f4d
Retrigger transport handshake CI
Spicy-cream Oct 26, 2026
0c36adb
Release URMA fallback buffers and preserve handshake errors
Spicy-cream Oct 26, 2026
071ee1b
Move legacy URMA handshake peers into interoperability tests
Spicy-cream Oct 26, 2026
c0ef0ea
Synchronize handshake read cancellation test and clarify protocol naming
Spicy-cream Oct 26, 2026
82cfd76
Condense the common handshake design document
Spicy-cream Oct 26, 2026
f3012a3
Forward application connection stop notifications through the adapter
Spicy-cream Oct 26, 2026
0296dd4
Initialize handshake wait state and stop writes on socket failure
Spicy-cream Oct 26, 2026
baf2aca
Stop handshake reads before consuming data from failed sockets
Spicy-cream Oct 26, 2026
51d2e18
Merge transport handshake fixes into URMA integration
Spicy-cream Oct 27, 2026
2c38095
Restore handshake pushback bytes before buffered input
Spicy-cream Oct 27, 2026
b669a68
Restore handshake pushback bytes before buffered input
Spicy-cream Oct 27, 2026
a4e3f84
Fix UBSHM timer cleanup and transaction pool shutdown
Spicy-cream Oct 27, 2026
bdfc9a1
Fix UBSHM upgrade cancellation and timer callback lifetime
Spicy-cream Nov 3, 2026
6842aa7
Simplify handshake test setup and remove unused timer helpers
Spicy-cream Nov 3, 2026
04eb56c
Remove unused handshake APIs and simplify socket IO loops
Spicy-cream Nov 3, 2026
aaeffc9
Simplify buffered handshake input and consolidate regression fixtures
Spicy-cream Nov 3, 2026
3b0ff2c
Consolidate handshake adapters and shared RDMA codecs
Spicy-cream Nov 3, 2026
aa7f688
Preserve TCP reads when unavailable upgrades revive
Spicy-cream Nov 3, 2026
6482a37
Complete UBSHM cleanup when its timer cannot start
Spicy-cream Nov 3, 2026
ee8db57
Unify UBSHM close ownership and transaction lifetime
Spicy-cream Nov 3, 2026
8063157
Pin the UBSHM connection before polling its endpoint
Spicy-cream Nov 3, 2026
4f10659
Pin the UBSHM connection before polling its endpoint
Spicy-cream Nov 3, 2026
3944d3e
Preserve URMA send input until a work request is accepted
Spicy-cream Nov 3, 2026
ae4534c
Align UBSHM cleanup with the transport handshake branch
Spicy-cream Nov 3, 2026
45d8e55
Fix UBS cleanup ownership and retry shutdown
Spicy-cream Nov 4, 2026
b24ca40
Preserve UBS cleanup ownership across allocation failures
Spicy-cream Nov 4, 2026
f771208
Defer UBS device faults during initialization and preserve name owner…
Spicy-cream Nov 4, 2026
8e24a18
Fix UBSHM poller dispatch and process shutdown
Spicy-cream Nov 5, 2026
c43bcd1
Make UBSHM example pacing and RPC results reliable
Spicy-cream Nov 5, 2026
573d742
Use portable GoogleTest flag access in UBSHM exit test
Spicy-cream Nov 5, 2026
bfb3956
Retry CI after transient Thrift download failures
Spicy-cream Nov 5, 2026
a5953ab
Fix CQ callback ownership and roll back poller startup failures
Spicy-cream Nov 5, 2026
401e6bb
Merge Apache master and adapt RDMA MTU negotiation to common handshake
Spicy-cream Nov 5, 2026
c5fdb67
Keep transport policy out of shared connection code
Spicy-cream Nov 6, 2026
aaf70de
Keep URMA-specific cleanup out of the common handshake change
Spicy-cream Nov 6, 2026
8331f19
Fix poller shutdown reentry and handshake diagnostics
Spicy-cream Nov 6, 2026
4f7912d
Support GoogleTest 1.11 in poller and exit tests
Spicy-cream Nov 6, 2026
3c95906
Simplify handshake phase handling
Spicy-cream Nov 9, 2026
da10630
Retry macOS FlatBuffers CI after acceptance timeout
Spicy-cream Nov 9, 2026
99c1885
Remove redundant handshake session state
Spicy-cream Nov 10, 2026
12c07c1
Merge Apache master and preserve RDMA handshake retry
Spicy-cream Nov 18, 2026
e5cabd0
Dispatch transport handshakes through a static registry
Spicy-cream Nov 18, 2026
8142980
Merge Apache master and adapt the common RDMA handshake to SRQ
Spicy-cream Nov 21, 2026
d9b502a
Merge the upstream UBSHM IPC unlink fix
Spicy-cream Nov 21, 2026
90e9272
Merge remote-tracking branch 'apache/master' into review/pr3535-trans…
Spicy-cream Nov 23, 2026
f22c03c
Address transport handshake review feedback
Spicy-cream Nov 23, 2026
65d0299
Fix UBSHM mapping lifetime and cleanup retries
Spicy-cream Nov 23, 2026
239e94e
Merge commit '73ccf6a5' into review/pr3535-flatbuffers-ci-local
Spicy-cream Nov 23, 2026
dae4d5c
Update FlatBuffers RDMA tests to use the common handshake
Spicy-cream Nov 23, 2026
4676484
Preserve NSHEAD requests during UBSHM handshake probing
Spicy-cream Nov 23, 2026
e1d5fd5
Protect transport I/O during connection teardown
Spicy-cream Nov 23, 2026
b3658b8
Merge common transport handshake updates into URMA
Spicy-cream Nov 25, 2026
5da87ee
Merge Apache master into URMA handshake
Spicy-cream Nov 25, 2026
76dfb91
Keep URMA test I/O explicit after the handshake merge
Spicy-cream Nov 25, 2026
280fe3e
Adapt legacy URMA fixtures to current socket APIs
Spicy-cream Nov 25, 2026
f5ba4a4
Preserve the socket contract when URMA write waiting stops
Spicy-cream Nov 25, 2026
fd27313
Merge Apache master and preserve owner-only UBSHM segments
Spicy-cream Nov 26, 2026
2052d12
Merge common transport handshake updates into URMA
Spicy-cream Nov 26, 2026
3c8c391
Retry CI after the Clang ASan test timeout
Spicy-cream Nov 27, 2026
3ad27b5
Merge Apache master and address transport lifetime review
Spicy-cream Nov 30, 2026
81a2e27
Merge transport lifetime fixes into URMA handshake
Spicy-cream Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ filegroup(
srcs = glob([
"src/brpc/*.proto",
"src/brpc/policy/*.proto",
"src/brpc/rdma/*.proto",
"src/brpc/urma/*.proto",
]),
visibility = ["//visibility:public"],
Expand All @@ -570,6 +569,7 @@ FLATBUFFERS_SRC_PATTERNS = [
]

URMA_SRC_PATTERNS = [
"src/brpc/handshake/urma_handshake.cpp",
"src/brpc/urma/*.cpp",
"src/brpc/urma/**/*.cpp",
]
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ JSON2PB_DIRS = src/json2pb
JSON2PB_SOURCES = $(foreach d,$(JSON2PB_DIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
JSON2PB_OBJS = $(addsuffix .o, $(basename $(JSON2PB_SOURCES)))

BRPC_DIRS = src/brpc src/brpc/details src/brpc/builtin src/brpc/policy src/brpc/policy/mysql src/brpc/rdma
BRPC_DIRS = src/brpc src/brpc/details src/brpc/builtin src/brpc/handshake src/brpc/policy src/brpc/policy/mysql src/brpc/rdma
ifeq ($(WITH_FLATBUFFERS),1)
BRPC_DIRS += src/brpc/flatbuffers
endif
Expand All @@ -220,7 +220,8 @@ ifneq ($(WITH_FLATBUFFERS),1)
BRPC_SOURCES_ALL := $(filter-out src/brpc/policy/flatbuffers_protocol.cpp,$(BRPC_SOURCES_ALL))
endif
BRPC_SOURCES = $(filter-out $(THRIFT_SOURCES) $(EXCLUDE_SOURCES), $(BRPC_SOURCES_ALL))
BRPC_PROTOS = $(filter %.proto,$(BRPC_SOURCES))
# TCP-only servers also encode the disabled URMA Hello.
BRPC_PROTOS = $(sort $(filter %.proto,$(BRPC_SOURCES)) src/brpc/urma/urma_handshake.proto)
BRPC_CFAMILIES = $(filter-out %.proto %.pb.cc,$(BRPC_SOURCES))
BRPC_OBJS = $(BRPC_PROTOS:.proto=.pb.o) $(addsuffix .o, $(basename $(BRPC_CFAMILIES)))

Expand Down Expand Up @@ -318,6 +319,8 @@ output/bin:protoc-gen-mcpack
src/mcpack2pb/generator.o:src/mcpack2pb/generator.cpp src/idl_options.pb.h
$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@

src/brpc/handshake/urma_fallback_handshake.o src/brpc/handshake/urma_fallback_handshake.dbg.o: src/brpc/urma/urma_handshake.pb.h

%.o:%.cpp
@echo "> Compiling $@"
$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
Expand Down
48 changes: 48 additions & 0 deletions docs/cn/handshake_common_design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 公共传输握手

RDMA、UBSHM 和 URMA 共用握手流程,以 TCP 交换控制帧。升级成功后使用高速
数据面,协商不可用时继续使用 TCP。

## 分工

| 组件 | 职责 |
| --- | --- |
| `AdapterTransport` | 持有 TCP 与高速 Transport,启动握手、分发输入并选择数据面 |
| `HandshakeSession` | 编排客户端和服务端流程,管理帧收发、增量解析和终态发布 |
| `HandshakeProtocol` | 编解码 hello、ACK 和扩展帧,校验协议版本及字段 |
| `HandshakeTransport` | 准备和协商资源,处理升级、回退及失败清理 |
| 各传输的 Endpoint | 管理传输资源和数据面 |

RDMA 和 UBSHM 各自声明 hello 帧规格及升级入口,由静态表统一分流。
未编译高速传输的节点仍可识别 hello 并协商回退到 TCP。

客户端在 TCP 连接建立后启动握手 bthread;服务端通过 `InputMessenger`
增量解析控制帧。在 `EXTENSION_WAIT` 和 `ACK_WAIT`,服务端保留解析上下文,
按已选协议版本继续处理后续帧。

## 状态与回退

- `ESTABLISHED`:业务数据走 RDMA/UBSHM/URMA,TCP 保留为控制连接。服务端
完成最终 ACK 解析并退出 TCP 解析循环后启动高速接收;额外 TCP 数据触发连接错误。
- `FALLBACK_TCP`:释放升级资源后以 release 顺序发布终态,事件线程以
acquire 顺序读取并继续处理已缓存及后续的 TCP 业务数据。
- `FAILED`:握手 I/O 错误或畸形帧导致失败,清理资源并关闭连接。

完整帧按边界消费;分片输入返回 `NOT_ENOUGH_DATA` 等待补齐,
与握手 magic 不匹配的前缀返回 `TRY_OTHERS`。

## 协议兼容

- RDMA 保持 v2/v3 wire format 和协议数值 ID `1`。公共握手使用枚举
`PROTOCOL_RDMA_HANDSHAKE`,注册名称为 `rdma_handshake`。
- UBSHM 使用 64 字节 v3 hello、4 字节网络序格式扩展和 4 字节 ACK。
IPC 后端选择 `IPC_V2`,UBS 后端选择 `LEGACY_64`;格式相同则升级,否则
回退 TCP。资源映射使用对端共享内存长度,数据面激活前发布协商格式。

- URMA 保持 v2 二进制和 v3 protobuf 格式;资源导入和收发信用由
`UrmaEndpoint` 管理。服务端退出 TCP 握手解析后注册 CQ 回调。

## 测试

覆盖分片与粘连输入、magic 分流、版本与格式校验、TCP 回退、资源释放、
终态发布、最终 ACK 与首包并发,以及 RDMA、UBSHM 和 URMA 回归测试。
42 changes: 15 additions & 27 deletions docs/cn/urma.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,41 +100,29 @@ sopt.socket_mode = brpc::SOCKET_MODE_URMA;
server.Start(port, &sopt);
```

若对端不支持 URMA(例如 TCP 客户端连接 URMA 服务端),在 4 字节 magic
握手后透明回退到 TCP,应用代码无需改动。
TCP 客户端可以直接连接 URMA 服务端。URMA 客户端收到禁用 URMA 的
Hello 后继续使用 TCP。

## 架构

UrmaTransport 沿用与 `RdmaTransport` / `UBShmTransport` 一致的两层设计:
`AdapterTransport` 编排公共握手,并在 TCP 和 URMA 数据面之间选择:

```
UrmaTransport : public Transport (urma_transport.{h,cpp})
+-- std::shared_ptr<TcpTransport> (回退路径)
+-- urma::UrmaEndpoint* (URMA 数据路径)
+-- UrmaState { URMA_ON, URMA_OFF, URMA_UNKNOWN }

urma::UrmaEndpoint : public SocketUser (urma/urma_endpoint.{h,cpp})
+-- UrmaResource { jfc, jfce, jfr, jetty, remote_jetty, remote_seg }
+-- 握手状态机(C/S 对称,在 TCP fd 上驱动)
+-- 发送路径:urma_post_jetty_send_wr(URMA_OPC_SEND)
+-- 接收路径:urma_poll_jfc -> HandleCompletion -> InputMessenger
+-- 双窗口信用流控(_remote_rq_window_size / _sq_window_size)
AdapterTransport
+-- TcpTransport (TCP 握手、普通 TCP 请求和回退)
+-- UrmaTransport
+-- UrmaEndpoint (URMA 资源、CQ 与收发信用)
```

### 建链流程(双平面)
### 建链流程

与 RDMA / UBRing 一致,控制面为 TCP,数据面为 URMA:

1. TCP 连接建立。
2. `UrmaConnect::StartConnect` 起客户端握手 bthread。
3. 双方在 TCP fd 上交换 `UrmaHello` 消息(v2 二进制 magic `URMA`,
v3 protobuf magic `URM3`),携带本地 EID、jetty id、recv buffer 数量、
以及扁平化的 buffer 池 segment。
4. 双方先调用 `urma_import_seg` **再**调用 `urma_import_jetty`,为远端 EID
建立传输路径(TP)路由。跳过 `import_seg` 会导致首个 SEND 被硬件以
`URMA_CR_RNR_RETRY_CNT_EXC_ERR` 拒绝。
5. 4 字节 ACK(`HELLO_ACK_URMA_OK = 0x1`)确认双方均要 URMA。
6. 成功后 TCP fd 仅保留用于 epoll 生命周期和回退,数据走 URMA。
1. TCP 连接建立后,`AdapterTransport` 启动客户端握手 bthread。服务端
通过 `InputMessenger` 解析握手帧。
2. 双方交换 Hello。v2 使用二进制格式和 magic `URMA`,v3 使用 protobuf
和 magic `URM3`。Hello 携带 EID、jetty ID、接收缓冲区数量和缓冲池段信息。
3. 双方先调用 `urma_import_seg`,再调用 `urma_import_jetty`。
4. 客户端发送 4 字节 ACK 确认升级。服务端处理完 ACK 并退出 TCP 握手解析后
启动 CQ 接收。业务数据走 URMA,TCP 保留为控制连接。

### 内存管理

Expand Down
51 changes: 18 additions & 33 deletions docs/en/urma.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,31 @@ sopt.socket_mode = brpc::SOCKET_MODE_URMA;
server.Start(port, &sopt);
```

If the peer does not speak URMA (e.g. a TCP-only client connecting to a
URMA-enabled server), the transport transparently falls back to TCP after
the 4-byte magic handshake. No application code change is required.
TCP clients can connect directly to a URMA-enabled server. A URMA client
continues over TCP when it receives a disabled Hello.

## Architecture

UrmaTransport follows the same two-layer design as `RdmaTransport` and
`UBShmTransport`:
`AdapterTransport` runs the common handshake and selects the data path:

```
UrmaTransport : public Transport (urma_transport.{h,cpp})
+-- std::shared_ptr<TcpTransport> (fallback path)
+-- urma::UrmaEndpoint* (URMA data path)
+-- UrmaState { URMA_ON, URMA_OFF, URMA_UNKNOWN }

urma::UrmaEndpoint : public SocketUser (urma/urma_endpoint.{h,cpp})
+-- UrmaResource { jfc, jfce, jfr, jetty, remote_jetty, remote_seg }
+-- handshake state machine (C/S symmetric, driven over the TCP fd)
+-- send path: urma_post_jetty_send_wr(URMA_OPC_SEND)
+-- recv path: urma_poll_jfc -> HandleCompletion -> InputMessenger
+-- two-window credit flow control
(_remote_rq_window_size / _sq_window_size)
AdapterTransport
+-- TcpTransport (TCP handshake, ordinary requests and fallback)
+-- UrmaTransport
+-- UrmaEndpoint (URMA resources, CQ and flow-control credits)
```

### Connection establishment (dual-plane)

Like RDMA / UBRing, the control plane is TCP and the data plane is URMA:

1. TCP connect completes.
2. `UrmaConnect::StartConnect` spawns the client handshake bthread.
3. Both sides exchange a `UrmaHello` message (magic `URMA` for v2 binary,
`URM3` for v3 protobuf) over the TCP fd. The message carries the local
EID, jetty id, recv buffer count, and the flattened buffer-pool segment.
4. Each side calls `urma_import_seg` **before** `urma_import_jetty` to
establish transport-path (TP) routing for the remote EID. Skipping the
`import_seg` step causes the first SEND to be rejected by hardware with
`URMA_CR_RNR_RETRY_CNT_EXC_ERR`.
5. A 4-byte ACK (`HELLO_ACK_URMA_OK = 0x1`) confirms both sides want URMA.
6. On success, the TCP fd is kept only for the epoll lifecycle and fallback;
payloads flow through URMA.
### Connection establishment

1. After TCP connects, `AdapterTransport` starts the client handshake bthread.
The server parses handshake frames through `InputMessenger`.
2. The peers exchange Hello frames. Version 2 uses binary encoding with the
`URMA` magic prefix, and version 3 uses protobuf with `URM3`. The frames
carry the EID, jetty ID, receive buffer count, and buffer pool segment details.
3. Both peers call `urma_import_seg` before `urma_import_jetty`.
4. The client sends a 4-byte ACK to confirm the upgrade. The server starts
receiving CQ events after processing the ACK and leaving the TCP handshake
parser. RPC traffic uses URMA, and TCP remains the control connection.

### Memory management

Expand Down
Loading
Loading