Commit 64b98e3
authored
refactor(fdv2): add server FDv2 heuristic fallback and recovery (#531)
## Summary
Heuristic FDv2 fallback (interrupted ≥ 2 min) and recovery (valid ≥ 5
min) for the server SDK, modeled on Java's event-driven `Condition`
design. The orchestrator races a condition future against
`synchronizer.Next()`; whichever resolves first wins. Synchronizer
rotation is cyclic with `Available`/`Blocked` state, mirroring Java's
`SourceManager`.
## What's in
- `IFDv2Condition` + concrete `FallbackCondition` / `RecoveryCondition`
with internal timers and an `Inform` / `Execute` interface.
- `Conditions` aggregator over multiple conditions, built on a new
`async::WhenAny` vector overload.
- `SourceManager` owns the synchronizer factory list with per-factory
`Available`/`Blocked` state. Iteration is cyclic (wraps + skips
blocked). `BlockCurrentSynchronizer` on `TerminalError`;
`ResetSourceIndex` on recovery.
- `FDv2DataSystem` builds conditions keyed off
`AvailableSynchronizerCount`/`IsPrimeSynchronizer` (no conditions if
only one available; prime gets fallback only; others get fallback +
recovery).
- Drops the `timeout` argument from `IFDv2Synchronizer::Next()` and
removes the unreachable `FDv2SourceResult::Timeout` variant.
## Deferred to future PRs
- FDv1 fallback directive (`X-LD-FD-Fallback` response header) —
server-driven, one-way switch to an FDv1 synchronizer.
- FDv1 synchronizer adapter wrapping the existing FDv1 sources as
`IFDv2Synchronizer`.
- Most of the spec's orchestration-logging requirements.
## Test plan
Unit tests for each new component and integration tests for fallback
advance, wrap-around on last synchronizer, recovery reset, and
exhaustion via
block.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes FDv2 orchestration and synchronizer interfaces (removing
`Next()` timeouts/`Timeout` results) while introducing timer-driven
fallback/recovery and cyclic source rotation, which could affect update
reliability and shutdown behavior.
>
> **Overview**
> Adds a new FDv2 *condition* abstraction (`IFDv2Condition`) with timed
`FallbackCondition`/`RecoveryCondition` implementations plus a
`Conditions` aggregator that races condition futures against
`synchronizer.Next()` to trigger source transitions.
>
> Refactors FDv2 synchronizer rotation into a new `SourceManager` that
cycles through synchronizer factories, skips blocked sources, blocks on
`TerminalError`, and resets to the most-preferred source on recovery.
>
> Removes FDv2 per-`Next()` timeouts by dropping the timeout parameter
from `IFDv2Synchronizer::Next()` and deleting the
`FDv2SourceResult::Timeout` variant; updates polling/streaming
synchronizers and tests accordingly. Also adds a vector overload of
`async::WhenAny` and comprehensive unit/integration tests for the new
rotation and condition behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1f7f26e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 261ba85 commit 64b98e3
20 files changed
Lines changed: 1669 additions & 287 deletions
File tree
- libs
- internal
- include/launchdarkly/async
- tests
- server-sdk
- src
- data_interfaces/source
- data_systems/fdv2
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
537 | 561 | | |
538 | 562 | | |
539 | 563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
419 | 447 | | |
420 | 448 | | |
421 | 449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
Lines changed: 2 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 59 | + | |
| 60 | + | |
70 | 61 | | |
71 | 62 | | |
72 | 63 | | |
| |||
Lines changed: 107 additions & 0 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 | + | |
Lines changed: 2 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | | - | |
| 22 | + | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | 28 | | |
34 | 29 | | |
35 | 30 | | |
36 | | - | |
37 | 31 | | |
38 | 32 | | |
39 | 33 | | |
40 | 34 | | |
41 | | - | |
42 | 35 | | |
43 | 36 | | |
44 | 37 | | |
| |||
0 commit comments