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

Clear local metadata cache before refresh in client.load_metadata_for_topics() #367

Merged
merged 3 commits into from
Apr 13, 2015
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
27 changes: 14 additions & 13 deletions kafka/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,11 @@ def reinit(self):

def reset_topic_metadata(self, *topics):
for topic in topics:
try:
partitions = self.topic_partitions[topic]
except KeyError:
continue

for partition in partitions:
self.topics_to_brokers.pop(TopicAndPartition(topic, partition), None)

del self.topic_partitions[topic]
for topic_partition in list(self.topics_to_brokers.keys()):
if topic_partition.topic == topic:
del self.topics_to_brokers[topic_partition]
if topic in self.topic_partitions:
del self.topic_partitions[topic]

def reset_all_metadata(self):
self.topics_to_brokers.clear()
Expand Down Expand Up @@ -315,10 +311,17 @@ def load_metadata_for_topics(self, *topics):
(a single partition w/o a leader, for example)
"""
topics = [kafka_bytestring(t) for t in topics]

if topics:
for topic in topics:
self.reset_topic_metadata(topic)
else:
self.reset_all_metadata()

resp = self.send_metadata_request(topics)

log.debug("Broker metadata: %s", resp.brokers)
log.debug("Topic metadata: %s", resp.topics)
log.debug("Received new broker metadata: %s", resp.brokers)
log.debug("Received new topic metadata: %s", resp.topics)

self.brokers = dict([(broker.nodeId, broker)
for broker in resp.brokers])
Expand All @@ -327,8 +330,6 @@ def load_metadata_for_topics(self, *topics):
topic = topic_metadata.topic
partitions = topic_metadata.partitions

self.reset_topic_metadata(topic)

# Errors expected for new topics
try:
kafka.common.check_error(topic_metadata)
Expand Down