Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 15 additions & 9 deletions docs/cn/urma.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,22 @@ server.Start(port, &sopt);
UrmaTransport 沿用与 `RdmaTransport` / `UBShmTransport` 一致的两层设计:

```
UrmaTransport : public Transport (urma_transport.{h,cpp})
+-- std::shared_ptr<TcpTransport> (回退路径)
+-- urma::UrmaEndpoint* (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)
urma::UrmaEndpoint (urma/urma_endpoint.{h,cpp})
+-- 握手状态机(C/S 对称,在 TCP fd 上驱动)与 TCP fallback
+-- InputMessengerProcessor(URMA 输入缓存与协议解析)
+-- UrmaConnectionHandle(绑定底层连接资源)

urma::UrmaConnection / Provider (urma/urma_connection.{h,cpp})
+-- urma::UrmaExclusiveConnection (urma/urma_exclusive_connection.{h,cpp})
+-- UrmaExclusiveResources { jfc, jfce, jfr, jetty, remote_jetty, remote_seg }
+-- 发送路径:urma_post_jetty_send_wr(URMA_OPC_SEND)
+-- 接收路径:urma_poll_jfc -> HandleCompletion -> on_bytes / on_input_ready
+-- 双窗口信用流控(_remote_rq_window_size / _sq_window_size)与 per-tag poller
```

### 建链流程(双平面)
Expand Down Expand Up @@ -150,6 +155,7 @@ block 都由注册 segment 支撑,发送路径可直接从 IOBuf block refs

| Flag | 默认 | 用途 |
|------|------|------|
| `--urma_resource_mode` | `"exclusive"` | URMA 连接资源后端(仅启动时生效;当前支持 `exclusive`,后续 PR 将接入 `pooled`) |
| `--urma_use_polling` | false | 轮询 JFC 而非事件模式 |
| `--urma_poller_num` | 1 | 每 bthread tag 的轮询器数(轮询模式) |
| `--urma_disable_bthread` | false | 内联处理消息(不起 bthread) |
Expand Down
26 changes: 16 additions & 10 deletions docs/en/urma.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,23 @@ UrmaTransport follows the same two-layer design as `RdmaTransport` and
`UBShmTransport`:

```
UrmaTransport : public Transport (urma_transport.{h,cpp})
+-- std::shared_ptr<TcpTransport> (fallback path)
+-- urma::UrmaEndpoint* (URMA data path)
UrmaTransport : public Transport (urma_transport.{h,cpp})
+-- std::shared_ptr<TcpTransport> (fallback path)
+-- urma::UrmaEndpoint* (URMA handshake & stream integration)
+-- 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)
urma::UrmaEndpoint (urma/urma_endpoint.{h,cpp})
+-- handshake state machine (C/S symmetric, driven over the TCP fd) & TCP fallback
+-- InputMessengerProcessor (URMA input buffer & protocol parsing)
+-- UrmaConnectionHandle (binds to the underlying connection resource backend)

urma::UrmaConnection / Provider (urma/urma_connection.{h,cpp})
+-- urma::UrmaExclusiveConnection (urma/urma_exclusive_connection.{h,cpp})
+-- UrmaExclusiveResources { jfc, jfce, jfr, jetty, remote_jetty, remote_seg }
+-- send path: urma_post_jetty_send_wr(URMA_OPC_SEND)
+-- recv path: urma_poll_jfc -> HandleCompletion -> on_bytes / on_input_ready
+-- two-window credit flow control (_remote_rq_window_size / _sq_window_size)
& per-tag pollers
```

### Connection establishment (dual-plane)
Expand Down Expand Up @@ -161,6 +166,7 @@ All flags use the `urma_` prefix (mirroring RDMA's `rdma_` prefix):

| Flag | Default | Purpose |
|------|---------|---------|
| `--urma_resource_mode` | `"exclusive"` | URMA connection resource backend (startup only; currently `exclusive`, with `pooled` planned in follow-up PRs) |
| `--urma_use_polling` | false | Busy-poll the JFC instead of event mode |
| `--urma_poller_num` | 1 | Poller bthreads per bthread tag (polling mode) |
| `--urma_disable_bthread` | false | Run message processing inline |
Expand Down
4 changes: 4 additions & 0 deletions src/brpc/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class RdmaHandshakeServerV3;
}

namespace urma {
class UrmaConnection;
class UrmaEndpoint;
class UrmaExclusiveConnection;
class UrmaConnect;
class UrmaHandshakeClientV2;
class UrmaHandshakeServerV2;
Expand Down Expand Up @@ -356,6 +358,8 @@ friend class rdma::RdmaHandshakeServerV2;
friend class rdma::RdmaHandshakeClientV3;
friend class rdma::RdmaHandshakeServerV3;
friend class urma::UrmaEndpoint;
friend class urma::UrmaConnection;
friend class urma::UrmaExclusiveConnection;
friend class urma::UrmaConnect;
friend class urma::UrmaHandshakeClientV2;
friend class urma::UrmaHandshakeServerV2;
Expand Down
113 changes: 107 additions & 6 deletions src/brpc/urma/mock_urma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <cstring>
#include <deque>
#include <map>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <sys/eventfd.h>
Expand Down Expand Up @@ -74,10 +75,22 @@ std::map<urma_jfr_t *, int> jfr_map;
std::map<urma_jfr_t *, urma_jfc_t *> jfr_jfc_map;
std::map<urma_jfr_t *, std::deque<PendingRecv>> jfr_recv_map;
std::map<urma_target_seg_t *, int> seg_map;
std::map<urma_jetty_t *, int> jetty_map;
std::map<urma_jetty_t *, std::shared_ptr<std::mutex>> jetty_map;
std::map<uint32_t, urma_jetty_t *> jetty_id_map;
std::map<urma_target_jetty_t *, int> target_jetty_map;
std::atomic<uint32_t> next_jetty_id{1};
// Deterministic teardown fault injection, exported only by the link-time mock.
std::atomic<int> fail_jetty_delete{0};
std::atomic<bool> fail_jetty_import{false};
std::atomic<bool> pause_jetty_delete{false};
std::atomic<bool> jetty_delete_entered{false};
std::atomic<int> fail_send_after{-1};
std::atomic<bool> pause_send{false};
std::atomic<bool> send_entered{false};
std::atomic<bool> pause_send_copy{false};
std::atomic<bool> send_copy_entered{false};
std::atomic<bool> pause_send_return{false};
std::atomic<bool> send_return_entered{false};

void PushCompletion(urma_jfc_t* jfc, JfcState* state,
const urma_cr_t& completion) {
Expand Down Expand Up @@ -462,12 +475,31 @@ urma_jetty_t *urma_create_jetty(urma_context_t *ctx, urma_jetty_cfg_t *cfg) {
jetty->jetty_id.id = next_jetty_id.fetch_add(1);
jetty->jetty_cfg = *cfg;
jetty->remote_jetty = nullptr;
jetty_map[jetty] = 1;
jetty_map[jetty] = std::make_shared<std::mutex>();
jetty_id_map[jetty->jetty_id.id] = jetty;
return jetty;
}

void brpc_urma_mock_fail_jetty_delete(int count) {
fail_jetty_delete.store(count);
}
void brpc_urma_mock_pause_jetty_delete(bool pause) {
if (pause) jetty_delete_entered.store(false);
pause_jetty_delete.store(pause);
}
bool brpc_urma_mock_jetty_delete_entered() {
return jetty_delete_entered.load();
}

urma_status_t urma_delete_jetty(urma_jetty_t *jetty) {
jetty_delete_entered.store(true);
while (pause_jetty_delete.load()) usleep(1000);
int failures = fail_jetty_delete.load();
while (failures > 0) {
if (fail_jetty_delete.compare_exchange_weak(failures, failures - 1)) {
return static_cast<urma_status_t>(EBUSY);
}
}
std::unique_lock<std::shared_mutex> lock(g_rw_mutex);
if (!jetty || jetty_map.find(jetty) == jetty_map.end()) {
return URMA_EINVAL;
Expand All @@ -487,9 +519,18 @@ urma_status_t urma_unbind_jetty(urma_jetty_t *jetty) {
return URMA_SUCCESS;
}

void brpc_urma_mock_fail_next_jetty_import() {
fail_jetty_import.store(true);
}

urma_target_jetty_t *urma_import_jetty(urma_context_t *ctx,
urma_rjetty_t *rjetty,
urma_token_t *token_value) {
if (fail_jetty_import.exchange(false)) {
errno = EIO;
return nullptr;
}

std::unique_lock<std::shared_mutex> lock(g_rw_mutex);
if (!ctx || !rjetty || !token_value ||
context_map.find(ctx) == context_map.end()) {
Expand Down Expand Up @@ -531,6 +572,31 @@ urma_status_t urma_modify_jetty(urma_jetty_t *jetty, urma_jetty_attr_t *attr) {
return URMA_SUCCESS;
}

void brpc_urma_mock_fail_send_after(int successful_wrs) {
fail_send_after.store(successful_wrs);
}
void brpc_urma_mock_pause_send(bool pause) {
if (pause) send_entered.store(false);
pause_send.store(pause);
}
bool brpc_urma_mock_send_entered() {
return send_entered.load();
}
void brpc_urma_mock_pause_send_copy(bool pause) {
if (pause) send_copy_entered.store(false);
pause_send_copy.store(pause);
}
bool brpc_urma_mock_send_copy_entered() {
return send_copy_entered.load();
}
void brpc_urma_mock_pause_send_return(bool pause) {
if (pause) send_return_entered.store(false);
pause_send_return.store(pause);
}
bool brpc_urma_mock_send_return_entered() {
return send_return_entered.load();
}

urma_status_t urma_post_jetty_send_wr(urma_jetty_t *jetty, urma_jfs_wr_t *wr,
urma_jfs_wr_t **bad_wr) {
std::shared_lock<std::shared_mutex> read_lock(g_rw_mutex);
Expand All @@ -546,9 +612,29 @@ urma_status_t urma_post_jetty_send_wr(urma_jetty_t *jetty, urma_jfs_wr_t *wr,
return URMA_EINVAL;
}
JfcState* local_state = local_jfc_it->second;
auto send_mutex = local_it->second;
read_lock.unlock();
// Model the provider's per-SQ post serialization, including SEND/ACK
// ordering. Never hold the global object-map mutex while waiting here.
std::lock_guard<std::mutex> send_lock(*send_mutex);

for (urma_jfs_wr_t* current = wr; current; current = current->next) {
if (current->opcode == URMA_OPC_SEND) {
send_entered.store(true);
while (pause_send.load()) usleep(1000);
int remaining = fail_send_after.load();
while (remaining >= 0) {
if (fail_send_after.compare_exchange_weak(
remaining, remaining - 1)) {
if (remaining == 0) {
if (bad_wr) *bad_wr = current;
errno = EIO;
return URMA_EINVAL;
}
break;
}
}
}
if (!current->tjetty) {
if (bad_wr) {
*bad_wr = current;
Expand All @@ -560,17 +646,20 @@ urma_status_t urma_post_jetty_send_wr(urma_jetty_t *jetty, urma_jfs_wr_t *wr,
send_cr.status = URMA_CR_SUCCESS;
send_cr.user_ctx = current->user_ctx;
send_cr.flag.bs.s_r = 0;
if (current->flag.bs.complete_enable) {
PushCompletion(jetty->jetty_cfg.jfs_cfg.jfc,
local_state, send_cr);
}
auto complete_send = [&] {
if (current->flag.bs.complete_enable) {
PushCompletion(jetty->jetty_cfg.jfs_cfg.jfc,
local_state, send_cr);
}
};

PendingRecv recv{};
urma_jfc_t* remote_jfc = nullptr;
{
std::unique_lock<std::shared_mutex> lock(g_rw_mutex);
auto remote_it = jetty_id_map.find(current->tjetty->id.id);
if (remote_it == jetty_id_map.end()) {
complete_send();
continue;
}
urma_jfr_t* remote_jfr =
Expand All @@ -579,13 +668,18 @@ urma_status_t urma_post_jetty_send_wr(urma_jetty_t *jetty, urma_jfs_wr_t *wr,
auto jfc_it = jfr_jfc_map.find(remote_jfr);
if (recv_it == jfr_recv_map.end() || recv_it->second.empty() ||
jfc_it == jfr_jfc_map.end()) {
complete_send();
continue;
}
recv = recv_it->second.front();
recv_it->second.pop_front();
remote_jfc = jfc_it->second;
}

if (current->opcode == URMA_OPC_SEND) {
send_copy_entered.store(true);
while (pause_send_copy.load()) usleep(1000);
}
uint32_t copied = 0;
for (uint32_t i = 0;
i < current->send.src.num_sge && copied < recv.len; ++i) {
Expand Down Expand Up @@ -617,6 +711,13 @@ urma_status_t urma_post_jetty_send_wr(urma_jetty_t *jetty, urma_jfs_wr_t *wr,
recv_cr.imm_data = current->send.imm_data;
PushCompletion(remote_jfc, remote_state, recv_cr);
}
// A TX CQE releases the application's last payload reference. The
// simulated DMA above must finish before making that CQE visible.
complete_send();
if (current->opcode == URMA_OPC_SEND) {
send_return_entered.store(true);
while (pause_send_return.load()) usleep(1000);
}
}
if (bad_wr) {
*bad_wr = nullptr;
Expand Down
Loading
Loading