Skip to content

Commit 016b8c9

Browse files
author
Gabriel Tincu
committed
Use old error api
1 parent 63b4ef8 commit 016b8c9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

kafka/producer/record_accumulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ def try_append(self, timestamp_ms, key, value, headers):
6868
sum(len(h_key.encode("utf-8")) + len(h_val) for h_key, h_val in headers) if headers else -1)
6969
return future
7070

71-
def done(self, base_offset=None, timestamp_ms=None, exception=None, log_start_offset=None):
71+
def done(self, base_offset=None, timestamp_ms=None, exception=None, log_start_offset=None, global_error=None):
7272
level = logging.DEBUG if exception is None else logging.WARNING
7373
log.log(level, "Produced messages to topic-partition %s with base offset"
7474
" %s log start offset %s and error %s.", self.topic_partition, base_offset,
75-
log_start_offset, exception) # trace
75+
log_start_offset, global_error) # trace
7676
if self.produce_future.is_done:
7777
log.warning('Batch is already closed -- ignoring batch.done()')
7878
return

kafka/producer/sender.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _handle_produce_response(self, node_id, send_time, batches, response):
195195

196196
for topic, partitions in response.topics:
197197
for partition_info in partitions:
198-
error_message = None
198+
global_error = None
199199
if response.API_VERSION < 2:
200200
partition, error_code, offset = partition_info
201201
ts = None
@@ -204,11 +204,11 @@ def _handle_produce_response(self, node_id, send_time, batches, response):
204204
elif 5 <= response.API_VERSION <= 7:
205205
partition, error_code, offset, ts, log_start_offset = partition_info
206206
else:
207-
partition, error_code, offset, ts, log_start_offset, _, error_message = partition_info
207+
partition, error_code, offset, ts, log_start_offset, _, global_error = partition_info
208208
tp = TopicPartition(topic, partition)
209-
error = error_message or Errors.for_code(error_code)
209+
error = Errors.for_code(error_code)
210210
batch = batches_by_partition[tp]
211-
self._complete_batch(batch, error, offset, ts)
211+
self._complete_batch(batch, error, offset, ts, global_error)
212212

213213
if response.API_VERSION > 0:
214214
self._sensors.record_throttle_time(response.throttle_time_ms, node=node_id)
@@ -218,7 +218,7 @@ def _handle_produce_response(self, node_id, send_time, batches, response):
218218
for batch in batches:
219219
self._complete_batch(batch, None, -1, None)
220220

221-
def _complete_batch(self, batch, error, base_offset, timestamp_ms=None, log_start_offset=None):
221+
def _complete_batch(self, batch, error, base_offset, timestamp_ms=None, log_start_offset=None, global_error=None):
222222
"""Complete or retry the given batch of records.
223223
224224
Arguments:
@@ -238,15 +238,15 @@ def _complete_batch(self, batch, error, base_offset, timestamp_ms=None, log_star
238238
" retrying (%d attempts left). Error: %s",
239239
batch.topic_partition,
240240
self.config['retries'] - batch.attempts - 1,
241-
error)
241+
global_error or error)
242242
self._accumulator.reenqueue(batch)
243243
self._sensors.record_retries(batch.topic_partition.topic, batch.record_count)
244244
else:
245245
if error is Errors.TopicAuthorizationFailedError:
246246
error = error(batch.topic_partition.topic)
247247

248248
# tell the user the result of their request
249-
batch.done(base_offset, timestamp_ms, error, log_start_offset)
249+
batch.done(base_offset, timestamp_ms, error, log_start_offset, global_error)
250250
self._accumulator.deallocate(batch)
251251
if error is not None:
252252
self._sensors.record_errors(batch.topic_partition.topic, batch.record_count)

0 commit comments

Comments
 (0)