Skip to content

Improve error message when expiring batches in KafkaProducer #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2017
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
18 changes: 11 additions & 7 deletions kafka/producer/record_accumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,19 @@ def maybe_expire(self, request_timeout_ms, retry_backoff_ms, linger_ms, is_full)
since_backoff = now - (self.last_attempt + retry_backoff_ms / 1000.0)
timeout = request_timeout_ms / 1000.0

if ((not self.in_retry() and is_full and timeout < since_append) or
(not self.in_retry() and timeout < since_ready) or
(self.in_retry() and timeout < since_backoff)):

error = None
if not self.in_retry() and is_full and timeout < since_append:
error = "%d ms has passed since last append" % since_append
elif not self.in_retry() and timeout < since_ready:
error = "%d ms has passed since batch creation plus linger time" % since_ready
elif self.in_retry() and timeout < since_backoff:
error = "%d ms has passed since last attempt plus backoff time" % since_backoff

if error:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe if error is not None or initialize error to be ""

self.records.close()
self.done(-1, None, Errors.KafkaTimeoutError(
"Batch containing %s record(s) expired due to timeout while"
" requesting metadata from brokers for %s", self.record_count,
self.topic_partition))
"Batch for %s containing %s record(s) expired: %s" % (
self.topic_partition, self.record_count, error)))
return True
return False

Expand Down