Skip to content

chore: Add read/write mode support for persistent store. - #206

Merged
kinyoklion merged 4 commits into
mainfrom
rlamb/support-persistent-store-mode
Dec 18, 2025
Merged

chore: Add read/write mode support for persistent store.#206
kinyoklion merged 4 commits into
mainfrom
rlamb/support-persistent-store-mode

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Dec 18, 2025

Copy link
Copy Markdown
Member

Adds support for controlling the read/write mode of the persistent store.
Added an exception for failure to write to the persistent store.

Adds a test suite for the WriteThroughStore.
Almost the entire PR size is from tests.


Note

Adds persistence mode to WriteThroughStore with conditional writes/init and improved apply error handling; wires mode in FDv2DataSystem; introduces a comprehensive test suite.

  • Data system:
    • FDv2DataSystem: Pass configuration.DataSystem.PersistentDataStoreMode to WriteThroughStore.
  • Data store:
    • WriteThroughStore:
      • Add _persistenceMode and ctor param to control persistent store behavior.
      • Init/Upsert/Apply write to persistent store only in ReadWrite mode; ReadOnly skips writes.
      • Switch active read store to memory on first initializing payload; Initialized() uses _activeReadStore.
      • In legacy persistence path, throw on failed apply (partial upserts) with clear exception message.
  • Tests:
    • New WriteThroughStoreTest: covers constructor behavior, init/get/getAll, upsert, apply (transactional vs legacy), store switching, initialized/selector/status monitoring, dispose, and error handling (including switch-to-memory on persistence failures).

Written by Cursor Bugbot for commit 0e23440. This will update automatically on new commits. Configure here.

@kinyoklion
kinyoklion force-pushed the rlamb/support-persistent-store-mode branch from ab581db to 2fed977 Compare December 18, 2025 21:44
@kinyoklion

Copy link
Copy Markdown
Member Author

bugbot review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no bugs!


@kinyoklion
kinyoklion marked this pull request as ready for review December 18, 2025 21:52
@kinyoklion
kinyoklion requested a review from a team as a code owner December 18, 2025 21:52
Comment thread pkgs/sdk/server/src/Internal/DataSystem/WriteThroughStore.cs
cursor[bot]

This comment was marked as outdated.

public bool Initialized()
{
return _hasPersistence ? _persistentStore.Initialized() : _memoryStore.Initialized();
return _activeReadStore.Initialized();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% on this. I think it results in correct LDClient behavior, but what needs validated is the persistent store restoration stuff. I think it will be fine as well.

If it isn't then this may need to be contingent on read/write mode. But it is not a critical problem either way.

public void Apply(DataStoreTypes.ChangeSet<DataStoreTypes.ItemDescriptor> changeSet)
{
_txMemoryStore.Apply(changeSet);
MaybeSwitchStore();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching earlier so a bad persistent store doesn't stop the SDK from using in-memory data.

// TODO: Probably throw?
}
// The exception type doesn't matter here, as it will be converted to data store status.
throw new Exception("Failure to apply data set to persistent store.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment knows too much!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also makes me wonder if Apply should have a bool result?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fits best with the current way data source updates works. Anything down the layers can throw an exception and its content can be included in a status update. The interface basically expects things to throw.

Basically this comment is just why it doesn't have a custom exception type, when it in a more general sense should.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we changed the exception type to "TransactionalApplyException", then the comment could go away.

@kinyoklion
kinyoklion merged commit 3b7e68e into main Dec 18, 2025
17 of 18 checks passed
@kinyoklion
kinyoklion deleted the rlamb/support-persistent-store-mode branch December 18, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants