Skip to content
Merged
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
15 changes: 11 additions & 4 deletions cassandra/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,14 +858,17 @@ def __init__(self, trace_id, session):
self.trace_id = trace_id
self._session = session

def populate(self, max_wait=2.0):
def populate(self, max_wait=2.0, wait_for_complete=True):
"""
Retrieves the actual tracing details from Cassandra and populates the
attributes of this instance. Because tracing details are stored
asynchronously by Cassandra, this may need to retry the session
detail fetch. If the trace is still not available after `max_wait`
seconds, :exc:`.TraceUnavailable` will be raised; if `max_wait` is
:const:`None`, this will retry forever.

`wait_for_complete=False` bypasses the wait for duration to be populated.
This can be used to query events from partial sessions.
"""
attempt = 0
start = time.time()
Expand All @@ -879,15 +882,19 @@ def populate(self, max_wait=2.0):
session_results = self._execute(
self._SELECT_SESSIONS_FORMAT, (self.trace_id,), time_spent, max_wait)

if not session_results or session_results[0].duration is None:
is_complete = session_results[0].duration is not None
if not session_results or (wait_for_complete and not is_complete):
time.sleep(self._BASE_RETRY_SLEEP * (2 ** attempt))
attempt += 1
continue
log.debug("Fetched trace info for trace ID: %s", self.trace_id)
if is_complete:
log.debug("Fetched trace info for trace ID: %s", self.trace_id)
else:
log.debug("Fetching parital trace info for trace ID: %s", self.trace_id)

session_row = session_results[0]
self.request_type = session_row.request
self.duration = timedelta(microseconds=session_row.duration)
self.duration = timedelta(microseconds=session_row.duration) if is_complete else None
self.started_at = session_row.started_at
self.coordinator = session_row.coordinator
self.parameters = session_row.parameters
Expand Down