kafka-python 2.2.2__py2.py3-none-any.whl → 2.2.3__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kafka/cluster.py CHANGED
@@ -3,13 +3,15 @@ from __future__ import absolute_import
3
3
  import collections
4
4
  import copy
5
5
  import logging
6
+ import random
7
+ import re
6
8
  import threading
7
9
  import time
8
10
 
9
11
  from kafka.vendor import six
10
12
 
11
13
  from kafka import errors as Errors
12
- from kafka.conn import collect_hosts
14
+ from kafka.conn import get_ip_port_afi
13
15
  from kafka.future import Future
14
16
  from kafka.structs import BrokerMetadata, PartitionMetadata, TopicPartition
15
17
 
@@ -422,3 +424,24 @@ class ClusterMetadata(object):
422
424
  def __str__(self):
423
425
  return 'ClusterMetadata(brokers: %d, topics: %d, coordinators: %d)' % \
424
426
  (len(self._brokers), len(self._partitions), len(self._coordinators))
427
+
428
+
429
+ def collect_hosts(hosts, randomize=True):
430
+ """
431
+ Collects a comma-separated set of hosts (host:port) and optionally
432
+ randomize the returned list.
433
+ """
434
+
435
+ if isinstance(hosts, six.string_types):
436
+ hosts = hosts.strip().split(',')
437
+
438
+ result = []
439
+ for host_port in hosts:
440
+ # ignore leading SECURITY_PROTOCOL:// to mimic java client
441
+ host_port = re.sub('^.*://', '', host_port)
442
+ host, port, afi = get_ip_port_afi(host_port)
443
+ result.append((host, port, afi))
444
+
445
+ if randomize:
446
+ random.shuffle(result)
447
+ return result
kafka/conn.py CHANGED
@@ -4,7 +4,7 @@ import copy
4
4
  import errno
5
5
  import io
6
6
  import logging
7
- from random import shuffle, uniform
7
+ from random import uniform
8
8
 
9
9
  # selectors in stdlib as of py3.4
10
10
  try:
@@ -1496,32 +1496,6 @@ def get_ip_port_afi(host_and_port_str):
1496
1496
  return host, port, af
1497
1497
 
1498
1498
 
1499
- def collect_hosts(hosts, randomize=True):
1500
- """
1501
- Collects a comma-separated set of hosts (host:port) and optionally
1502
- randomize the returned list.
1503
- """
1504
-
1505
- if isinstance(hosts, six.string_types):
1506
- hosts = hosts.strip().split(',')
1507
-
1508
- result = []
1509
- afi = socket.AF_INET
1510
- for host_port in hosts:
1511
-
1512
- host, port, afi = get_ip_port_afi(host_port)
1513
-
1514
- if port < 0:
1515
- port = DEFAULT_KAFKA_PORT
1516
-
1517
- result.append((host, port, afi))
1518
-
1519
- if randomize:
1520
- shuffle(result)
1521
-
1522
- return result
1523
-
1524
-
1525
1499
  def is_inet_4_or_6(gai):
1526
1500
  """Given a getaddrinfo struct, return True iff ipv4 or ipv6"""
1527
1501
  return gai[0] in (socket.AF_INET, socket.AF_INET6)
kafka/consumer/fetcher.py CHANGED
@@ -153,6 +153,7 @@ class Fetcher(six.Iterator):
153
153
  future = self._client.send(node_id, request, wakeup=False)
154
154
  future.add_callback(self._handle_fetch_response, node_id, fetch_offsets, time.time())
155
155
  future.add_errback(self._handle_fetch_error, node_id)
156
+ future.add_both(self._clear_pending_fetch_request, node_id)
156
157
  futures.append(future)
157
158
  self._fetch_futures.extend(futures)
158
159
  self._clean_done_fetch_futures()
@@ -643,36 +644,42 @@ class Fetcher(six.Iterator):
643
644
  log.debug("Skipping fetch for partition %s because node %s is throttled",
644
645
  partition, node_id)
645
646
 
647
+ elif not self._client.ready(node_id):
648
+ # Until we support send request queues, any attempt to send to a not-ready node will be
649
+ # immediately failed with NodeNotReadyError.
650
+ log.debug("Skipping fetch for partition %s because connection to leader node is not ready yet")
651
+
646
652
  elif node_id in self._nodes_with_pending_fetch_requests:
647
653
  log.debug("Skipping fetch for partition %s because there is a pending fetch request to node %s",
648
654
  partition, node_id)
649
- continue
650
655
 
651
- if version < 5:
652
- partition_info = (
653
- partition.partition,
654
- position.offset,
655
- self.config['max_partition_fetch_bytes']
656
- )
657
- elif version <= 8:
658
- partition_info = (
659
- partition.partition,
660
- position.offset,
661
- -1, # log_start_offset is used internally by brokers / replicas only
662
- self.config['max_partition_fetch_bytes'],
663
- )
664
656
  else:
665
- partition_info = (
666
- partition.partition,
667
- position.leader_epoch,
668
- position.offset,
669
- -1, # log_start_offset is used internally by brokers / replicas only
670
- self.config['max_partition_fetch_bytes'],
671
- )
672
-
673
- fetchable[node_id][partition] = partition_info
674
- log.debug("Adding fetch request for partition %s at offset %d",
675
- partition, position.offset)
657
+ # Leader is connected and does not have a pending fetch request
658
+ if version < 5:
659
+ partition_info = (
660
+ partition.partition,
661
+ position.offset,
662
+ self.config['max_partition_fetch_bytes']
663
+ )
664
+ elif version <= 8:
665
+ partition_info = (
666
+ partition.partition,
667
+ position.offset,
668
+ -1, # log_start_offset is used internally by brokers / replicas only
669
+ self.config['max_partition_fetch_bytes'],
670
+ )
671
+ else:
672
+ partition_info = (
673
+ partition.partition,
674
+ position.leader_epoch,
675
+ position.offset,
676
+ -1, # log_start_offset is used internally by brokers / replicas only
677
+ self.config['max_partition_fetch_bytes'],
678
+ )
679
+
680
+ fetchable[node_id][partition] = partition_info
681
+ log.debug("Adding fetch request for partition %s at offset %d",
682
+ partition, position.offset)
676
683
 
677
684
  requests = {}
678
685
  for node_id, next_partitions in six.iteritems(fetchable):
@@ -761,14 +768,18 @@ class Fetcher(six.Iterator):
761
768
 
762
769
  if self._sensors:
763
770
  self._sensors.fetch_latency.record((time.time() - send_time) * 1000)
764
- self._nodes_with_pending_fetch_requests.remove(node_id)
765
771
 
766
772
  def _handle_fetch_error(self, node_id, exception):
767
773
  level = logging.INFO if isinstance(exception, Errors.Cancelled) else logging.ERROR
768
774
  log.log(level, 'Fetch to node %s failed: %s', node_id, exception)
769
775
  if node_id in self._session_handlers:
770
776
  self._session_handlers[node_id].handle_error(exception)
771
- self._nodes_with_pending_fetch_requests.remove(node_id)
777
+
778
+ def _clear_pending_fetch_request(self, node_id, _):
779
+ try:
780
+ self._nodes_with_pending_fetch_requests.remove(node_id)
781
+ except KeyError:
782
+ pass
772
783
 
773
784
  def _parse_fetched_data(self, completed_fetch):
774
785
  tp = completed_fetch.topic_partition
kafka/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '2.2.2'
1
+ __version__ = '2.2.3'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kafka-python
3
- Version: 2.2.2
3
+ Version: 2.2.3
4
4
  Summary: Pure Python client for Apache Kafka
5
5
  Author-email: Dana Powers <dana.powers@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/dpkp/kafka-python
@@ -1,14 +1,14 @@
1
1
  kafka/__init__.py,sha256=4dvHKZAxmD_4tfJ5wGcRV2X78vPcm8vsUoqceULevjA,1077
2
2
  kafka/client_async.py,sha256=joZB3AnL1mLwvV5fv61Pqn8mkP90FVvzcZ2tZsTGmvM,57060
3
- kafka/cluster.py,sha256=f9VNkWanz8X2Rn67XDdmunfx5aJ4s35JUsF5VYJ5hvk,16143
3
+ kafka/cluster.py,sha256=N3_Al4We4ZhWzz6lVHy6SfqwDZfQy73iV7Qg4g4nxRs,16745
4
4
  kafka/codec.py,sha256=8NZpnehzNrhSBIjzbPVSvyFbSeLAqEntE7BfVHu-_9I,10036
5
- kafka/conn.py,sha256=IdWJTEYTalvsmnT74P0eu1Jzx6YdPyemvQovRoBQ8NM,70019
5
+ kafka/conn.py,sha256=pDmzcn-m8oiFdvYh-97qbRLEBXh0sSl9nT74VIIRuEE,69472
6
6
  kafka/errors.py,sha256=J3R7z2hkbWA1hsD-bGHdRjcz6BYjP6RNVSQswA2UMmE,33749
7
7
  kafka/future.py,sha256=ZQStbfUYIPJRrgMfAWxxjrIRVxsw4WCtSR0J0bkyGno,2847
8
8
  kafka/socks5_wrapper.py,sha256=6woOaCTJXJ5e89_zdyW5BjOpyE4rCbYFH-kd-FeuPuk,9827
9
9
  kafka/structs.py,sha256=SJGzmLdV21jZyQ7247k0WFy16UiusgTHK3I-e4qzI-E,3058
10
10
  kafka/util.py,sha256=LV6BlELC8-889FpWM1RECX25sccoVrY2U0r5dRZjLNo,3781
11
- kafka/version.py,sha256=jsJ9CNIuUt8dDFB4i0PiBf07nzBU0RtG1CVRQ7TdoQ0,22
11
+ kafka/version.py,sha256=imyOcBgptJng0fWUAVwWSHYVE3csDgLCIYFSbnvEA-U,22
12
12
  kafka/admin/__init__.py,sha256=S_XxqyyV480_yXhttK79XZqNAmZyXRjspd3SoqYykE8,720
13
13
  kafka/admin/acl_resource.py,sha256=ak_dUsSni4SyP0ORbSKenZpwTy0Ykxq3FSt_9XgLR8k,8265
14
14
  kafka/admin/client.py,sha256=RabA8l8Im3iBEXgPVkiofNW6QyeatQHaymBWFZ8Sxkw,78929
@@ -23,7 +23,7 @@ kafka/benchmarks/record_batch_compose.py,sha256=CnUreNg1lUT0Qx9enmSr-THmBl9PjVMf
23
23
  kafka/benchmarks/record_batch_read.py,sha256=vlFaWU2YWI379n_2M8qieb_S2uHUWKV0NquEYy5b-Ho,2184
24
24
  kafka/benchmarks/varint_speed.py,sha256=s4CuvKgDZL-_zna5E3vM8RgHjhXuW6pcaO1z1WYZ_0Y,12585
25
25
  kafka/consumer/__init__.py,sha256=NDdvtyuJgFyQZahqL9i5sYXGP6rOMIXWwHQEaZ1fCcs,122
26
- kafka/consumer/fetcher.py,sha256=0SUg8_8W0b-sVDg8dMq06ydR3P_mIGvUwxfbYI8cUIE,67963
26
+ kafka/consumer/fetcher.py,sha256=EP7SHDS35BaIa3TqAu8GbI1HG8An15twGc9zia6LZ9M,68584
27
27
  kafka/consumer/group.py,sha256=Jvoal4SdOniweXeUhhYR_HxDUJmmUiKf4WrI_tuJfCQ,58857
28
28
  kafka/consumer/subscription_state.py,sha256=f_qJQMhTWQnUd_7lPj43gsagWSKGEmP4jpnEwA6s1Ec,23661
29
29
  kafka/coordinator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -120,7 +120,7 @@ kafka/vendor/enum34.py,sha256=-u-lxAiJMt6ru4Do7NUDY9OpeWkYJMksb2xengJawFE,31204
120
120
  kafka/vendor/selectors34.py,sha256=gxejLO4eXf8mRSGXaQiknPig3GdX1rtsZiYOQJVuAy8,20594
121
121
  kafka/vendor/six.py,sha256=lLBa9_HrANP5BMZ7twEzg1M3wofwPmXyptuWmHX0brY,34826
122
122
  kafka/vendor/socketpair.py,sha256=Fi3PoY1Okkppab720wFk1BhHXyjcw7hi5DwhqrYZH2Y,2737
123
- kafka_python-2.2.2.dist-info/METADATA,sha256=EuIBIkLV9AnC3o6uwA2Q958lceSJRuqr3AJw3gYyoKE,9951
124
- kafka_python-2.2.2.dist-info/WHEEL,sha256=_itY3bZllKbLk93i0gzNzdweAt5eocJdfN7atrjOnvQ,109
125
- kafka_python-2.2.2.dist-info/top_level.txt,sha256=IivJz7l5WHdLNDT6RIiVAlhjQzYRwGqBBmKHZ7WjPeM,6
126
- kafka_python-2.2.2.dist-info/RECORD,,
123
+ kafka_python-2.2.3.dist-info/METADATA,sha256=5rHeRnLYzvBgmUIntERI45fmOmLAcZtPttVu2DDDZTs,9951
124
+ kafka_python-2.2.3.dist-info/WHEEL,sha256=_itY3bZllKbLk93i0gzNzdweAt5eocJdfN7atrjOnvQ,109
125
+ kafka_python-2.2.3.dist-info/top_level.txt,sha256=IivJz7l5WHdLNDT6RIiVAlhjQzYRwGqBBmKHZ7WjPeM,6
126
+ kafka_python-2.2.3.dist-info/RECORD,,