Skip to content

Commit 4b32b2e

Browse files
authored
Initialize metadata_snapshot in group coordinator (#1174)
1 parent 422189b commit 4b32b2e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

kafka/coordinator/consumer.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self, client, subscription, metrics, **configs):
8787
assert self.config['assignors'], 'Coordinator requires assignors'
8888

8989
self._subscription = subscription
90-
self._metadata_snapshot = {}
90+
self._metadata_snapshot = self._build_metadata_snapshot(subscription, client.cluster)
9191
self._assignment_snapshot = None
9292
self._cluster = client.cluster
9393
self._cluster.request_update()
@@ -162,15 +162,18 @@ def _handle_metadata_update(self, cluster):
162162
for partition in self._metadata_snapshot[topic]
163163
])
164164

165-
def _subscription_metadata_changed(self, cluster):
166-
if not self._subscription.partitions_auto_assigned():
167-
return False
168-
165+
def _build_metadata_snapshot(self, subscription, cluster):
169166
metadata_snapshot = {}
170-
for topic in self._subscription.group_subscription():
167+
for topic in subscription.group_subscription():
171168
partitions = cluster.partitions_for_topic(topic) or []
172169
metadata_snapshot[topic] = set(partitions)
170+
return metadata_snapshot
171+
172+
def _subscription_metadata_changed(self, cluster):
173+
if not self._subscription.partitions_auto_assigned():
174+
return False
173175

176+
metadata_snapshot = self._build_metadata_snapshot(self._subscription, cluster)
174177
if self._metadata_snapshot != metadata_snapshot:
175178
self._metadata_snapshot = metadata_snapshot
176179
return True

0 commit comments

Comments
 (0)