Commit dbf0c3f
authored
feat(bigtable): add per-AFE sessionList for the two-tier session pool (#20224)
## Summary
First of five PRs porting the session-pool infrastructure from
`feat/bigtable-sessionz-debug` (which powers the recycle-repro fleet)
upstream. Stacks on #20215 (Session lifecycle, now merged).
### What lands
**New file: `session_list.go`** (~600 LOC) — the per-pool sessionList
data structure that groups sessions by the AFE (Application Front End)
their handshake landed on. Consumed by the two-tier picker
(K-choice-over-AFEs → dequeue-idle-session) in a follow-up PR.
Key types:
- `AfeID` (int64) — AFE identifier from the server's PeerInfo header at
session-open. 0 is the sentinel "unknown" bucket for handshakes that did
not carry a peer-info header.
- `AfeSnapshot` — value-typed view of an afeHandle for pickers to score
without holding sl.mu (Checkout re-resolves by ID; no *afeHandle
escapes).
- `AfeSnapshotRow` — debug-UI row emitted by `sessionList.Snapshot()`
(consumed by afez/sessionz in a later debug PR).
- `afeHandle` (unexported) — per-AFE bucket: FIFO idle queue, refCount
(idle + inFlight + closing), two PeakEwma trackers.
- `SessionHandle` — pool bookkeeping wrapper around Session. Carries
`inExpectedCount` (I5 guard against WaitServerClose retry storm) and
`activated / closingRecorded / closeRecorded` dedup flags for the pool's
per-session hook chain.
- `sessionList` (unexported) — the state machine, guarded by `sl.mu`.
The state model documents **six invariants (I1-I6)** that every method
preserves:
```
I1 inExpectedCount ⇒ handleToAfe[sh] != nil
I2 readyCount == count of inExpectedCount handles
I3 afesWithReady == {afe : len(afe.sessions) > 0}
I4 afe.refCount == count of handleToAfe entries pointing at afe
I5 sh in afe.sessions ⇒ handleToAfe[sh]==afe AND inExpectedCount
I6 refCount-- only on OnSessionClosed (Closing keeps slot warm)
```
Lock order: `sl.mu` ONLY. `RecordVRpcOutcome` deliberately drops `sl.mu`
between the map lookup and the `PeakEwma.Update` so the hot vRPC-outcome
path doesn't serialize on it.
Consolidates AFE types (`AfeID` + `AfeSnapshot`) that previously lived
in `afe_snapshot.go` — sessionList now owns all AFE-bucket concepts.
Deletes `afe_snapshot.go`.
**New file: `session_list_test.go`** (~770 LOC) — I1-I6 coverage plus
per-method tests (OnSessionStarted / Checkout / ReleaseToPool /
OnSessionClosing / OnSessionClosed / RecordVRpcOutcome / ReadyAfes /
Snapshot / AllHandles / Prune) and a concurrency stress test covering
the documented lock-drop path in RecordVRpcOutcome.
**Edits to `debug_tracer.go`** — three new tag constants for sessionList
bookkeeping violations (all unreachable-under-invariants, kept as
belt-and-suspenders):
- `tagSessionListStartedNilSession`
- `tagSessionListRefcountUnderflow`
- `tagSessionListReadyCountUnderflow`
**Edit to `session.go`** — one-line comment retarget on `AfeID()` (type
now lives in `session_list.go`, not the deleted `afe_snapshot.go`).
### Stack
1. #20211 — Session debug surface (merged)
2. #20213 — Session vRPC dispatch (merged)
3. #20215 — Session lifecycle (merged)
4. **This PR** — sessionList (PR-1 of 5)
5. Next — SessionPoolImpl core, pool_lifecycle, pool_scaling, pool_debug
## Test plan
- [x] `go build ./internal/transport/` passes
- [x] `go vet ./internal/transport/` clean
- [x] `go test ./internal/transport/ -race -count=1 -short
-timeout=120s` passes — 20+ new sessionList tests plus all pre-existing.1 parent 42a1fa8 commit dbf0c3f
5 files changed
Lines changed: 1408 additions & 29 deletions
File tree
- bigtable/internal/transport
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
121 | 151 | | |
122 | 152 | | |
123 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
| 236 | + | |
236 | 237 | | |
237 | 238 | | |
238 | 239 | | |
| |||
0 commit comments