Commit bce448f
authored
feat(sqs): partition resolver for HT-FIFO routing (Phase 3.D PR 4-B-2) (#715)
## Summary
Routing-layer half of PR 4-B. Adds a `PartitionResolver` that
`ShardRouter` consults BEFORE falling through to the byte-range engine.
SQS HT-FIFO needs partition-aware dispatch, but the engine's
non-overlapping-cover model can't express overlay routes — the
resolver-first dispatch sidesteps this cleanly.
Stacks on top of #708 (PR 4-B-1, capability JSON). Next is PR 4-B-3
(leadership-refusal + catalog polling + flip
`htfifoCapabilityAdvertised` to `true`).
## What's added
- `kv.PartitionResolver` interface — `ResolveGroup([]byte) (uint64,
bool)`.
- `kv.ShardRouter.WithPartitionResolver(...)` — fluent option, nil-safe.
- `kv.ShardRouter.resolveGroup(...)` — unified dispatch path: resolver
first, engine fallback. Both `groupRequests` (Commit/Abort) and `Get`
route through it.
- `kv.ShardedCoordinator.WithPartitionResolver(...)` — delegates to the
router so `main.go` can install via the existing fluent-construction
style.
- `adapter.SQSPartitionResolver` — parses `(queue, partition)` from the
partitioned key shape, looks up the operator-chosen group. Defensive
copy at construction, nil-safe `ResolveGroup`, returns `(0, false)` for
legacy / non-matching keys.
- `main.go` — builds the resolver from
`runtimeConfig.sqsFifoPartitionMap` and installs it. Resolver is `nil`
on a non-partitioned cluster — hot path stays engine-only.
## What's NOT added (deferred to PR 4-B-3)
- §8 leadership-refusal hook in `kv` (refuses leadership for an SQS Raft
group hosting a partitioned queue when the binary lacks `htfifo`).
- Catalog-polling helper for the CreateQueue capability gate (PR 5
starts using it).
- Flipping `htfifoCapabilityAdvertised` from `false` to `true`.
The design's "advertise htfifo only when both routing AND
leadership-refusal are in place" rule keeps the constant `false` in this
PR — PR 4-B-3 flips it.
## Test plan
- [x] `adapter/sqs_partition_resolver_test.go` — 9 top-level tests:
nil-on-empty, defensive-copy, partition dispatch across all 5 families,
queue-name prefix isolation (`"queue"` vs `"queue1"`), legacy
fall-through (8 sub-cases), unknown queue, out-of-range partition, nil
receiver, prefix alignment with `sqs_keys.go` constants.
- [x] `kv/shard_router_partition_test.go` — 4 tests: resolver wins over
engine, engine fallthrough on resolver-miss, nil resolver no-op, `Get`
path also routes through the resolver.
- [x] `go test -race ./kv/...` pass.
- [x] `go test -race ./adapter/...` pass.
- [x] `golangci-lint ./kv/... ./adapter/... .` clean.
## Self-review (per CLAUDE.md)
1. **Data loss** — routing layer only; no FSM/Pebble/retention path. No
issue.
2. **Concurrency** — `partitionResolver` is set once at startup before
any request. `ResolveGroup` reads a constructor-time defensive copy, so
a future hot-reload of `--sqsFifoPartitionMap` cannot perturb in-flight
requests. No issue.
3. **Performance** — one map lookup + 4-byte BigEndian decode per
resolver hit (only on partitioned-prefix matches). Engine-only path adds
a single `if s.partitionResolver != nil` branch. No issue.
4. **Data consistency** — resolver output strictly OVERRIDES the engine
for partitioned keys; legacy keys flow through unchanged. "queue not
found" / "partition out of range" branches return `(0, false)` so the
router surfaces an explicit error rather than silently mis-routing. No
issue.
5. **Test coverage** — 13 tests across two new files; existing
`TestShardRouter*` tests unchanged. Both override and fall-through paths
pinned, plus the queue-name prefix-isolation invariant from PR #703.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added partition-based routing for distributed coordination. Requests
are now directed to specific nodes based on configured partition
mappings.
* Enhanced SQS queue handling with optional partition-aware routing.
When partition information is unavailable or unconfigured, the system
automatically falls back to the existing routing mechanism.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->9 files changed
Lines changed: 1530 additions & 38 deletions
| 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