Skip to content

Commit 8bcddb1

Browse files
committed
Halt execution if set/apply fails
1 parent d63149a commit 8bcddb1

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

ldclient/impl/datasystem/store.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,34 @@ def all(self, kind: VersionedDataKind, callback: Callable[[Any], Any] = lambda x
8787
finally:
8888
self._lock.runlock()
8989

90-
def set_basis(self, collections: Collections):
90+
def set_basis(self, collections: Collections) -> bool:
9191
"""
9292
Initializes the store with a full set of data, replacing any existing data.
9393
"""
9494
all_decoded = self.__decode_collection(collections)
9595
if all_decoded is None:
96-
return
96+
return False
9797

9898
try:
9999
self._lock.lock()
100100
self._items.clear()
101101
self._items.update(all_decoded)
102102
self._initialized = True
103+
except Exception as e:
104+
log.error("Failed applying set_basis", exc_info=e)
105+
return False
103106
finally:
104107
self._lock.unlock()
105108

106-
def apply_delta(self, collections: Collections):
109+
return True
110+
111+
def apply_delta(self, collections: Collections) -> bool:
107112
"""
108113
Applies a delta update to the store.
109114
"""
110115
all_decoded = self.__decode_collection(collections)
111116
if all_decoded is None:
112-
return
117+
return False
113118

114119
try:
115120
self._lock.lock()
@@ -121,9 +126,14 @@ def apply_delta(self, collections: Collections):
121126
log.debug(
122127
"Updated %s in '%s' to version %d", key, kind.namespace, item["version"]
123128
)
129+
except Exception as e:
130+
log.error("Failed applying apply_delta", exc_info=e)
131+
return False
124132
finally:
125133
self._lock.unlock()
126134

135+
return True
136+
127137
def __decode_collection(self, collections: Collections) -> Optional[Dict[VersionedDataKind, Dict[str, Any]]]:
128138
try:
129139
all_decoded = {}
@@ -289,7 +299,9 @@ def _set_basis(
289299
for kind in [FEATURES, SEGMENTS]:
290300
old_data[kind] = self._memory_store.all(kind, lambda x: x)
291301

292-
self._memory_store.set_basis(collections)
302+
ok = self._memory_store.set_basis(collections)
303+
if ok is False:
304+
return
293305

294306
# Update dependency tracker
295307
self._reset_dependency_tracker(collections)
@@ -322,7 +334,9 @@ def _apply_delta(
322334
change_set: The changeset containing the delta changes
323335
persist: Whether to persist the changes to the persistent store
324336
"""
325-
self._memory_store.apply_delta(collections)
337+
ok = self._memory_store.apply_delta(collections)
338+
if ok is False:
339+
return
326340

327341
has_listeners = self._flag_change_listeners.has_listeners()
328342
affected_items: Set[KindAndKey] = set()

0 commit comments

Comments
 (0)