Skip to content

Commit ab581db

Browse files
committed
chore: Add read/write mode support for persistent store.
1 parent ac41228 commit ab581db

File tree

3 files changed

+719
-6
lines changed

3 files changed

+719
-6
lines changed

pkgs/sdk/server/src/Internal/DataSystem/FDv2DataSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public static FDv2DataSystem Create(Logger logger, Configuration configuration,
5959
var persistentStore =
6060
dataSystemConfiguration.PersistentStore?.Build(clientContext.WithDataStoreUpdates(dataStoreUpdates));
6161

62-
var writeThroughStore = new WriteThroughStore(memoryStore, persistentStore);
62+
var writeThroughStore = new WriteThroughStore(memoryStore, persistentStore,
63+
dataSystemConfiguration.PersistentDataStoreMode);
6364

6465
// TODO: When a persistent store is available we monitor it, is this a consistent choice.
6566
// TODO: Update the responses data store monitoring?

pkgs/sdk/server/src/Internal/DataSystem/WriteThroughStore.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using LaunchDarkly.Sdk.Internal.Concurrent;
32
using LaunchDarkly.Sdk.Server.Subsystems;
43

@@ -26,15 +25,18 @@ internal class WriteThroughStore : IDataStore, ITransactionalDataStore
2625
/// </para>
2726
/// </summary>
2827
private readonly AtomicBoolean _hasReceivedAnInitializingPayload = new AtomicBoolean(false);
28+
29+
private readonly DataSystemConfiguration.DataStoreMode _persistenceMode;
2930

30-
public WriteThroughStore(IDataStore memoryStore, IDataStore persistentStore)
31+
public WriteThroughStore(IDataStore memoryStore, IDataStore persistentStore, DataSystemConfiguration.DataStoreMode persistenceMode)
3132
{
3233
_memoryStore = memoryStore;
3334
_txMemoryStore = (ITransactionalDataStore)_memoryStore;
3435
_persistentStore = persistentStore;
3536
_hasPersistence = persistentStore != null;
3637
// During initializations read will happen from the persistent store.
3738
_activeReadStore = _hasPersistence ? _persistentStore : _memoryStore;
39+
_persistenceMode = persistenceMode;
3840
}
3941

4042
public void Dispose()
@@ -56,7 +58,11 @@ private void Dispose(bool disposing)
5658
public void Init(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allData)
5759
{
5860
_memoryStore.Init(allData);
59-
_persistentStore?.Init(allData);
61+
if (_persistenceMode == DataSystemConfiguration.DataStoreMode.ReadWrite)
62+
{
63+
_persistentStore?.Init(allData);
64+
}
65+
6066
MaybeSwitchStore();
6167
}
6268

@@ -73,7 +79,7 @@ public void Init(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allDa
7379
public bool Upsert(DataStoreTypes.DataKind kind, string key, DataStoreTypes.ItemDescriptor item)
7480
{
7581
var result = _memoryStore.Upsert(kind, key, item);
76-
if (_hasPersistence)
82+
if (_hasPersistence && _persistenceMode == DataSystemConfiguration.DataStoreMode.ReadWrite)
7783
{
7884
result &= _persistentStore.Upsert(kind, key, item);
7985
}
@@ -93,7 +99,7 @@ public void Apply(DataStoreTypes.ChangeSet<DataStoreTypes.ItemDescriptor> change
9399
{
94100
_txMemoryStore.Apply(changeSet);
95101

96-
if (_hasPersistence)
102+
if (_hasPersistence && _persistenceMode == DataSystemConfiguration.DataStoreMode.ReadWrite)
97103
{
98104
if (_persistentStore is ITransactionalDataStore txPersistentStore)
99105
{

0 commit comments

Comments
 (0)