Skip to content

Commit 75281c5

Browse files
authored
Rename api_version_auto_timeout_ms -> bootstrap_timeout_ms; default 30s (#3028)
1 parent 7250337 commit 75281c5

6 files changed

Lines changed: 66 additions & 40 deletions

File tree

kafka/admin/client.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,31 @@ class KafkaAdminClient(
123123
certificate expiration. By default, no CRL check is done. When
124124
providing a file, only the leaf certificate will be checked against
125125
this CRL. Default: None.
126-
api_version (tuple): Specify which Kafka API version to use. If set
127-
to None, KafkaConnectionManager will attempt to infer the
128-
broker version by probing various APIs. Example: (0, 10, 2).
126+
api_version (tuple): Specify which Kafka API version to use. If set to
127+
None, the client will infer the broker version from the results of
128+
ApiVersionsRequest API or, for brokers earlier than 0.10, probing
129+
various known APIs. Different versions enable different functionality.
130+
131+
Examples:
132+
(4, 2) most recent broker release, enable all supported features
133+
(0, 11) enables message format v2 (internal)
134+
(0, 10, 0) enables sasl authentication and message format v1
135+
(0, 9) enables full group coordination features with automatic
136+
partition assignment and rebalancing,
137+
(0, 8, 2) enables kafka-storage offset commits with manual
138+
partition assignment only,
139+
(0, 8, 1) enables zookeeper-storage offset commits with manual
140+
partition assignment only,
141+
(0, 8, 0) enables basic functionality but requires manual
142+
partition assignment and offset management.
143+
129144
Default: None
130-
bootstrap_timeout_ms (int): number of milliseconds to throw a
131-
timeout exception from the constructor when bootstrapping.
132-
Default: 2000.
145+
bootstrap_timeout_ms (int): number of milliseconds to wait for first
146+
successful cluster bootstrap. If provided, an attempt to bootstrap
147+
will raise KafkaTimeoutError if it is unable to fetch cluster
148+
metadata before the configured timeout. Note that bootstrap is
149+
called eagerly from __init__().
150+
Default: 30000
133151
selector (selectors.BaseSelector): Provide a specific selector
134152
implementation to use for I/O multiplexing.
135153
Default: selectors.DefaultSelector
@@ -181,7 +199,7 @@ class KafkaAdminClient(
181199
'ssl_password': None,
182200
'ssl_crlfile': None,
183201
'api_version': None,
184-
'bootstrap_timeout_ms': 2000,
202+
'bootstrap_timeout_ms': 30000,
185203
'selector': selectors.DefaultSelector,
186204
'sasl_mechanism': None,
187205
'sasl_plain_username': None,

kafka/consumer/group.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,12 @@ class KafkaConsumer:
219219
or other configuration forbids use of all the specified ciphers),
220220
an ssl.SSLError will be raised. See ssl.SSLContext.set_ciphers
221221
api_version (tuple): Specify which Kafka API version to use. If set to
222-
None, the client will attempt to determine the broker version via
222+
None, the client will infer the broker version from the results of
223223
ApiVersionsRequest API or, for brokers earlier than 0.10, probing
224-
various known APIs. Dynamic version checking is performed eagerly
225-
during __init__ and can raise KafkaTimeoutError if no connection
226-
was made before timeout (see api_version_auto_timeout_ms below).
227-
Different versions enable different functionality.
224+
various known APIs. Different versions enable different functionality.
228225
229226
Examples:
230-
(3, 9) most recent broker release, enable all supported features
227+
(4, 2) most recent broker release, enable all supported features
231228
(0, 11) enables message format v2 (internal)
232229
(0, 10, 0) enables sasl authentication and message format v1
233230
(0, 9) enables full group coordination features with automatic
@@ -240,10 +237,12 @@ class KafkaConsumer:
240237
partition assignment and offset management.
241238
242239
Default: None
243-
api_version_auto_timeout_ms (int): number of milliseconds to throw a
244-
timeout exception from the constructor when checking the broker
245-
api version. Only applies if api_version set to None.
246-
Default: 2000
240+
bootstrap_timeout_ms (int): number of milliseconds to wait for first
241+
successful cluster bootstrap. If provided, an attempt to bootstrap
242+
will raise KafkaTimeoutError if it is unable to fetch cluster
243+
metadata before the configured timeout. Note that bootstrap will
244+
be called eagerly from __init__() if api_version is None.
245+
Default: 30000
247246
connections_max_idle_ms: Close idle connections after the number of
248247
milliseconds specified by this config. The broker closes idle
249248
connections after connections.max.idle.ms, so this avoids hitting
@@ -335,7 +334,7 @@ class KafkaConsumer:
335334
'ssl_password': None,
336335
'ssl_ciphers': None,
337336
'api_version': None,
338-
'api_version_auto_timeout_ms': 2000,
337+
'bootstrap_timeout_ms': 30000,
339338
'connections_max_idle_ms': 9 * 60 * 1000,
340339
'metric_reporters': [],
341340
'metrics_enabled': True,
@@ -407,11 +406,11 @@ def __init__(self, *topics, **configs):
407406
# poll() timing.
408407
self._net.start()
409408

410-
# If api_version was not passed explicitly, bootstrap to auto-discover
411-
# it. bootstrap is passed as a deferred coroutine so that once the IO
412-
# thread is introduced in a later phase it runs on the IO thread.
409+
# We currently depend on eager-resolution of api_version.
410+
# If it wasn't provided as a config option, we need to bootstrap
411+
# to get it.
413412
if self._manager.broker_version_data is None:
414-
self._manager.bootstrap(self.config['api_version_auto_timeout_ms'])
413+
self._manager.bootstrap(self.config['bootstrap_timeout_ms'])
415414
self.config['api_version'] = self._manager.broker_version
416415

417416
# Coordinator configurations are different for older brokers

kafka/net/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class KafkaConnection:
3434
'sasl_kerberos_service_name': 'kafka',
3535
'sasl_kerberos_domain_name': None,
3636
'sasl_oauth_token_provider': None,
37-
'api_version_auto_timeout_ms': 2000,
3837
'metrics': None,
3938
'metric_group_prefix': '',
4039
}

kafka/net/manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class KafkaConnectionManager:
5555
'sasl_oauth_token_provider': None,
5656
'proxy_url': None,
5757
'api_version': None,
58-
'api_version_auto_timeout_ms': 2000,
5958
'metrics': None,
6059
'metric_group_prefix': '',
6160
'metadata_max_age_ms': 300000,

kafka/producer/kafka.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,24 +336,30 @@ class KafkaProducer:
336336
or other configuration forbids use of all the specified ciphers),
337337
an ssl.SSLError will be raised. See ssl.SSLContext.set_ciphers
338338
api_version (tuple): Specify which Kafka API version to use. If set to
339-
None, the client will attempt to determine the broker version via
339+
None, the client will infer the broker version from the results of
340340
ApiVersionsRequest API or, for brokers earlier than 0.10, probing
341-
various known APIs. Dynamic version checking is performed eagerly
342-
during __init__ and can raise KafkaTimeoutError if no connection
343-
was made before timeout (see api_version_auto_timeout_ms below).
344-
Different versions enable different functionality.
341+
various known APIs. Different versions enable different functionality.
345342
346343
Examples:
347-
(3, 9) most recent broker release, enable all supported features
344+
(4, 2) most recent broker release, enable all supported features
348345
(0, 11) enables message format v2 (internal)
349346
(0, 10, 0) enables sasl authentication and message format v1
350-
(0, 8, 0) enables basic functionality only
347+
(0, 9) enables full group coordination features with automatic
348+
partition assignment and rebalancing,
349+
(0, 8, 2) enables kafka-storage offset commits with manual
350+
partition assignment only,
351+
(0, 8, 1) enables zookeeper-storage offset commits with manual
352+
partition assignment only,
353+
(0, 8, 0) enables basic functionality but requires manual
354+
partition assignment and offset management.
351355
352356
Default: None
353-
api_version_auto_timeout_ms (int): number of milliseconds to throw a
354-
timeout exception from the constructor when checking the broker
355-
api version. Only applies if api_version set to None.
356-
Default: 2000
357+
bootstrap_timeout_ms (int): number of milliseconds to wait for first
358+
successful cluster bootstrap. If provided, an attempt to bootstrap
359+
will raise KafkaTimeoutError if it is unable to fetch cluster
360+
metadata before the configured timeout. Note that bootstrap will
361+
be called eagerly from __init__() if api_version is None.
362+
Default: 30000
357363
metric_reporters (list): A list of classes to use as metrics reporters.
358364
Implementing the AbstractMetricsReporter interface allows plugging
359365
in classes that will be notified of new metric creation. Default: []
@@ -429,7 +435,7 @@ class KafkaProducer:
429435
'ssl_password': None,
430436
'ssl_ciphers': None,
431437
'api_version': None,
432-
'api_version_auto_timeout_ms': 2000,
438+
'bootstrap_timeout_ms': 30000,
433439
'metric_reporters': [],
434440
'metrics_enabled': True,
435441
'metrics_num_samples': 2,
@@ -506,9 +512,14 @@ def __init__(self, **configs):
506512
metrics=self._metrics, metric_group_prefix='producer',
507513
wakeup_timeout_ms=self.config['max_block_ms'],
508514
**self.config)
515+
manager = client._manager
509516

510-
# Get auto-discovered / normalized version from client
511-
self.config['api_version'] = client.get_broker_version(timeout_ms=self.config['api_version_auto_timeout_ms'])
517+
# We currently depend on eager-resolution of api_version.
518+
# If it wasn't provided as a config option, we need to bootstrap
519+
# to get it.
520+
if manager.broker_version_data is None:
521+
manager.bootstrap(self.config['bootstrap_timeout_ms'])
522+
self.config['api_version'] = manager.broker_version
512523

513524
if self.config['compression_type'] == 'lz4':
514525
assert self.config['api_version'] >= (0, 8, 2), 'LZ4 Requires >= Kafka 0.8.2 Brokers'
@@ -525,7 +536,7 @@ def __init__(self, **configs):
525536
assert checker(), "Libraries for {} compression codec not found".format(ct)
526537
self.config['compression_attrs'] = compression_attrs
527538

528-
self._metadata = client.cluster
539+
self._metadata = manager.cluster
529540
self._transaction_manager = None
530541
self._init_transactions_result = None
531542

test/integration/test_consumer_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def consumer_thread(i):
366366
client_id="consumer_thread-%s" % i,
367367
session_timeout_ms=3000,
368368
request_timeout_ms=4000,
369-
api_version_auto_timeout_ms=5000) as c:
369+
bootstrap_timeout_ms=5000) as c:
370370
consumers[i] = c
371371
while not stop[i].is_set():
372372
for tp, records in consumers[i].poll(timeout_ms=200).items():

0 commit comments

Comments
 (0)