Commit aa4a7ba
authored
feat(encryption): Stage 6E-2d — §7.1 quiescence barrier scaffold (#933)
## Summary
Stage 6E-2d ships the §7.1 quiescence-barrier scaffold inside
`EnableRaftEnvelope`. The barrier mechanism is fully wired and
tested but unreachable from operators — `raftEnvelopeWrapEnabled`
stays `false` in this slice (6E-2e wires the closure source from
`main.go`; 6E-2f atomically flips the gate).
### What ships
- `raftengine.ErrEnvelopeCutoverInProgress` sentinel error
returned on `Propose` under the barrier. `ProposeAdmin` is
exempt by interface contract so the cutover marker itself (and
ConfChange-time `RegisterEncryptionWriter`) cross the barrier.
- `dynamicWrappedProposer` barrier state (`barrierMu` +
`inflightUser` counter + `drainSig` channel) gating user-
`Propose` only.
- `BeginCutoverBarrier` / `WaitInflightDrained` /
`EndCutoverBarrier` trio on `dynamicWrappedProposer` driving
steps 1 / 2 / 6 of the §7.1 sequence.
- `ShardGroup` forwarder methods with degraded fast-path on raw-
Engine fallback so test fixtures degrade gracefully (immediate-
success drain, pre-closed Begin channel, no-op End).
- `CutoverBarrierController` interface +
`WithEncryptionAdminCutoverBarrier` option on
`EncryptionAdminServer` (no production impl yet — 6E-2e).
- `EnableRaftEnvelope` handler runs the §7.1 6-step sequence
(Begin → WaitDrained → ProposeAdmin → awaitCutoverApply →
InstallWrap → End-via-defer) when the gate is true. Refuses
with `FailedPrecondition` when the controller or latest-
applied-index callbacks are unwired so a misconfigured 6E-2f
release fails closed before any side effect.
- `raftEnvelopeWrapEnabled` converts from `const` to `var` so
unit tests can flip it via `t.Cleanup`-based override (production
value unchanged at `false`; 6E-2f atomically flips it).
### Behavior change, risk, test evidence
- **Behavior change**: production-observable change is **none**.
`raftEnvelopeWrapEnabled = false` short-circuits before any
6E-2d code path runs. The new error / barrier / state-machine
are dead code under operator use until 6E-2e/2f land.
- **Risk**: low. The barrier mechanism is exercised end-to-end
in unit tests but never engaged from production wiring.
- **Test evidence**:
- `go test -race ./adapter/... ./kv/... ./internal/raftengine/...`
targeting the encryption test surface — all pass.
- `golangci-lint --config=.golangci.yaml run` (pre-commit hook
fired during `git commit`) — 0 issues.
- New tests pin: barrier blocks `Propose` / allows
`ProposeAdmin`; `End` reopens `Propose`; `WaitDrained`
respects ctx; drain semantics under in-flight Propose; the
`ShardGroup` forwarder degraded fallback + production
delegation; the state machine refuses without barrier/applied-
index, drives the expected sequence, and runs `End` even on
propose error or drain timeout.
### Caller audit
- `ErrEnvelopeCutoverInProgress` is a new sentinel — no existing
`errors.Is` callers. The documented future caller
(`main_encryption_registration.go::RegisterEncryptionWriter`)
routes through `ProposeAdmin` and is barrier-exempt as designed
(comment at the call site already anticipated this).
- `raftEnvelopeWrapEnabled` const → var: production read sites
unchanged (one read in `EnableRaftEnvelope`); no callers
performed compile-time reasoning on the value. Tests
serialize their writes via `t.Cleanup`-based restore so the
parallel `TestEncryptionAdmin_EnableRaftEnvelope_GatedUntil6E2`
(which reads the var) observes the original `false` value
while paused at `t.Parallel()`.
### 5-lens self-review
1. **Data loss** — none. `ErrEnvelopeCutoverInProgress` returns
BEFORE `engine.Propose` so the entry was never accepted.
2. **Concurrency / distributed failures** — `barrierMu`
serializes (read-barrier, inc-counter) atomically with
(open-barrier, sample-counter); see the
`dynamicWrappedProposer` type comment for the race that
motivates a mutex over three atomics. Leader change mid-
cutover: the handler's `requireLeader` precheck guards the
entry; `ProposeAdmin` from a former leader returns
`NotLeader` / `LeadershipLost`, the deferred `End` fires, the
barrier closes, and the operator's retry restarts the
sequence on the new leader.
3. **Performance** — one `sync.Mutex` acquire+release per
`Propose` call (~50 ns), negligible vs Raft consensus
latency. No new metrics, no new Raft round-trips, no new
Pebble reads.
4. **Data consistency** — MVCC/OCC/HLC visibility unchanged.
HLC lease renewal (which calls `Propose`, not `ProposeAdmin`)
does observe the barrier; a single missed renewal tick
during the few-ms barrier window is within the existing
renewal tolerance (`hlcRenewalInterval = 1s`,
`hlcPhysicalWindowMs = 3s`). The `awaitCutoverApply` step-4
guarantees the cutover entry has been applied locally before
step-5 `InstallWrap` runs, closing the propose-side race
where the wrap closure could be installed before the engine
sees the cutover index.
5. **Test coverage** — six new tests in `kv/` covering the
barrier semantics; five new tests in `adapter/` covering the
state machine. The barrier-incapable fallback path is
covered alongside the production delegation path so a
regression that swapped one for the other surfaces
immediately.
## Test plan
- [x] `go test -race` on `adapter`, `kv`, `internal/raftengine`
(targeted encryption surface)
- [x] `golangci-lint run` clean
- [ ] Full `make test` in CI
- [ ] No Jepsen suite — barrier is unreachable from production
paths until 6E-2f flips the gate. Jepsen coverage will
attach to 6E-2f / Stage 9.7 files changed
Lines changed: 1598 additions & 8 deletions
File tree
- adapter
- docs/design
- internal/raftengine
- kv
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
26 | 40 | | |
27 | 41 | | |
28 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
134 | 142 | | |
135 | 143 | | |
136 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
137 | 173 | | |
138 | 174 | | |
139 | 175 | | |
| |||
174 | 210 | | |
175 | 211 | | |
176 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
177 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
178 | 231 | | |
179 | 232 | | |
180 | 233 | | |
| |||
186 | 239 | | |
187 | 240 | | |
188 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 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 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
189 | 426 | | |
190 | 427 | | |
191 | 428 | | |
| |||
0 commit comments