def _unpack_send_message(self, resp_bytes): resp = ProduceResponseStruct() resp.unpack(resp_bytes) d = resp.dump2nametuple() for topic in d.topics: for partition in topic.partitions: check_and_raise_error(partition)
def _load_metadata(self, metadata, expected_topics): log.debug('metadata %s', metadata) brokers = metadata.brokers for broker in brokers: self.brokers[broker.node_id] = broker log.debug('brokers %s', self.brokers) topics = metadata.topics for topic in topics: topic_name = topic.topic_name try: check_and_raise_error(topic) except (UnknownTopicOrPartition, LeaderNotAvailable) as e: if topic_name in expected_topics: # The topic which you requested is not exist, raise! raise log.error("Error loading topic metadata for %s: %s", topic_name, e) continue partitions = topic.partitions self.topic_to_partitions[topic.topic_name] = partitions for partition in partitions: # Check for partition errors # no leader for some of the partitions is acceptable try: check_and_raise_error(partition) except LeaderNotAvailable: log.error('No leader for topic %s partition %d', topic, partition) continue self.topic_and_partition_to_brokers[( topic.topic_name, partition.partition)] = partition.leader
def _load_metadata(self, metadata, expected_topics): log.debug('metadata %s', metadata) brokers = metadata.brokers for broker in brokers: self.brokers[broker.node_id] = broker log.debug('brokers %s', self.brokers) topics = metadata.topics for topic in topics: topic_name = topic.topic_name try: check_and_raise_error(topic) except (UnknownTopicOrPartition, LeaderNotAvailable) as e: if topic_name in expected_topics: # The topic which you requested is not exist, raise! raise log.error("Error loading topic metadata for %s: %s", topic_name, e) continue partitions = topic.partitions self.topic_to_partitions[topic.topic_name] = partitions for partition in partitions: # Check for partition errors # no leader for some of the partitions is acceptable try: check_and_raise_error(partition) except LeaderNotAvailable: log.error('No leader for topic %s partition %d', topic, partition) continue self.topic_and_partition_to_brokers[(topic.topic_name, partition.partition)] = partition.leader