Search in sources :

Example 1 with HostAndPort

use of org.voltdb.importclient.kafka.KafkaStreamImporterConfig.HostAndPort in project voltdb by VoltDB.

the class KafkaTopicPartitionImporter method resetLeader.

private void resetLeader() {
    KafkaStreamImporterConfig.closeConsumer(m_consumer);
    m_consumer = null;
    HostAndPort leaderBroker = findNewLeader();
    if (leaderBroker == null) {
        //point to original leader which will fail and we fall back again here.
        rateLimitedLog(Level.WARN, null, "Fetch Failed to find leader continue with old leader: " + m_config.getPartitionLeader());
        leaderBroker = m_config.getPartitionLeader();
    } else {
        if (!leaderBroker.equals(m_config.getPartitionLeader())) {
            info(null, "Fetch Found new leader for " + m_topicAndPartition + " New Leader: " + leaderBroker);
            m_config.setPartitionLeader(leaderBroker);
        }
    }
    m_consumer = new SimpleConsumer(leaderBroker.getHost(), leaderBroker.getPort(), m_config.getSocketTimeout(), m_config.getFetchSize(), KafkaStreamImporterConfig.CLIENT_ID);
}
Also used : HostAndPort(org.voltdb.importclient.kafka.KafkaStreamImporterConfig.HostAndPort) SimpleConsumer(kafka.javaapi.consumer.SimpleConsumer)

Example 2 with HostAndPort

use of org.voltdb.importclient.kafka.KafkaStreamImporterConfig.HostAndPort in project voltdb by VoltDB.

the class KafkaTopicPartitionImporter method findNewLeader.

//Find leader for this topic partition.
private HostAndPort findNewLeader() {
    for (int i = 0; i < 3; i++) {
        boolean shouldSleep = false;
        PartitionMetadata metadata = findLeader();
        if (metadata == null) {
            shouldSleep = true;
        } else if (metadata.leader() == null) {
            shouldSleep = true;
        } else if (m_config.getPartitionLeader().getHost().equalsIgnoreCase(metadata.leader().host()) && i == 0) {
            // first time through if the leader hasn't changed give ZooKeeper a second to recover
            // second time, assume the broker did recover before failover, or it was a non-Broker issue
            shouldSleep = true;
        } else {
            return new HostAndPort(metadata.leader().host(), metadata.leader().port());
        }
        if (shouldSleep) {
            backoffSleep(i + 1);
        }
    }
    //Unable to find return null for recheck.
    rateLimitedLog(Level.WARN, null, "Failed to find new leader for " + m_topicAndPartition);
    return null;
}
Also used : HostAndPort(org.voltdb.importclient.kafka.KafkaStreamImporterConfig.HostAndPort) PartitionMetadata(kafka.javaapi.PartitionMetadata)

Aggregations

HostAndPort (org.voltdb.importclient.kafka.KafkaStreamImporterConfig.HostAndPort)2 PartitionMetadata (kafka.javaapi.PartitionMetadata)1 SimpleConsumer (kafka.javaapi.consumer.SimpleConsumer)1