Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
370 changes: 323 additions & 47 deletions cassandra/_lifecycle.py

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions cassandra/_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,19 +728,32 @@ def physical_work():
receive(None, exc)
return _PENDING

def notify(self, callback, *, wait=False, timeout=None, budget='ordinary'):
def notify(self, callback, *, wait=False, timeout=None, budget='ordinary',
ready=None):
"""Admit FIFO delivery, optionally gated by a caller publication batch.

A gate is scheduler state: handlers never wait on the submitting
thread. Release it through ``release_notifications`` after publication.
"""
self._check_pid()
def admit(record):
with self._condition:
if self._closing or record.handler_done or record.released:
return _PENDING
record.notification = True
self._notifications.append((record, callback))
self._notifications.append((record, callback, ready))
self._condition.notify_all()
return _PENDING
return self.submit(admit, wait=wait, timeout=timeout, budget=budget,
kind='notification')

def release_notifications(self, gates):
self._check_pid()
with self._condition:
for gate in gates:
gate.set()
self._condition.notify_all()

@contextmanager
def synchronous_reentry(self):
"""Reserve one L aggregate and a bounded prerequisite window."""
Expand Down Expand Up @@ -1047,11 +1060,14 @@ def _execute(self, record, callback, kind):
def _run_notifications(self):
while True:
with self._condition:
while not self._notifications and not self._closing:
while (not self._closing and
(not self._notifications or
(self._notifications[0][2] is not None and
not self._notifications[0][2].is_set()))):
self._condition.wait()
if self._closing:
return
record, callback = self._notifications.popleft()
record, callback, ready = self._notifications.popleft()
with _entered('callback', record):
try:
value = callback()
Expand All @@ -1066,7 +1082,7 @@ def _run_notifications(self):
with self._condition:
record.notification = False
self._release_locked(record)
record = callback = value = None
record = callback = ready = value = None

def retain_cleanup(self):
"""Retain one cleanup obligation independently of load."""
Expand Down Expand Up @@ -1097,7 +1113,7 @@ def close(self, wait=False):
for record in tuple(self._records):
self._finish(record, error=ManagementClosed(
'Management lifetime ended'))
for record, _ in self._notifications:
for record, _, _ in self._notifications:
record.notification = False
self._release_locked(record)
self._notifications.clear()
Expand Down
Loading
Loading