Skip to content
Open
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
9 changes: 9 additions & 0 deletions kafka/producer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import atexit
import logging
import time
import random

try:
from queue import Empty, Full, Queue # pylint: disable=import-error
Expand Down Expand Up @@ -125,9 +126,17 @@ def _send_upstream(queue, client, codec, batch_time, batch_size,
stop_event.set()
break

topic_partitions = client.topic_partitions

# Adjust the timeout to match the remaining period
count -= 1
timeout = send_at - time.time()
partitions_for_topic = len(topic_partitions[topic_partition.topic])
partition = topic_partition.partition
while topic_partitions[topic_partition.topic][topic_partition.partition] != -1:
log.warn('APPLIFT : Leader not found for %s:%d, reassigning data to other', topic_partition.topic, partition)
partition = random.randint(0, partitions_for_topic)
topic_partition = TopicPartition(topic_partition.topic, partition)
msgset[topic_partition].append((msg, key))

# Send collected requests upstream
Expand Down