@@ -251,11 +251,7 @@ def _can_bootstrap(self):
251
251
252
252
def _can_connect (self , node_id ):
253
253
if node_id not in self ._conns :
254
- # cluster.broker_metadata() is stateful when called w/ 'bootstrap'
255
- # (it cycles through all of the bootstrap servers)
256
- # so we short-circuit here and assume that we should always have
257
- # some bootstrap_servers config to power bootstrap broker_metadata
258
- if node_id == 'bootstrap' or self .cluster .broker_metadata (node_id ):
254
+ if self .cluster .broker_metadata (node_id ):
259
255
return True
260
256
return False
261
257
conn = self ._conns [node_id ]
@@ -272,7 +268,7 @@ def _conn_state_change(self, node_id, conn):
272
268
except KeyError :
273
269
self ._selector .modify (conn ._sock , selectors .EVENT_WRITE )
274
270
275
- if node_id == 'bootstrap' :
271
+ if self . cluster . is_bootstrap ( node_id ) :
276
272
self ._last_bootstrap = time .time ()
277
273
278
274
elif conn .connected ():
@@ -290,12 +286,13 @@ def _conn_state_change(self, node_id, conn):
290
286
291
287
self ._idle_expiry_manager .update (node_id )
292
288
293
- if node_id == 'bootstrap' :
289
+ if self . cluster . is_bootstrap ( node_id ) :
294
290
self ._bootstrap_fails = 0
295
291
296
- elif 'bootstrap' in self ._conns :
297
- bootstrap = self ._conns .pop ('bootstrap' )
298
- bootstrap .close ()
292
+ else :
293
+ for node_id in list (self ._conns .keys ()):
294
+ if self .cluster .is_bootstrap (node_id ):
295
+ self ._conns .pop (node_id ).close ()
299
296
300
297
# Connection failures imply that our metadata is stale, so let's refresh
301
298
elif conn .state is ConnectionStates .DISCONNECTING :
@@ -314,7 +311,7 @@ def _conn_state_change(self, node_id, conn):
314
311
idle_disconnect = True
315
312
self ._idle_expiry_manager .remove (node_id )
316
313
317
- if node_id == 'bootstrap' :
314
+ if self . cluster . is_bootstrap ( node_id ) :
318
315
self ._bootstrap_fails += 1
319
316
320
317
elif self ._refresh_on_disconnects and not self ._closed and not idle_disconnect :
@@ -337,10 +334,6 @@ def _should_recycle_connection(self, conn):
337
334
if not conn .disconnected ():
338
335
return False
339
336
340
- # Always recycled disconnected bootstraps
341
- elif conn .node_id == 'bootstrap' :
342
- return True
343
-
344
337
# Otherwise, only recycle when broker metadata has changed
345
338
broker = self .cluster .broker_metadata (conn .node_id )
346
339
if broker is None :
@@ -361,10 +354,6 @@ def _maybe_connect(self, node_id):
361
354
conn = self ._conns .get (node_id )
362
355
363
356
if conn is None :
364
- # Note that when bootstrapping, each call to broker_metadata may
365
- # return a different host/port. So we need to be careful to only
366
- # call when necessary to avoid skipping some possible bootstrap
367
- # source.
368
357
broker = self .cluster .broker_metadata (node_id )
369
358
assert broker , 'Broker id %s not in current metadata' % (node_id ,)
370
359
@@ -703,7 +692,7 @@ def least_loaded_node(self):
703
692
in-flight-requests. If no such node is found, a node will be chosen
704
693
randomly from disconnected nodes that are not "blacked out" (i.e.,
705
694
are not subject to a reconnect backoff). If no node metadata has been
706
- obtained, will return ' bootstrap' (subject to exponential backoff).
695
+ obtained, will return a bootstrap node (subject to exponential backoff).
707
696
708
697
Returns:
709
698
node_id or None if no suitable node was found
@@ -730,10 +719,6 @@ def least_loaded_node(self):
730
719
if found is not None :
731
720
return found
732
721
733
- elif not nodes and self ._can_bootstrap ():
734
- self ._last_bootstrap = time .time ()
735
- return 'bootstrap'
736
-
737
722
return None
738
723
739
724
def set_topics (self , topics ):
@@ -791,7 +776,7 @@ def _maybe_refresh_metadata(self):
791
776
792
777
if self ._can_send_request (node_id ):
793
778
topics = list (self ._topics )
794
- if not topics and node_id == 'bootstrap' :
779
+ if not topics and self . cluster . is_bootstrap ( node_id ) :
795
780
topics = list (self .config ['bootstrap_topics_filter' ])
796
781
797
782
if self .cluster .need_all_topic_metadata or not topics :
0 commit comments