Skip to content
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

try to fix uncaught FailedPayloadsError in consumer #392

Merged
merged 1 commit into from
Jun 8, 2015
Merged
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
2 changes: 2 additions & 0 deletions kafka/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def _iter_broker_errors():


def check_error(response):
if isinstance(response, Exception):
raise response
if response.error:
error_class = kafka_errors.get(response.error, UnknownError)
raise error_class(response)
Expand Down
9 changes: 8 additions & 1 deletion kafka/consumer/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
FetchRequest, OffsetRequest,
ConsumerFetchSizeTooSmall, ConsumerNoMoreData,
UnknownTopicOrPartitionError, NotLeaderForPartitionError,
OffsetOutOfRangeError, check_error
OffsetOutOfRangeError, FailedPayloadsError, check_error
)
from .base import (
Consumer,
Expand Down Expand Up @@ -355,6 +355,13 @@ def _fetch(self):
# Retry this partition
retry_partitions[resp.partition] = partitions[resp.partition]
continue
except FailedPayloadsError as e:
log.warning("Failed payloads of %s"
"Resetting partition offset...",
e.payload)
# Retry this partition
retry_partitions[e.payload.partition] = partitions[e.payload.partition]
continue

partition = resp.partition
buffer_size = partitions[partition]
Expand Down
8 changes: 8 additions & 0 deletions test/test_failover_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def test_switch_leader_keyed_producer(self):
msg = random_string(10).encode('utf-8')
producer.send_messages(topic, key, msg)

@kafka_versions("all")
def test_switch_leader_simple_consumer(self):
producer = Producer(self.client, async=False)
consumer = SimpleConsumer(self.client, None, self.topic, partitions=None, auto_commit=False, iter_timeout=10)
self._send_random_messages(producer, self.topic, 0, 2)
consumer.get_messages()
self._kill_leader(self.topic, 0)
consumer.get_messages()

def _send_random_messages(self, producer, topic, partition, n):
for j in range(n):
Expand Down