Repository navigation
feat: Let each data source decide whether FDv2 writes its data to a persistent store - #389
Conversation
…ersistent store The FDv2 data system wrote the data of every initializer and synchronizer to a persistent store in read-write mode, and wrote the memory store back after a store outage. The data system spec requires each source to state whether its data is persisted (requirements 1.1.7 and 1.2.8), so that, for example, file data does not replace the LaunchDarkly data in a shared store. Change sets and full data sets now carry an internal persist flag. The write- through store writes a change set to the persistent store only if the flag is set, the memory store remembers the flag of the data it holds, and store recovery leaves the persistent store as it is when the memory store holds data that must not be persisted. An FDv1-style source states its flag on its configurer, and the data system applies it to the source's full data sets and upserts alike: - The file data source is not persisted by default. FileDataSourceBuilder. ShouldPersist(true) opts in. - TestData is persisted by default, as before. TestData.ShouldPersist(false) opts out, and covers later updates as well as the initial data. - FDv2 polling and streaming, the FDv1 fallback synchronizer, and custom data sources are persisted, as before. The FDv1 data system is unchanged: its data store receives all data.
|
bugbot review |
1 similar comment
|
bugbot review |
The transactional persistent store spec (requirement 1.4.3.2) has the data system track a single, most recent persistence indicator, and requires the write back whenever that indicator allows it (requirement 1.4.3). The memory store let a partial payload only clear its flag, so a persisted delta on a basis that was not persisted would have skipped the write back. Use the flag of the latest change set, as the spec, Java and Go do.
… wraps theirs The data system read the persistence flag only from the configurer it was given, so an application configurer that delegates to FileData.DataSource() made file data persisted again. The file and test data sources now also put the flag on the full data sets they deliver. The adapter persists a full data set only if both its configurer and the data set allow it, and an upsert takes the flag of the last full data set, the data it changes. Also from the review of this change: - The TestData docs said a change to ShouldPersist applies to clients created after it. The data system reads it each time it starts the source, which a running client also does. - The mixed-sequence test now checks the store's Init count: the mock store's Init replaces all its data, so the old assertion could not fail. - WriteThroughStore.Upsert says why it ignores the flag, the recovery skip is logged at Info, and the read-write mode docs name the FDv1 fallback, custom data sources and the write back after an outage.
|
bugbot review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 982d5c9. Configure here.
| fdv1Fallback); | ||
| fdv1Fallback, | ||
| // LaunchDarkly data is always persisted. | ||
| shouldPersist: true); |
There was a problem hiding this comment.
I'm confused how this can be hardcoded but things that don't implement IDataSourcePersistence will have persist = false.
There was a problem hiding this comment.
This reply was written by an AI agent (Claude Code) working on behalf of @kinyoklion.
A source whose configurer does not implement IDataSourcePersistence is persisted: the check in FDv2DataSystem.ToSourceFactory is !(dataSourceFactory is IDataSourcePersistence persistence) || persistence.ShouldPersist. Only the file data source and test data configurers implement it, and they default to not persisting. That check covers sources that write through DataSourceUpdatesV2ToV1Adapter's Init/Upsert; FDv2 change sets pass through it unchanged, so for the FDv2 streaming and polling sources the value on the change set is the only control.
That value was hardcoded here. As of ce030b4, ToChangeSet takes shouldPersist as a required argument and the streaming and polling sources pass true at their call sites, so the declaration sits with the source rather than in the translation (7f88e38 makes the same change on #390).
| return (sink) => | ||
| dataSourceFactory.Build(clientContext.WithDataSourceUpdates(new DataSourceUpdatesV2ToV1Adapter(sink))); | ||
| { | ||
| var shouldPersist = !(dataSourceFactory is IDataSourcePersistence persistence) || |
There was a problem hiding this comment.
Is there an obvious argument for doing it this way and not the inverse? The inverse being a sources not implementing the interface defaults to persist and sources must implement and opt out of persist?
There was a problem hiding this comment.
This reply was written by an AI agent (Claude Code) working on behalf of @kinyoklion.
The code is that inverse: a configurer that does not implement IDataSourcePersistence is persisted, and a source opts out by implementing it. The file data source and test data implement it and default to ShouldPersist(false).
The reason is in the data system spec. DATASYSTEM v2 Requirement 1.1.7 says initializers MUST indicate whether data persistence is requested via the persist field of a returned Basis, and Requirement 1.2.8 says the same of synchronizers for a Basis or a Delta. The motivation under 1.1.7 is that not all data should be mirrored to a persistent store, only data that is "trusted" or "authoritative", and its examples are a file initializer that sets persist = false and a polling initializer that sets persist = true.
So the sources that carry local, non-authoritative data declare that they do not persist: the file data source, which the spec names, and test data, which is local data of the same kind. Everything else keeps persisting without having to declare anything: the FDv2 streaming and polling sources, the FDv1 fallback synchronizer, whose data also comes from LaunchDarkly, and a custom data source written against the existing IDataSource API, whose data the SDK always wrote to the store before this change. Defaulting the other way would make each of those opt in, and a custom source that predates the interface would silently stop being persisted.
| environmentId, | ||
| fdv1Fallback); | ||
| fdv1Fallback, | ||
| // LaunchDarkly data is always persisted. |
There was a problem hiding this comment.
AI review comment: This comment gives an origin-based rationale, but the rule this PR implements is per-source declaration — "LaunchDarkly data" isn't the criterion anywhere else (the FDv1 fallback's data is also from LaunchDarkly and persists via a different mechanism, the configurer default in ToSourceFactory).
The hardcoded true is doing more work than the comment suggests: DataSourceUpdatesV2ToV1Adapter.Apply passes change sets through untouched, so on the direct-apply path this value is the only persistence control. A future FDv2-native source that reuses this translator would silently persist its data, and the factory-level IDataSourcePersistence check wouldn't catch it.
Java's translator takes shouldPersist as a parameter, and the streaming/polling sources pass true at their call sites. Suggest mirroring that here — the method already takes caller context (environmentId, fdv1Fallback) — or at minimum rewording to the mechanism-accurate reason: the only users of this translator are the LaunchDarkly streaming and polling sources, which always permit persistence per spec requirements 1.1.7/1.2.8; the flag is those sources' declaration, not a property of the translation.
There was a problem hiding this comment.
This reply was written by an AI agent (Claude Code) working on behalf of @kinyoklion.
Changed as suggested in ce030b4 (and 7f88e38 on #390). FDv2ChangeSetTranslator.ToChangeSet takes shouldPersist as a required argument, as Java's translator does, and the streaming and polling sources pass true where they call it, with a comment that cites DATASYSTEM 1.1.7 and 1.2.8. The translator's own comment is gone, and its doc says the value is the calling source's declaration and the only persistence control for FDv2 change sets. A new translator test checks that both values pass through; the existing streaming and polling tests assert ShouldPersist and fail if either call site passes false.
… the calling source The translator marked every change set it produced as persistable, a decision that belongs to the source. The data system applies FDv2 change sets as they are, so for those sources the value is the only persistence control, and a future source that reused the translator would have persisted its data without declaring it. ToChangeSet now takes shouldPersist as a required argument, and the streaming and polling sources pass true at their call sites, as Java's translator does.
<!-- TERMAG_PR_BODY_BEGIN --> ## Summary The server SDK's contract test service had no persistent store support: the data system store configuration in `SdkClientEntity.cs` was commented out with a TODO about the store packages, and the FDv1 `persistentDataStore` configuration was not handled. CI therefore ran both harness versions with `enable_persistence_tests: 'false'`. This change makes the service drive real Redis, DynamoDB, and Consul stores and runs the persistence suites in CI. It is separate from the persistence fix in #390 (and #389 on `main`), which these tests do not cover yet; the harness gains tests for that behavior in a separate change. ## Test service - The FDv2 `dataSystem.store` and `storeMode` configuration (harness v3) and the FDv1 top-level `persistentDataStore` configuration (harness v2) build the store with `Components.PersistentDataStore`, with the requested prefix and cache mode. - An FDv1 configuration with a store and no streaming, polling, or service endpoint configuration runs in daemon mode (`Components.ExternalUpdatesOnly`), which the v2 suite expects. Without this, the client tried to reach LaunchDarkly and failed to initialize. - An empty prefix means the store's default prefix, and a store configuration without a DSN is rejected. - The Redis and DynamoDB clients fail fast (500 ms timeouts, no DynamoDB retries), as the store recovery tests require. The Consul client does not retry. - The service advertises `persistent-data-store-redis`, `persistent-data-store-dynamodb`, `persistent-data-store-consul`, and `persistent-data-store-recovery`. - The service already takes its port as an optional first argument; CI now passes one. Its default stays 8000. ### Building against the local SDK The store projects in `pkgs/` reference the published `LaunchDarkly.ServerSdk` package, so a reference to them would bring a second copy of the SDK into the service. Instead, a small project per store under `contract-tests/Stores/` compiles that store's sources against the SDK project, with the same client library and version range as the store's own project. There is one project per store because the Redis and DynamoDB stores share internal type names. The store projects themselves are not changed, and neither are their packages or their builds. On this branch the SDK is 9.0.0-alpha, outside the stores' published range (`[8.0.0, 9.0.0)`); the stores build and pass against it from their sources. ## CI - `.github/actions/contract-tests` gains `enable_persistence_tests` (default `false`) and `test_service_port` (default `8000`). With persistence enabled, it starts the stores with `launchdarkly/gh-actions/actions/persistent-stores`, waits until they accept connections and Consul has a leader, and enables the tests in both harness runs. - The server SDK workflow enables the persistence tests on the Linux runner only, where the stores start in Docker, and passes port 9000 on every runner: the harness expects DynamoDB on port 8000, the service's default. The client SDK workflow uses the same action with the default port, because its test service always listens on 8000. ## Suppressed tests The persistence suites found three pre-existing defects in the store integrations. They are suppressed with a comment in each suppression file. The harness reads every non-blank line as a test ID, so a line that starts with `#` matches no test. 1. A deleted flag is stored without a `"key"` property: `{"version":N,"deleted":true}`, from the `ItemDescriptor` serializer in `DataStoreTypes.cs` (Redis and Consul store that string), or as the placeholder `"null"` in the item attribute (`DynamoDBDataStoreImpl.MarshalItem`). The harness expects a JSON tombstone with a `key` property, the item key or `$deleted`. This fails `read-write/data source deletions respect versioning` for each store (both harness versions) and, in v3, the five store recovery tests that check a deleted flag after the write back. With a one-line serializer change that writes `"key": "$deleted"`, the Redis and Consul tests pass, and the recovery write back itself works; DynamoDB needs its own fix. 2. `ConsulDataStoreImpl.GetAllAsync` iterates `result.Response`, which is null when no key has the collection's prefix, so reading an empty collection throws. This fails `collection cardinality/collection holds no flags` for Consul. These need SDK and store changes, which this PR does not make. For the keyless tombstone, the v3 harness's own tombstone suite lists `{"version":N,"deleted":true}` as a shape that .NET, Java, and Node write and that readers must accept, so for Redis and Consul the fix may belong in the harness's read-write matcher instead. DynamoDB's `"null"` placeholder is not one of the accepted shapes. Until one of these lands, CI does not check the store write back after recovery or the store side of deletions for any store; the only recovery test that runs checks evaluations from memory during the outage. ## Testing With Redis, DynamoDB local, and Consul running in Docker on their default ports: - Harness v2 (2.41.1), full suite with persistence enabled and the suppression file: all tests passed (4989 ran). - Harness v3 (3.2.0-alpha.15, from `v3` at 58f4122), full suite with persistence enabled and the FDv2 suppression file: all tests passed (5174 ran). Without the suppressions, the persistence suites fail exactly the tests listed above (4 in v2, 19 in v3). After the review changes (the store projects, the port default, the readiness wait), both persistence suites pass again with the suppressions (v3: 141 ran; v2: 111 ran), and `LaunchDarkly.ServerSdk.sln` builds with no errors. This is the `dotnet-server-sdk-v9` version of #391. <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=Overrides --> <sub>Opened from termag</sub> [SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Enables the SDK test harness’s persistent-store suites in CI** by wiring the contract test service to real Redis, DynamoDB, and Consul integrations and extending the shared contract-test GitHub Action. > > The contract test service now maps harness **FDv1 `persistentDataStore`** and **FDv2 `dataSystem.store`** into `Components.PersistentDataStore` (Redis, DynamoDB, Consul) with prefix/cache options, **500 ms fail-fast** client settings for recovery tests, and **daemon mode** (`ExternalUpdatesOnly`) when a store is configured without streaming/polling. It advertises the new persistence capabilities. **Wrapper projects under `Stores/`** compile each integration’s sources against the in-repo SDK so CI does not pull a second published SDK copy. > > **CI:** `enable_persistence_tests` and `test_service_port` are plumbed through the composite action; when enabled it starts stores, waits on ports **6379/8000/8500** and Consul leadership, and launches the service on a non-8000 port (DynamoDB local uses 8000). **Server SDK workflow** turns persistence on **Linux only** and uses port **9000**. > > **Known integration gaps** are temporarily **skipped** via suppression entries (deletion tombstone shape without `"key"`, DynamoDB `"null"` deletes, Consul empty collection reads)—CI still runs the rest of the persistence suites. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8f77f3f. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> [SDK-3493]: https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- TERMAG_PR_BODY_BEGIN --> ## Summary The server SDK's contract test service had no persistent store support: the data system store configuration in `SdkClientEntity.cs` was commented out with a TODO about the store packages, and the FDv1 `persistentDataStore` configuration was not handled. CI therefore ran both harness versions with `enable_persistence_tests: 'false'`. This change makes the service drive real Redis, DynamoDB, and Consul stores and runs the persistence suites in CI. It is separate from the persistence fix in #389 (and #390 on `dotnet-server-sdk-v9`), which these tests do not cover yet; the harness gains tests for that behavior in a separate change. ## Test service - The FDv2 `dataSystem.store` and `storeMode` configuration (harness v3) and the FDv1 top-level `persistentDataStore` configuration (harness v2) build the store with `Components.PersistentDataStore`, with the requested prefix and cache mode. - An FDv1 configuration with a store and no streaming, polling, or service endpoint configuration runs in daemon mode (`Components.ExternalUpdatesOnly`), which the v2 suite expects. Without this, the client tried to reach LaunchDarkly and failed to initialize. - An empty prefix means the store's default prefix, and a store configuration without a DSN is rejected. - The Redis and DynamoDB clients fail fast (500 ms timeouts, no DynamoDB retries), as the store recovery tests require. The Consul client does not retry. - The service advertises `persistent-data-store-redis`, `persistent-data-store-dynamodb`, `persistent-data-store-consul`, and `persistent-data-store-recovery`. - The service takes its port as an optional first argument, as on `dotnet-server-sdk-v9`. Its default stays 8000. ### Building against the local SDK The store projects in `pkgs/` reference the published `LaunchDarkly.ServerSdk` package, so a reference to them would bring a second copy of the SDK into the service. Instead, a small project per store under `contract-tests/Stores/` compiles that store's sources against the SDK project, with the same client library and version range as the store's own project. There is one project per store because the Redis and DynamoDB stores share internal type names. The store projects themselves are not changed, and neither are their packages or their builds. ## CI - `.github/actions/contract-tests` gains `enable_persistence_tests` (default `false`) and `test_service_port` (default `8000`). With persistence enabled, it starts the stores with `launchdarkly/gh-actions/actions/persistent-stores`, waits until they accept connections and Consul has a leader, and enables the tests in both harness runs. - The server SDK workflow enables the persistence tests on the Linux runner only, where the stores start in Docker, and passes port 9000 on every runner: the harness expects DynamoDB on port 8000, the service's default. The client SDK workflow uses the same action with the default port, because its test service always listens on 8000. - The nightly enables them too, also with port 9000. ## Suppressed tests The persistence suites found three pre-existing defects in the store integrations. They are suppressed with a comment in each suppression file. The harness reads every non-blank line as a test ID, so a line that starts with `#` matches no test. 1. A deleted flag is stored without a `"key"` property: `{"version":N,"deleted":true}`, from the `ItemDescriptor` serializer in `DataStoreTypes.cs` (Redis and Consul store that string), or as the placeholder `"null"` in the item attribute (`DynamoDBDataStoreImpl.MarshalItem`). The harness expects a JSON tombstone with a `key` property, the item key or `$deleted`. This fails `read-write/data source deletions respect versioning` for each store (both harness versions) and, in v3, the five store recovery tests that check a deleted flag after the write back. With a one-line serializer change that writes `"key": "$deleted"`, the Redis and Consul tests pass, and the recovery write back itself works; DynamoDB needs its own fix. 2. `ConsulDataStoreImpl.GetAllAsync` iterates `result.Response`, which is null when no key has the collection's prefix, so reading an empty collection throws. This fails `collection cardinality/collection holds no flags` for Consul. These need SDK and store changes, which this PR does not make. For the keyless tombstone, the v3 harness's own tombstone suite lists `{"version":N,"deleted":true}` as a shape that .NET, Java, and Node write and that readers must accept, so for Redis and Consul the fix may belong in the harness's read-write matcher instead. DynamoDB's `"null"` placeholder is not one of the accepted shapes. Until one of these lands, CI does not check the store write back after recovery or the store side of deletions for any store; the only recovery test that runs checks evaluations from memory during the outage. ## Testing With Redis, DynamoDB local, and Consul running in Docker on their default ports: - Harness v2 (2.41.1), full suite with persistence enabled and the suppression file: all tests passed (4989 ran). - Harness v3 (3.2.0-alpha.15, from `v3` at 58f4122), full suite with persistence enabled and the FDv2 suppression file: all tests passed (5095 ran). - After moving the port to the first argument: both persistence suites with the service on port 9000 passed. Without the suppressions, the persistence suites fail exactly the tests listed above (4 in v2, 19 in v3). After the review changes (the store projects, the port default, the readiness wait), both persistence suites pass again with the suppressions (v3: 141 ran; v2: 111 ran), and `LaunchDarkly.ServerSdk.sln` builds with no errors. #392 makes the same change on `dotnet-server-sdk-v9`. <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=Overrides --> <sub>Opened from termag</sub> [SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Enables **persistent store contract tests** in CI by wiring the server SDK contract test service to real Redis, DynamoDB, and Consul, and turning those suites on in GitHub Actions. > > The contract test service now builds Redis, DynamoDB, and Consul integrations from in-repo sources (via `Stores/*` wrapper projects) against the local SDK, implements `CreatePersistentDataStore` for harness FDv1 `persistentDataStore` and FDv2 `dataSystem.store`, supports **daemon mode** when a store is configured without streaming/polling, advertises the new store capabilities, and accepts an **optional listen port** (9000 in CI so DynamoDB can use 8000). Store clients use short timeouts for recovery tests. > > The **contract-tests** composite action gains `enable_persistence_tests` and `test_service_port`, starts stores and waits for readiness when enabled, and forwards those flags to both harness runs. **sdk-server-ci** runs persistence tests on Linux only; **nightly** always enables them with port 9000. > > Known failures from **pre-existing tombstone / empty-collection bugs** in the store integrations are listed in `test-supressions*.txt` so CI stays green until separate fixes land. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit fd9c0d6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> [SDK-3493]: https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ersistent store (#390) <!-- TERMAG_PR_BODY_BEGIN --> ## Summary In the FDv2 data system with a persistent store in read-write mode, the SDK wrote the data of every initializer and synchronizer to the store, and wrote all of the memory store back to it after an outage. A file data source used as an initializer or synchronizer therefore replaced the LaunchDarkly data in a shared Redis, DynamoDB, or Consul store, on start, on every reload, and again on every store recovery. The data system spec requires each data source to say whether its data may be persisted, and the SDK to mirror only that data: requirement 1.1.7 for initializers and 1.2.8 for synchronizers (`specs/DATASYSTEM-data-system/v2/README.md`). Its example is the file initializer, which does not persist. The decision is not based on the payload selector, because the FDv1 fallback synchronizer has no selector and its data must still be persisted (the spec's definition of a basis notes that neither a file data source nor the FDv1 fallback synchronizer can provide one). The Java SDK is the complete reference implementation, and this change follows its design, with one difference described below. ## How it works - `ChangeSet` and `FullDataSet` carry an internal persist flag. It is stored inverted, so that a defaulted struct, or one built with an existing constructor, means "persist". The public API of both types is unchanged. - `WriteThroughStore` writes a full data set or a change set to the persistent store only if its flag is set. Data that is not persisted still goes to the memory store, which becomes the store that evaluations read from, as before. - `InMemoryDataStore` remembers the flag of the latest full or partial change set and returns it from `ExportAll`. Like the transactional persistent store spec (requirement 1.4.3.2), it tracks a single, most recent indicator, not one per item. - `PersistentStoreWrapper.PollAvailabilityAfterOutage` skips the write when the exported data must not be persisted. The store still reports that it has recovered, and keeps its contents. - `DataStoreSorter` keeps the flag when it sorts a data set or change set. ### How a data source states its flag FDv2 polling and streaming declare that their data may be persisted when they translate a change set: `FDv2ChangeSetTranslator.ToChangeSet` takes the flag as a required argument, as Java's translator does, and both sources pass `true`. The data system applies FDv2 change sets as they are, so that argument is the only persistence control for them. Every other source is an FDv1-style source run through `DataSourceUpdatesV2ToV1Adapter`. An FDv1 `Upsert` call has no data set that could carry a flag. So the data system reads the flag from the source's configurer each time it builds the source, through the internal interface `IDataSourcePersistence`, and gives it to the adapter. A configurer that does not implement the interface is persisted. The file and test data sources also put the flag on the full data sets they deliver, so that their data stays out of the store when an application's own configurer wraps theirs and hides the interface. The adapter persists a full data set only if both the configurer and the data set allow it, and an upsert takes the flag of the last full data set, the data it changes. This is where the change differs from Java. Java's adapter copies the flag from the full data set but always sets it on upserts, so a Java `TestData` configured with `shouldPersist(false)` keeps its initial data out of the store but writes every later update to it. After one update the memory store's flag says "persist", so the next store recovery writes the initial data as well. ### Defaults | Source | Persisted | |---|---| | FDv2 polling and streaming | yes | | FDv1 fallback synchronizer (`DataSystemComponents.FDv1Polling()`) | yes | | A custom data source | yes, as before | | `FileData.DataSource()` | no; `FileDataSourceBuilder.ShouldPersist(true)` opts in | | `TestData` | no; `TestData.ShouldPersist(true)` opts in. Before this change, it was persisted. | The FDv1 data system is unchanged: its data store, persistent or not, receives all data, including the file data source's. The flag is read only by the FDv2 data system. ### Mixed sequences - A file initializer followed by a persisted synchronizer's basis: the basis is written to the store and replaces whatever the store held, and a recovery after it writes the memory store. - A delta whose flag differs from the basis it applies to: the write-through store writes or skips each change set by its own flag, and recovery follows the flag of the latest change set, as the spec says. A persisted delta can only follow a basis that was not persisted if a source sends a delta without a basis of its own. A file source never sends deltas, `TestData` starts with a full data set, and an FDv2 synchronizer that follows a basis without a selector (the file and test data sources provide none) requests a full transfer. ## Testing - `FDv2DataSystemPersistenceTest` runs real clients against a mock persistent store, for each case: - A file initializer is not written. - A file synchronizer's reload is not written. - File data with `ShouldPersist(true)` is written. - `TestData` is written neither for its initial data nor for an update by default. - `TestData` with `ShouldPersist(true)` is written, initial data and updates. - A custom FDv1-style data source is written. - The FDv1 fallback synchronizer's data is written. - A persisted synchronizer basis after a file initializer is written, and the file data is not; the store's `Init` count shows it, because the mock store's `Init` replaces all of its data. - A file data source or `TestData` behind an application's own wrapping configurer is not written. - The FDv1 data system with a file data source still writes to the store. - Unit tests for the write-through store, the memory store's flag of the latest change set, recovery with data that must not be persisted and with persisted data that replaced it, the adapter, the sorter, and the flag on FDv2 polling and streaming change sets. - To check that the tests detect the defects they target, each of thirteen parts of the fix was reverted on its own, and every reversion failed at least one test: - The write-through check. - The adapter's upsert flag, reverted to Java's behavior. - The recovery skip. - The memory store's flag for partial payloads. - Reading the configurer's flag. - The sorter. - The `TestData` flag. - The file data default. - The flag on the file data source's data set. - The flag on `TestData`'s data set. - The adapter's use of the data set's flag. - The upsert's use of the last data set's flag. - The memory store's update of the flag on a partial payload. - The full server SDK test suite passes on net8.0 (2012 tests on this branch). The SDK builds for netstandard2.0, net462, and net8.0. The contract tests do not cover this. The harness persistence suites have no test of file or test data, and this repository runs them with `enable_persistence_tests: 'false'`; the contract test service has no persistent store support. A separate change enables them, and the harness gains tests of these cases. This is the `dotnet-server-sdk-v9` version of #389. It differs only in the `TestData` default: on `main`, `TestData` stays persisted by default and `ShouldPersist(false)` opts out; for the next major version it is not persisted by default, like the file data source. The file data source builder conflicts with the shared file data engine from #376 only in its using directives, in where the new method sits, and in where the file data source builds its data set. ## Found in review, not changed here A multi-agent review of this change found three gaps in code it does not change. Java has the same three: - TXNS 1.4.3.1: with an infinite cache TTL, a store recovery before the first payload takes the cache-based branch of `PollAvailabilityAfterOutage` and writes an empty data set. Consul's `Init` deletes every key under the prefix that is not in the data, so this empties a shared Consul store. - TXNS 1.3.5: when a shared store rejects a delta item because it already holds that version or a newer one, `WriteThroughStore` stops applying the rest of the delta and throws, so the SDK reports a store error and skips the flag change events. - TXNS 1.4.3.3: the recovery write back is not serialized with concurrent updates, so a newer item that this SDK writes during it can be replaced by the older snapshot. <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=dotnet-core --> <sub>Opened from termag</sub> [SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493) [SDK-3493]: https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > The FDv2 data system now honors each data source’s **persist** decision instead of writing every initializer/synchronizer payload (and post-outage memory snapshots) into a read-write persistent store. **File** and **TestData** default to **not** persisting; LaunchDarkly streaming/polling, FDv1 fallback, and custom sources still persist unless they opt out. > > **`ChangeSet`** and **`FullDataSet`** carry an internal **`ShouldPersist`** flag. **`WriteThroughStore`** and **`PersistentStoreWrapper`** skip persistent writes and recovery sync when that flag is false. **`IDataSourcePersistence`** on configurers plus flags on file/test payloads (and **`DataSourceUpdatesV2ToV1Adapter`** logic) set the flag end-to-end; **`FileDataSourceBuilder.ShouldPersist`** and **`TestData.ShouldPersist`** opt in explicitly. > > Contract-test support adds file/test data synchronizers, **`updateTestData`**, and capabilities **`file-data-source`**, **`test-data-source`**, **`data-source-persist-opt-in`**. Broad unit/integration tests cover stores, recovery, and mixed initializer/synchronizer sequences. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ad54619. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
Summary
In the FDv2 data system with a persistent store in read-write mode, the SDK wrote the data of every initializer and synchronizer to the store, and wrote all of the memory store back to it after an outage. A file data source used as an initializer or synchronizer therefore replaced the LaunchDarkly data in a shared Redis, DynamoDB, or Consul store, on start, on every reload, and again on every store recovery.
The data system spec requires each data source to say whether its data may be persisted, and the SDK to mirror only that data: requirement 1.1.7 for initializers and 1.2.8 for synchronizers (
specs/DATASYSTEM-data-system/v2/README.md). Its example is the file initializer, which does not persist. The decision is not based on the payload selector, because the FDv1 fallback synchronizer has no selector and its data must still be persisted (the spec's definition of a basis notes that neither a file data source nor the FDv1 fallback synchronizer can provide one).The Java SDK is the complete reference implementation, and this change follows its design, with one difference described below.
How it works
ChangeSetandFullDataSetcarry an internal persist flag. It is stored inverted, so that a defaulted struct, or one built with an existing constructor, means "persist". The public API of both types is unchanged.WriteThroughStorewrites a full data set or a change set to the persistent store only if its flag is set. Data that is not persisted still goes to the memory store, which becomes the store that evaluations read from, as before.InMemoryDataStoreremembers the flag of the latest full or partial change set and returns it fromExportAll. Like the transactional persistent store spec (requirement 1.4.3.2), it tracks a single, most recent indicator, not one per item.PersistentStoreWrapper.PollAvailabilityAfterOutageskips the write when the exported data must not be persisted. The store still reports that it has recovered, and keeps its contents.DataStoreSorterkeeps the flag when it sorts a data set or change set.How a data source states its flag
FDv2 polling and streaming declare that their data may be persisted when they translate a change set:
FDv2ChangeSetTranslator.ToChangeSettakes the flag as a required argument, as Java's translator does, and both sources passtrue. The data system applies FDv2 change sets as they are, so that argument is the only persistence control for them.Every other source is an FDv1-style source run through
DataSourceUpdatesV2ToV1Adapter. An FDv1Upsertcall has no data set that could carry a flag. So the data system reads the flag from the source's configurer each time it builds the source, through the internal interfaceIDataSourcePersistence, and gives it to the adapter. A configurer that does not implement the interface is persisted.The file and test data sources also put the flag on the full data sets they deliver, so that their data stays out of the store when an application's own configurer wraps theirs and hides the interface. The adapter persists a full data set only if both the configurer and the data set allow it, and an upsert takes the flag of the last full data set, the data it changes.
This is where the change differs from Java. Java's adapter copies the flag from the full data set but always sets it on upserts, so a Java
TestDataconfigured withshouldPersist(false)keeps its initial data out of the store but writes every later update to it. After one update the memory store's flag says "persist", so the next store recovery writes the initial data as well.Defaults
DataSystemComponents.FDv1Polling())FileData.DataSource()FileDataSourceBuilder.ShouldPersist(true)opts inTestDataTestData.ShouldPersist(false)opts outThe FDv1 data system is unchanged: its data store, persistent or not, receives all data, including the file data source's. The flag is read only by the FDv2 data system.
Behavior change: an application that uses the file data source as an FDv2 initializer or synchronizer with a read-write persistent store no longer has the file data written to the store.
FileDataSourceBuilder.ShouldPersist(true)restores that.Mixed sequences
TestDatastarts with a full data set, and an FDv2 synchronizer that follows a basis without a selector (the file and test data sources provide none) requests a full transfer.Testing
FDv2DataSystemPersistenceTestruns real clients against a mock persistent store, for each case:ShouldPersist(true)is written.TestDatais written by default, initial data and updates.TestDatawithShouldPersist(false)is written neither for its initial data nor for an update.Initcount shows it, because the mock store'sInitreplaces all of its data.TestDatabehind an application's own wrapping configurer is not written.TestDataflag.TestData's data set.The contract tests do not cover this. The harness persistence suites have no test of file or test data, and this repository runs them with
enable_persistence_tests: 'false'; the contract test service has no persistent store support. A separate change enables them, and the harness gains tests of these cases.#390 makes the same change on
dotnet-server-sdk-v9, whereTestDatais not persisted by default.Found in review, not changed here
A multi-agent review of this change found three gaps in code it does not change. Java has the same three:
PollAvailabilityAfterOutageand writes an empty data set. Consul'sInitdeletes every key under the prefix that is not in the data, so this empties a shared Consul store.WriteThroughStorestops applying the rest of the delta and throws, so the SDK reports a store error and skips the flag change events.Opened from termag
SDK-3493