Exemplo n.º 1
0
    def _get_partition(self, kc):
        def get_partition():
            meta = kc.metadata()
            topics = meta["topics"]
            assert len(topics) == 1
            assert topics[0]["topic"] == self.topic
            partition = random.choice(topics[0]["partitions"])
            return partition["leader"] > 0, partition

        return wait_until_result(get_partition,
                                 timeout_sec=30,
                                 backoff_sec=2,
                                 err_msg="No partition with leader available")
Exemplo n.º 2
0
    def get_partition_leader(self, topic, partition, timeout_sec=None):
        """
        :param topic: string, topic name
        :param partition: integer
        :param timeout_sec: wait for leader (if falsey return immediately)
        :return: 2-tuple of (leader id or None, list of replica broker IDs)
        """
        if not timeout_sec:
            return self._get_partition_leader(topic, partition)

        def get_leader():
            leader = self._get_partition_leader(topic, partition)
            return leader[0] is not None, leader

        return wait_until_result(get_leader,
                                 timeout_sec=timeout_sec,
                                 backoff_sec=2)
Exemplo n.º 3
0
    def wait_stable_configuration(
            self,
            topic,
            partition=0,
            namespace="kafka",
            replication=None,
            timeout_s=10,
            hosts: Optional[list[str]] = None) -> PartitionDetails:
        """
        Method waits for timeout_s until the configuration is stable and returns it.
        
        When the timeout is exhaust it throws TimeoutException
        """
        if hosts == None:
            hosts = [n.account.hostname for n in self.redpanda.nodes]
        hosts = list(hosts)

        def get_stable_configuration():
            random.shuffle(hosts)
            msg = ",".join(hosts)
            self.redpanda.logger.debug(
                f"wait details for {namespace}/{topic}/{partition} from nodes: {msg}"
            )
            try:
                info = self._get_stable_configuration(hosts,
                                                      topic,
                                                      partition=partition,
                                                      namespace=namespace,
                                                      replication=replication)
                if info == None:
                    return False
                return True, info
            except RequestException:
                self.redpanda.logger.exception(
                    "an error on getting stable configuration, retrying")
                return False

        return wait_until_result(
            get_stable_configuration,
            timeout_sec=timeout_s,
            backoff_sec=1,
            err_msg=
            f"can't fetch stable replicas for {namespace}/{topic}/{partition} within {timeout_s} sec"
        )