Commit b9e53c6
authored
feat(bigtable): add Session lifecycle (Start, Close, ForceClose, readLoop, heartBeatLoop) (#20215)
## Summary
Third and final PR in the Session core stack. Adds the lifecycle
orchestration that drives a Session from \`Start\` through teardown,
plus the \`readLoop\` that dispatches server frames to the vRPC handlers
landed in #20213.
**Stacks on** #20213 (Session vRPC dispatch + slot lifecycle). Deletes
the minimal \`ForceClose\` stub that PR shipped, replacing it with the
full lifecycle-shaped body.
### What lands
**New file: \`session_lifecycle.go\`** (~640 LOC)
- \`Session.Start(ctx, OpenSessionRequest)\` — transitions New→Starting,
Sends the OpenSession frame, fires \`onStart\`, spawns \`readLoop\` +
\`heartBeatLoop\`. Wraps a failed \`Send\` as \`codes.Unavailable\` so
retry plumbing treats pre-wire OpenSession loss the same as any other
transport-side loss.
- \`ForceClose\` — full body: \`transitionTo(Closed)\` →
\`setCloseReason\` → \`notifyClosing\` (once) → \`cancelActiveRPCs\` →
\`signalQuiescent\` → \`notifyClosed\`.
- \`Close(ctx, CloseSessionRequest)\` — graceful drain: Ready→Closing,
waits on \`quiescent\`, sends CloseSession, transitions to
WaitServerClose, arms the pool's stuck-session sweep to eventually
ForceClose if the server never confirms.
- \`notifyClosing\` / \`notifyClosed\` — once-guarded hook dispatchers
with the strict \`onClosing\`-precedes-\`onClose\` ordering enforced.
- \`readLoop(ctx)\` — Recv-loop that dispatches every SessionResponse
variant via \`handleSessionResponse\`, drives \`handleClose\` on stream
termination, records \`msgsRecv\` counters + resets heartbeat deadline
on every recognized frame.
- \`handleSessionResponse\` — dispatch switch to \`handleOpenSession\` /
\`handleVRPCResponse\` / \`handleErrorResponse\` /
\`handleSessionParameters\` / \`handleGoAway\` /
\`handleSessionRefreshConfig\`. Heartbeat frames reset the deadline;
unknown-payload branch records a debug tag but doesn't reset (so a
misbehaving server can't keep the watchdog satisfied with junk).
- \`handleOpenSession\` — Starting→Ready transition, PeerInfo extract
from the bidi header (synchronous, matches Java's onHeaders synchrony),
fires \`onActive\`.
- \`handleGoAway\` / \`handleClose\` / \`handleErrorResponse\` /
\`handleSessionParameters\` / \`handleSessionRefreshConfig\` —
protocol-level handlers.
- \`heartBeatLoop\` — Timer + \`heartbeatWake\` reactive-wake pair. Only
enforces the deadline while a vRPC is in flight (idle sessions
legitimately receive no server heartbeats). See SESSION_SPEC.md #7.
- \`peerInfoExtracter\` — parses the \`bigtable-peer-info\` header,
stamps \`s.peerInfo\` atomically before \`onActive\` fires.
- \`closeReasonLabel\` / \`closeReasonToCause\` —
CloseSessionRequest.Reason → string / sentinel error mapping for
close-reason attribution.
**New file: \`session_lifecycle_test.go\`** (~660 LOC) — 30+ tests
covering Start, ForceClose, Close, readLoop, handleSessionResponse
dispatch, handleOpenSession + peerInfo parsing, handleGoAway,
handleClose, handleErrorResponse (rpc_id=0 harmlessly drops via
routeVRPCFrame guards), heartBeatLoop (reactive wake, idle-gate,
missed-heartbeat ForceClose).
**Edits to \`session_vrpc.go\`**
- Delete the minimal \`ForceClose\` stub introduced in the prior PR —
the full body lives in \`session_lifecycle.go\` now.
**Edits to \`session_test.go\`**
- \`hookCounts\` helper (start/active/close callback counters).
- \`setSlotForTest\` helper (seed the in-flight slot from tests).
### Stack
1. #20211 — Session debug surface
2. #20213 — Session vRPC dispatch + slot lifecycle
3. **This PR** — Session lifecycle
## Test plan
- [x] \`go build ./internal/transport/\` passes
- [x] \`go vet ./internal/transport/\` clean
- [x] \`go test ./internal/transport/ -count=1 -short -timeout 90s\`
passes — 30+ new lifecycle tests plus all pre-existing tests1 parent ef97df3 commit b9e53c6Copy full SHA for b9e53c6
9 files changed
+3,102-21Lines changed: 3102 additions & 21 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- bigtable/internal/transport
Expand file treeCollapse file tree
Open diff view settings
Collapse file
bigtable/internal/transport/debug_tracer.go
Copy file name to clipboardExpand all lines: bigtable/internal/transport/debug_tracer.go+11Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
93 | 93 | |
94 | 94 | |
95 | 95 | |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
96 | 101 | |
97 | 102 | |
98 | 103 | |
99 | 104 | |
100 | 105 | |
101 | 106 | |
102 | 107 | |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
103 | 114 | |
104 | 115 | |
105 | 116 | |
|
Collapse file
bigtable/internal/transport/session.go
Copy file name to clipboardExpand all lines: bigtable/internal/transport/session.go+65-9Lines changed: 65 additions & 9 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
61 | 61 | |
62 | 62 | |
63 | 63 | |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
64 | 71 | |
65 | | - |
66 | | - |
67 | | - |
68 | | - |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
69 | 77 | |
70 | 78 | |
71 | 79 | |
| ||
80 | 88 | |
81 | 89 | |
82 | 90 | |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
83 | 97 | |
84 | 98 | |
85 | 99 | |
| ||
159 | 173 | |
160 | 174 | |
161 | 175 | |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
162 | 182 | |
163 | 183 | |
164 | 184 | |
| ||
184 | 204 | |
185 | 205 | |
186 | 206 | |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
192 | 213 | |
193 | 214 | |
194 | 215 | |
| ||
245 | 266 | |
246 | 267 | |
247 | 268 | |
| 269 | + |
| 270 | + |
| 271 | + |
| 272 | + |
| 273 | + |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | + |
| 299 | + |
| 300 | + |
| 301 | + |
| 302 | + |
| 303 | + |
Collapse file
bigtable/internal/transport/session_debug.go
Copy file name to clipboardExpand all lines: bigtable/internal/transport/session_debug.go+18-1Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
150 | 150 | |
151 | 151 | |
152 | 152 | |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
153 | 170 | |
154 | 171 | |
155 | 172 | |
| ||
164 | 181 | |
165 | 182 | |
166 | 183 | |
167 | | - |
| 184 | + |
168 | 185 | |
169 | 186 | |
170 | 187 | |
|
0 commit comments