Search in sources :

Example 1 with OffsetFetchRequest

use of kafka.javaapi.OffsetFetchRequest in project voltdb by VoltDB.

the class KafkaTopicPartitionImporter method getClientTopicOffset.

private OffsetFetchResponse getClientTopicOffset() {
    final short version = 1;
    OffsetFetchResponse rsp = null;
    Throwable fault = null;
    for (int attempts = 0; attempts < 3; ++attempts) try {
        final OffsetFetchRequest rq = new OffsetFetchRequest(m_config.getGroupId(), singletonList(m_topicAndPartition), version, nextCorrelationId(), KafkaStreamImporterConfig.CLIENT_ID);
        BlockingChannel channel = m_offsetManager.get();
        channel.send(rq.underlying());
        rsp = OffsetFetchResponse.readFrom(channel.receive().buffer());
        short code = rsp.offsets().get(m_topicAndPartition).error();
        if (code != ErrorMapping.NoError()) {
            fault = ErrorMapping.exceptionFor(code);
            backoffSleep(attempts + 1);
            if (code == ErrorMapping.NotCoordinatorForConsumerCode()) {
                getOffsetCoordinator();
            } else if (code == ErrorMapping.ConsumerCoordinatorNotAvailableCode()) {
                getOffsetCoordinator();
            } else if (code == ErrorMapping.UnknownTopicOrPartitionCode()) {
                getOffsetCoordinator();
                fault = null;
                continue;
            }
        } else {
            fault = null;
            break;
        }
    } catch (Exception e) {
        if (e instanceof IOException) {
            getOffsetCoordinator();
        }
        fault = e;
    }
    if (fault != null) {
        rateLimitedLog(Level.WARN, fault, "unable to fetch earliest offset for " + m_topicAndPartition);
        rsp = null;
    }
    return rsp;
}
Also used : OffsetFetchResponse(kafka.javaapi.OffsetFetchResponse) OffsetFetchRequest(kafka.javaapi.OffsetFetchRequest) IOException(java.io.IOException) BlockingChannel(kafka.network.BlockingChannel) FormatException(org.voltdb.importer.formatter.FormatException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 OffsetFetchRequest (kafka.javaapi.OffsetFetchRequest)1 OffsetFetchResponse (kafka.javaapi.OffsetFetchResponse)1 BlockingChannel (kafka.network.BlockingChannel)1 FormatException (org.voltdb.importer.formatter.FormatException)1