Skip to content
New issue

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

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

Already on GitHub? # to your account

Initialize metadata_snapshot in group coordinator #1174

Merged
merged 2 commits into from
Aug 13, 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
15 changes: 9 additions & 6 deletions kafka/coordinator/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, client, subscription, metrics, **configs):
assert self.config['assignors'], 'Coordinator requires assignors'

self._subscription = subscription
self._metadata_snapshot = {}
self._metadata_snapshot = self._build_metadata_snapshot(subscription, client.cluster)
self._assignment_snapshot = None
self._cluster = client.cluster
self._cluster.request_update()
Expand Down Expand Up @@ -162,15 +162,18 @@ def _handle_metadata_update(self, cluster):
for partition in self._metadata_snapshot[topic]
])

def _subscription_metadata_changed(self, cluster):
if not self._subscription.partitions_auto_assigned():
return False

def _build_metadata_snapshot(self, subscription, cluster):
metadata_snapshot = {}
for topic in self._subscription.group_subscription():
for topic in subscription.group_subscription():
partitions = cluster.partitions_for_topic(topic) or []
metadata_snapshot[topic] = set(partitions)
return metadata_snapshot

def _subscription_metadata_changed(self, cluster):
if not self._subscription.partitions_auto_assigned():
return False

metadata_snapshot = self._build_metadata_snapshot(self._subscription, cluster)
if self._metadata_snapshot != metadata_snapshot:
self._metadata_snapshot = metadata_snapshot
return True
Expand Down