Skip to content

Commit 7545052

Browse files
committed
lifecycle: adapt management producers and synchronous APIs
Deliver existing lifecycle notifications through the bounded management runtime while retaining publication locks and causal observation ordering. Reserve synchronous API admission before effects, allow bounded callback reentry between policy phases, and reject blocking calls on owner or I/O threads. Keep ordinary query routing on its existing path. Gate transaction notifications in the scheduler, release nested async admission through its active drainer, and restore idle state after executor rejection or runtime loss. Report unknown-host overload explicitly and release host-UP handling after failed pool admission. Coordinate lazy runtime installation with shutdown and defer managed cleanup until physical pool work and the completion barrier retire. Cover saturation, reentry, startup, shutdown, nested recovery and collection with controlled interleavings on rebuilt Cython and pure Python runtimes.
1 parent babdd72 commit 7545052

8 files changed

Lines changed: 1186 additions & 84 deletions

‎cassandra/_lifecycle.py‎

Lines changed: 323 additions & 47 deletions
Large diffs are not rendered by default.

‎cassandra/_management.py‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -728,19 +728,32 @@ def physical_work():
728728
receive(None, exc)
729729
return _PENDING
730730

731-
def notify(self, callback, *, wait=False, timeout=None, budget='ordinary'):
731+
def notify(self, callback, *, wait=False, timeout=None, budget='ordinary',
732+
ready=None):
733+
"""Admit FIFO delivery, optionally gated by a caller publication batch.
734+
735+
A gate is scheduler state: handlers never wait on the submitting
736+
thread. Release it through ``release_notifications`` after publication.
737+
"""
732738
self._check_pid()
733739
def admit(record):
734740
with self._condition:
735741
if self._closing or record.handler_done or record.released:
736742
return _PENDING
737743
record.notification = True
738-
self._notifications.append((record, callback))
744+
self._notifications.append((record, callback, ready))
739745
self._condition.notify_all()
740746
return _PENDING
741747
return self.submit(admit, wait=wait, timeout=timeout, budget=budget,
742748
kind='notification')
743749

750+
def release_notifications(self, gates):
751+
self._check_pid()
752+
with self._condition:
753+
for gate in gates:
754+
gate.set()
755+
self._condition.notify_all()
756+
744757
@contextmanager
745758
def synchronous_reentry(self):
746759
"""Reserve one L aggregate and a bounded prerequisite window."""
@@ -1047,11 +1060,14 @@ def _execute(self, record, callback, kind):
10471060
def _run_notifications(self):
10481061
while True:
10491062
with self._condition:
1050-
while not self._notifications and not self._closing:
1063+
while (not self._closing and
1064+
(not self._notifications or
1065+
(self._notifications[0][2] is not None and
1066+
not self._notifications[0][2].is_set()))):
10511067
self._condition.wait()
10521068
if self._closing:
10531069
return
1054-
record, callback = self._notifications.popleft()
1070+
record, callback, ready = self._notifications.popleft()
10551071
with _entered('callback', record):
10561072
try:
10571073
value = callback()
@@ -1066,7 +1082,7 @@ def _run_notifications(self):
10661082
with self._condition:
10671083
record.notification = False
10681084
self._release_locked(record)
1069-
record = callback = value = None
1085+
record = callback = ready = value = None
10701086

10711087
def retain_cleanup(self):
10721088
"""Retain one cleanup obligation independently of load."""
@@ -1097,7 +1113,7 @@ def close(self, wait=False):
10971113
for record in tuple(self._records):
10981114
self._finish(record, error=ManagementClosed(
10991115
'Management lifetime ended'))
1100-
for record, _ in self._notifications:
1116+
for record, _, _ in self._notifications:
11011117
record.notification = False
11021118
self._release_locked(record)
11031119
self._notifications.clear()

0 commit comments

Comments
 (0)