Commit 888e930
authored
subnet/etcd: unify the two subnet watch loops (#2539)
* subnet/etcd: unify the two subnet watch loops
watchSubnets and watchSubnet were near-identical copies of one reconnect
loop. That is why the compaction fix landed in the first (#2471) months
before the second (#2524): nothing connected them, so fixing one did not
even suggest the other.
Both now call a shared runWatch that owns the reconnect loop, backoff,
compaction recovery and revision bookkeeping. What genuinely differs
stays in a subnetWatch struct: the key, start revision, result channel
and resync callback.
The two response converters are unified too. Their apparent differences
were artifacts of copied code: the parser already sets EnableIPv4,
compaction is reported by the watch response rather than event parsing,
and cursor-only or empty results misrepresent parse failures as
snapshots. The shared converter skips malformed events, while TTL lookup
failures retry from the same revision instead of advancing past an
event.
watchSubnet picks up the resync retry loop watchSubnets already had.
Retry waits and result delivery honor context cancellation, so a blocked
receiver cannot keep the watch alive. Each per-attempt watch context is
also canceled before reconnecting rather than accumulating deferred
cleanup for the lifetime of the loop.
* subnet/etcd: give the two watch functions the same argument order
watchSubnets took (ctx, chan, since) while watchSubnet took (ctx, since,
sn, sn6, chan), so two adjacent functions in the same interface
disagreed about where the revision and the channel belong.
Both are now (ctx, since, [subnet], chan), which is watchSubnet's
existing shape, so only watchSubnets moves. Mechanical: the interface,
the mock, one caller in local_manager.go and two in the tests.1 parent cf7a72f commit 888e930
4 files changed
Lines changed: 211 additions & 221 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
355 | | - | |
| 355 | + | |
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| |||
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | 409 | | |
414 | 410 | | |
415 | 411 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
0 commit comments