use of kafka.javaapi.OffsetFetchResponse in project voltdb by VoltDB.
the class KafkaTopicPartitionImporter method getLastOffset.
public long getLastOffset() {
final int partition = m_topicAndPartition.partition();
final String topic = m_topicAndPartition.topic();
OffsetResponse response = getTopicOffset(EARLIEST_OFFSET);
if (response == null)
return -1L;
long earliest = response.offsets(topic, partition)[0];
response = getTopicOffset(LATEST_OFFSET);
if (response == null)
return -1L;
long latest = response.offsets(topic, partition)[0];
if (latest == earliest)
return latest;
OffsetFetchResponse ofr = getClientTopicOffset();
if (ofr == null)
return earliest;
long current = ofr.offsets().get(m_topicAndPartition).offset();
if (current < earliest)
return earliest;
if (current < latest)
return current;
return latest;
}
use of kafka.javaapi.OffsetFetchResponse 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;
}
Aggregations