Skip to content

Commit a097be2

Browse files
author
Petr Šebek
committed
change_subscription called only when necessary
When we are using subscription by pattern change subscription is called every metadata update even when nothing changes. This PR ensures that change subscription is called only when set of topics changes.
1 parent b8da199 commit a097be2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

kafka/consumer/subscription_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ def change_subscription(self, topics):
137137
topics = [topics]
138138

139139
if self.subscription == set(topics):
140-
log.warning("subscription unchanged by change_subscription(%s)",
141-
topics)
140+
log.info("subscription unchanged by change_subscription(%s)",
141+
topics)
142142
return
143143

144144
if any(not isinstance(t, six.string_types) for t in topics):

kafka/coordinator/consumer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ def _handle_metadata_update(self, cluster):
140140
if self._subscription.subscribed_pattern.match(topic):
141141
topics.append(topic)
142142

143-
self._subscription.change_subscription(topics)
144-
self._client.set_topics(self._subscription.group_subscription())
143+
if set(topics) != self._subscription.subscription:
144+
self._subscription.change_subscription(topics)
145+
self._client.set_topics(self._subscription.group_subscription())
145146

146147
# check if there are any changes to the metadata which should trigger
147148
# a rebalance

0 commit comments

Comments
 (0)