Commit 12ec8ba
authored
feat(raftengine): Stage 6C-2c — encryptionScanner against etcdraft.MemoryStorage (#783)
## Summary
Stage 6C-2c per the [PR #762
plan](#762) and the 6C
sub-decomposition landed in [PR
#781](#781) / [PR
#782](#782).
Ships the **raftengine-side scanner** that implements the
`encryption.EncryptionRelevantScanner` interface defined in [PR #782
(Stage 6C-2b)](#782). The
`main.go` startup-guard wiring that ties this scanner to the
encryption-side guard is split into a new **6C-2d** sub-milestone per
the design doc update in this PR.
## What this PR ships
### `encryptionScanner` against `etcdraft.MemoryStorage`
```go
func (e *Engine) EncryptionScanner() encryption.EncryptionRelevantScanner
```
Walks `raftpb.Entry` rows in `(startExclusive, endInclusive]` via
`storage.Entries(lo, hi, scanMaxBytes)`, filters out:
- `EntryConfChange` / `EntryConfChangeV2` — config changes never carry
FSM payloads; their `Data[0]` could coincidentally fall in the
encryption opcode range without this gate
- Zero-length normal entries — etcd-raft leadership bumps after
election; would `panic: index out of range` on a naive `Data[0]` read
Returns `IsEncryptionRelevantOpcode(ent.Data[0])` over surviving entries
— i.e., asks whether any entry's opcode is in `[OpBootstrap,
OpEncryptionMax]` = `[0x04, 0x07]`. Note: **OpRegistration (0x03) is
correctly excluded** per the predicate's narrowed range from PR #782.
### Error semantics
| Path | Behavior |
|---|---|
| Compacted range (sidecar below snapshot horizon) | Wrapped
`ErrCompacted` propagated; caller routes as scanner-error refusal
**distinct** from `ErrSidecarBehindRaftLog` |
| `nil` storage (engine not opened) | Returns error rather than
nil-deref |
| Empty range | `(false, nil)` fast path; storage NOT consulted |
### Tests (8 cases covering every branch)
| Test | Pins |
|---|---|
| `EmptyRange` (3 sub-cases) | equal / start-ahead / both-zero — storage
never consulted |
| `NoRelevantEntries` | OpRegistration (0x03) explicitly NOT hit — pins
the PR #782 predicate narrowing end-to-end |
| `BootstrapHit` | OpBootstrap in range → hit |
| `RotationHit` | OpRotation in range → hit |
| `NonNormalEntriesSkipped` | ConfChange / ConfChangeV2 with `Data[0]`
in encryption range → NOT hit |
| `EmptyDataSkipped` | nil / empty `Data` → NOT hit AND no panic |
| `CompactedRange` | Snapshot at index 10, scan `[0, 5)` → error,
hit=false |
| `NilStorageError` | Zero-value scanner returns an error |
## Design doc updates
- **6C-2c** row rewritten to reflect the scanner-only scope of this PR
(engine implementation + `Engine.EncryptionScanner()` accessor, **no**
`main.go` wiring).
- **6C-2d** row added — `main.go` startup-guard phase that ties 6C-2b's
pure-function guard to 6C-2c's engine scanner. Will ship as its own PR.
- Shipping order updated: `6C-1 ✅ → 6C-2 ✅ → 6C-2b ✅ → 6C-2c (this PR) →
6C-2d → 6D (bundles 6C-3) → 6E (bundles 6C-4)`.
- Rationale section updated with the 6C-2c / 6C-2d split.
## Why split 6C-2c into "scanner" vs "wiring"
Keeping the engine scanner separate from the `main.go` wiring lets:
- Reviewers focus on one concern per PR.
- Stage 6D-and-later code paths that need the scanner (capability
fan-out gap-coverage check) depend on the engine package without waiting
for 6C-2d.
- 6C-2d's main.go integration touches the multi-shard lifecycle, which
is a different concern from the engine-internal scanner implementation
here.
## Caller audit
No public API changes outside `Engine.EncryptionScanner()`, which is
net-additive. `encryptionScanner` and `isEncryptionRelevantEntry` are
package-internal. No existing caller references the new accessor.
The implementation depends only on:
- `encryption.EncryptionRelevantScanner` (interface from PR #782)
- `encryption.IsEncryptionRelevantOpcode` (predicate from PR #782,
OpRegistration-excluded)
- `etcdraft.MemoryStorage.Entries` (existing engine internal)
- `raftpb.Entry` / `raftpb.EntryConfChange` / V2 (existing types)
No changes to the engine's apply path or any other lifecycle.
## Five-lens self-review
1. **Data loss** — net-positive. The scanner enables the §9.1 refusal
that catches partial-write crashes between an encryption-relevant Raft
commit and the sidecar update. Until 6C-2d wires the scanner into
main.go the scanner is operator-inert, but its failure modes
(compacted-range error, conf-change skip, empty-data skip, nil-storage
error) are all correct.
2. **Concurrency / distributed failures** — scanner reads from
`MemoryStorage` (thread-safe per etcd-raft contract). Scanner itself is
stateless.
3. **Performance** — zero hot-path impact. Called once per shard per
process start in 6C-2d, with at most one `Entries()` call in the typical
case (gap size << 64 MiB).
4. **Data consistency** — the scanner respects MemoryStorage's
compaction boundary: never silently returns "no hit" for a range below
the snapshot horizon; propagates the error so the guard routes it as a
distinct scanner-error refusal.
5. **Test coverage** — 8 tests cover all 6 predicate paths, all 2 filter
gates (type, length), AND the 2 error paths (compacted, nil-storage).
The OpRegistration exclusion is pinned end-to-end with a dedicated test
case.
## Test plan
- [x] `go test -race -timeout=120s ./internal/raftengine/etcd/...
./internal/encryption/...` — PASS
- [x] `golangci-lint run ./internal/raftengine/etcd/...` — 0 issues
- [ ] Full Jepsen suite — not run; scanner has no caller in this PR
(operator-inert until 6C-2d)
## Plan
Per the design doc updates in this PR, next sub-milestones:
- **6C-2d** — `main.go` startup-guard phase that calls
`encryption.GuardSidecarBehindRaftLog` with the scanner from this PR
- **6C-3** — `ErrNodeIDCollision` + `ErrLocalEpochRollback` (bundles
with Stage 6D)
- **6D** — `enable-storage-envelope` admin RPC + §7.1 Phase-1 cutover
(unblocked once 6C-2d lands)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Advances encryption-at-rest implementation with internal validation
mechanisms to ensure system consistency during startup.
* **Documentation**
* Updated design documentation clarifying the encryption-at-rest
implementation phases and dependency chain.
* **Tests**
* Added comprehensive test coverage for encryption validation logic,
including edge cases and error scenarios.
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/bootjp/elastickv/pull/783?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->3 files changed
Lines changed: 505 additions & 14 deletions
File tree
- docs/design
- internal/raftengine/etcd
Lines changed: 26 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
208 | 219 | | |
209 | 220 | | |
210 | 221 | | |
211 | 222 | | |
212 | | - | |
213 | | - | |
214 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
215 | 226 | | |
216 | 227 | | |
217 | 228 | | |
| |||
229 | 240 | | |
230 | 241 | | |
231 | 242 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
237 | 249 | | |
238 | 250 | | |
239 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 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 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
0 commit comments