Skip to content

Commit a89650b

Browse files
committed
chore: Update FDv2 memory store to be atomic
1 parent bf82505 commit a89650b

File tree

10 files changed

+168
-137
lines changed

10 files changed

+168
-137
lines changed

ldclient/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
DataStoreStatusProvider,
5454
DataStoreUpdateSink,
5555
FeatureStore,
56-
FlagTracker
56+
FlagTracker,
57+
ReadOnlyStore
5758
)
5859
from ldclient.migrations import OpTracker, Stage
5960
from ldclient.plugin import (
@@ -272,7 +273,7 @@ def __start_up(self, start_wait: float):
272273
self._data_system.data_source_status_provider
273274
)
274275
self.__flag_tracker = self._data_system.flag_tracker
275-
self._store: FeatureStore = self._data_system.store # type: ignore
276+
self._store: ReadOnlyStore = self._data_system.store
276277

277278
big_segment_store_manager = BigSegmentStoreManager(self._config.big_segments)
278279
self.__big_segment_store_manager = big_segment_store_manager

ldclient/impl/datasystem/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
DataSourceState,
1717
DataSourceStatusProvider,
1818
DataStoreStatusProvider,
19-
FlagTracker
19+
FlagTracker,
20+
ReadOnlyStore
2021
)
2122

2223

@@ -141,6 +142,14 @@ def target_availability(self) -> DataAvailability:
141142
"""
142143
raise NotImplementedError
143144

145+
@property
146+
@abstractmethod
147+
def store(self) -> ReadOnlyStore:
148+
"""
149+
Returns the data store used by the data system.
150+
"""
151+
raise NotImplementedError
152+
144153

145154
class SelectorStore(Protocol):
146155
"""

ldclient/impl/datasystem/fdv1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
DataStoreStatusProvider,
2525
FeatureStore,
2626
FlagTracker,
27+
ReadOnlyStore,
2728
UpdateProcessor
2829
)
2930

@@ -110,7 +111,7 @@ def stop(self):
110111
self._update_processor.stop()
111112

112113
@property
113-
def store(self) -> FeatureStore:
114+
def store(self) -> ReadOnlyStore:
114115
return self._store_wrapper
115116

116117
def set_flag_value_eval_fn(self, eval_fn):

ldclient/impl/datasystem/fdv2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
DataStoreStatus,
2525
DataStoreStatusProvider,
2626
FeatureStore,
27-
FlagTracker
27+
FlagTracker,
28+
ReadOnlyStore
2829
)
2930
from ldclient.versioned_data_kind import VersionedDataKind
3031

@@ -500,7 +501,7 @@ def _recovery_condition(self, status: DataSourceStatus) -> bool:
500501
return interrupted_at_runtime or healthy_for_too_long or cannot_initialize
501502

502503
@property
503-
def store(self) -> FeatureStore:
504+
def store(self) -> ReadOnlyStore:
504505
"""Get the underlying store for flag evaluation."""
505506
return self._store.get_active_store()
506507

ldclient/impl/datasystem/protocolv2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,7 @@ class Change:
458458
kind: ObjectKind
459459
key: str
460460
version: int
461-
object: Any = (
462-
None # TODO(fdv2): At some point, we should define a better type for this.
463-
)
461+
object: Optional[dict] = None
464462

465463

466464
@dataclass(frozen=True)

0 commit comments

Comments
 (0)