rajvarun77 opened a new pull request, #3348:
URL: https://github.com/apache/brpc/pull/3348
Generic `Controller`/`Socket` plumbing that lets a protocol pin a
pooled/short connection across multiple RPCs (connection affinity). This is the
shared substrate extracted from the MySQL client PR #3330 so it can be reviewed
independently; #3330 is now stacked on top of this branch and contains only the
MySQL-specific code.
### Controller
- `BindSockAction {NONE,RESERVE,USE}` encoded in two `Controller::_flags`
bits (`FLAGS_BIND_SOCK_RESERVE`/`USE`) via
`set_bind_sock_action()`/`bind_sock_action()` — no dedicated member added to
the hot `Controller`.
- `_bind_sock` holds a socket reserved by a previous RPC. `EndRPC`
propagates the action to the current `Call`; `Call::OnComplete` reserves the
socket (on success) instead of returning it to the pool / failing it;
`IssueRPC` reuses the reserved socket when the action is `USE`.
- `_session_data`: opaque per-RPC slot a protocol codec may use to carry
typed state between serialize/pack/parse (not owned by `Controller`).
### Socket
- `_fd_version` (relaxed atomic, bumped on every `ResetFileDescriptor`) +
`fd_version()` accessor — an ABA guard so an affinity holder can detect that a
reserved fd was reconnected underneath it. Atomic because it is written on the
reconnect path (no socket lock held) and read from other threads.
- `Socket::Write` accepts an empty buffer when `WriteOptions::auth_flags` is
set, for server-greets-first handshakes that send their first bytes from the
connection-phase handler rather than from `data`.
### Backup/retry fix
Also fixes an uninitialized read this machinery would otherwise introduce:
the `Call(Call*)` copy constructor used for backup requests and retries did not
initialize `bind_sock_action`, so `OnComplete` could read indeterminate bits
and (when they matched `RESERVE`/`USE`) divert the backup call's socket away
from the pool-return path, hanging the RPC (manifested as
`ChannelTest.backup_request` timing out). Initialized to `BIND_SOCK_NONE`,
matching `Call::Reset()`; a backup/retry never inherits affinity.
No protocol uses these primitives in this PR; the first consumer is MySQL
(#3330).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]