@@ -245,11 +245,7 @@ def _can_bootstrap(self):
245
245
246
246
def _can_connect (self , node_id ):
247
247
if node_id not in self ._conns :
248
- # cluster.broker_metadata() is stateful when called w/ 'bootstrap'
249
- # (it cycles through all of the bootstrap servers)
250
- # so we short-circuit here and assume that we should always have
251
- # some bootstrap_servers config to power bootstrap broker_metadata
252
- if node_id == 'bootstrap' or self .cluster .broker_metadata (node_id ):
248
+ if self .cluster .broker_metadata (node_id ):
253
249
return True
254
250
return False
255
251
conn = self ._conns [node_id ]
@@ -266,7 +262,7 @@ def _conn_state_change(self, node_id, conn):
266
262
except KeyError :
267
263
self ._selector .modify (conn ._sock , selectors .EVENT_WRITE )
268
264
269
- if node_id == 'bootstrap' :
265
+ if self . cluster . is_bootstrap ( node_id ) :
270
266
self ._last_bootstrap = time .time ()
271
267
272
268
elif conn .connected ():
@@ -284,12 +280,13 @@ def _conn_state_change(self, node_id, conn):
284
280
285
281
self ._idle_expiry_manager .update (node_id )
286
282
287
- if node_id == 'bootstrap' :
283
+ if self . cluster . is_bootstrap ( node_id ) :
288
284
self ._bootstrap_fails = 0
289
285
290
- elif 'bootstrap' in self ._conns :
291
- bootstrap = self ._conns .pop ('bootstrap' )
292
- bootstrap .close ()
286
+ else :
287
+ for node_id in list (self ._conns .keys ()):
288
+ if self .cluster .is_bootstrap (node_id ):
289
+ self ._conns .pop (node_id ).close ()
293
290
294
291
# Connection failures imply that our metadata is stale, so let's refresh
295
292
elif conn .state is ConnectionStates .DISCONNECTING :
@@ -308,7 +305,7 @@ def _conn_state_change(self, node_id, conn):
308
305
idle_disconnect = True
309
306
self ._idle_expiry_manager .remove (node_id )
310
307
311
- if node_id == 'bootstrap' :
308
+ if self . cluster . is_bootstrap ( node_id ) :
312
309
self ._bootstrap_fails += 1
313
310
314
311
elif self ._refresh_on_disconnects and not self ._closed and not idle_disconnect :
@@ -331,10 +328,6 @@ def _should_recycle_connection(self, conn):
331
328
if not conn .disconnected ():
332
329
return False
333
330
334
- # Always recycled disconnected bootstraps
335
- elif conn .node_id == 'bootstrap' :
336
- return True
337
-
338
331
# Otherwise, only recycle when broker metadata has changed
339
332
broker = self .cluster .broker_metadata (conn .node_id )
340
333
if broker is None :
@@ -355,10 +348,6 @@ def _maybe_connect(self, node_id):
355
348
conn = self ._conns .get (node_id )
356
349
357
350
if conn is None :
358
- # Note that when bootstrapping, each call to broker_metadata may
359
- # return a different host/port. So we need to be careful to only
360
- # call when necessary to avoid skipping some possible bootstrap
361
- # source.
362
351
broker = self .cluster .broker_metadata (node_id )
363
352
assert broker , 'Broker id %s not in current metadata' % (node_id ,)
364
353
@@ -697,7 +686,7 @@ def least_loaded_node(self):
697
686
in-flight-requests. If no such node is found, a node will be chosen
698
687
randomly from disconnected nodes that are not "blacked out" (i.e.,
699
688
are not subject to a reconnect backoff). If no node metadata has been
700
- obtained, will return ' bootstrap' (subject to exponential backoff).
689
+ obtained, will return a bootstrap node (subject to exponential backoff).
701
690
702
691
Returns:
703
692
node_id or None if no suitable node was found
@@ -724,10 +713,6 @@ def least_loaded_node(self):
724
713
if found is not None :
725
714
return found
726
715
727
- elif not nodes and self ._can_bootstrap ():
728
- self ._last_bootstrap = time .time ()
729
- return 'bootstrap'
730
-
731
716
return None
732
717
733
718
def set_topics (self , topics ):
@@ -785,7 +770,7 @@ def _maybe_refresh_metadata(self):
785
770
786
771
if self ._can_send_request (node_id ):
787
772
topics = list (self ._topics )
788
- if not topics and node_id == 'bootstrap' :
773
+ if not topics and self . cluster . is_bootstrap ( node_id ) :
789
774
topics = list (self .config ['bootstrap_topics_filter' ])
790
775
791
776
if self .cluster .need_all_topic_metadata or not topics :
0 commit comments