Commit 1dd9793
authored
refactor: implement fdv2 polling initializer / synchronizer (#519)
This implements the C++ polling initializer and synchronizer.
I have rewritten this code substantially since the first round of
reviews, mostly by hand.
Changes:
* Implements `FDv2PollingInitializer` and `FDv2PollingSynchronizer`.
* Updates the `IFDv2Initializer` and `IFDv2Synchronizer` interfaces to
be async.
* Makes it safe to `delete` both classes without joining any threads.
* Updates `AsioRequester::Request` to use a more modern style that is
more flexible in how it can be used.
* This will be needed for cancellation eventually anyway.
* Marks a method in `AsioRequester` as `const` to make it more obvious
that it's thread-safe.
* Adds a helper to create promisified ASIO timers.
* Adds some minor Promise helpers to simplify the new code.
Caveats:
* I have not yet implemented any kind of cancellation on async
operations. We should at least do this for timers at some point, but I'd
rather defer it to a later PR. It's no longer a deadlock or correctness
issue, but we _will_ get timeout timers slowly piling up in the
background if requests are fast.
Previous description:
> The bulk of this code was generated by Claude based on the Java
version, but I've gone through it line-by-line, and I think it makes
sense. But I'm new to both FDv2 and ASIO, so I could be missing
something.
>
> Probably the most controversial part is the decision from the previous
PR to use `std::future` and a blocking call. If we decide we need
Java-like conditions, or if we need the callers to be non-blocking, we
could change these to use `asio::deferred` instead. But I don't think
these changes require that yet.
>
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Introduces new FDv2 polling data path and converts FDv2 source
interfaces to `Future`-based async, which can affect orchestration flow
and lifecycle/shutdown behavior. Also changes the Boost.Asio HTTP
requester initiation style, so regressions could impact networking
behavior and timeouts.
>
> **Overview**
> Adds an **FDv2 polling implementation**: `FDv2PollingInitializer`
performs a one-shot poll, and `FDv2PollingSynchronizer` repeatedly polls
with minimum-interval enforcement and timeout/close handling using the
internal `Promise/Future` utilities.
>
> Introduces a shared `FDv2ProtocolHandler` state machine that
accumulates FDv2 wire events into a complete `FDv2ChangeSet` (or emits
typed protocol/JSON/server errors and `Goodbye`), with accompanying unit
tests.
>
> Refactors FDv2 source interfaces (`IFDv2Initializer::Run`,
`IFDv2Synchronizer::Next`) to return `async::Future<FDv2SourceResult>`
instead of blocking results, adds async helpers (`kInlineExecutor`,
`MakeFuture`, `async::Delay`), and updates
`AsioRequester::Request`/`Requester::Request` to be `const` and use
`boost::asio::async_initiate`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
4b02b67. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 4b40bb4 commit 1dd9793
19 files changed
Lines changed: 1597 additions & 65 deletions
File tree
- libs
- internal
- include/launchdarkly
- async
- network
- src
- network
- tests
- server-sdk/src
- data_interfaces/source
- data_systems/fdv2
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
440 | 444 | | |
441 | 445 | | |
442 | 446 | | |
| |||
528 | 532 | | |
529 | 533 | | |
530 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
531 | 547 | | |
| 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 | + | |
Lines changed: 114 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 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
Lines changed: 13 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
302 | 296 | | |
303 | 297 | | |
304 | 298 | | |
| |||
313 | 307 | | |
314 | 308 | | |
315 | 309 | | |
316 | | - | |
| 310 | + | |
317 | 311 | | |
318 | 312 | | |
319 | 313 | | |
| |||
336 | 330 | | |
337 | 331 | | |
338 | 332 | | |
339 | | - | |
| 333 | + | |
340 | 334 | | |
341 | 335 | | |
342 | 336 | | |
| |||
Lines changed: 16 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | | - | |
25 | | - | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | | - | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | | - | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
0 commit comments