Don't invalidate zk context on stop event

Instead of aborting all zkobject operations when a component is stopped,
we should try to complete the current op and shutdown gracefully. The
stop event will only be used to determine if we should continue retrying
an operation or not.

Treating the stop event like a invalid ZK session can lead to data loss.

Change-Id: I16aa5a184934d5e3f451502e577301ad1d063feb
This commit is contained in:
Simon Westphahl
2025-01-14 11:18:40 +01:00
committed by James E. Blair
parent 7b35a1ae18
commit b52399b3bf
2 changed files with 7 additions and 4 deletions

View File

@@ -50,7 +50,7 @@ class BlobStore:
def _retry(self, context, func, *args, max_tries=-1, **kw):
kazoo_retry = KazooRetry(max_tries=max_tries,
interrupt=context.sessionIsInvalid,
interrupt=context.shouldAbortRetry,
delay=self._retry_interval, backoff=0,
ignore_expire=False)
try:

View File

@@ -97,12 +97,15 @@ class ZKContext(BaseZKContext):
self.profile = self.profile_default
def sessionIsValid(self):
return ((not self.lock or self.lock.is_still_valid()) and
(not self.stop_event or not self.stop_event.is_set()))
return (not self.lock or self.lock.is_still_valid())
def sessionIsInvalid(self):
return not self.sessionIsValid()
def shouldAbortRetry(self):
return (self.sessionIsInvalid() or
(self.stop_event and self.stop_event.is_set()))
def updateStatsFromOtherContext(self, other):
self.cumulative_read_time += other.cumulative_read_time
self.cumulative_write_time += other.cumulative_write_time
@@ -358,7 +361,7 @@ class ZKObject:
@classmethod
def _retry(cls, context, func, *args, max_tries=-1, **kw):
kazoo_retry = KazooRetry(max_tries=max_tries,
interrupt=context.sessionIsInvalid,
interrupt=context.shouldAbortRetry,
delay=cls._retry_interval, backoff=0,
ignore_expire=False)
try: