无法在zookeeper中保存kafka偏移量

时间:2015-11-24 15:32:47

标签: java apache-kafka centos7 hortonworks-data-platform

我已经在CentoS 7上安装了Ambari的Zookeeper和Kafka。

Ambari版本:2.1.2.1
Zookeeper版本:3.4.6.2.3
卡夫卡版本:0.8.2.2.3
Java Kafka客户端:kafka_2.10,0.8.2.2

我尝试使用以下代码保存Kafka偏移量:

SimpleConsumer simpleConsumer = new SimpleConsumer(host, port, soTimeout, bufferSize, clientId);
TopicAndPartition topicAndPartition = new TopicAndPartition(topicName, partitionId);
Map<TopicAndPartition, OffsetAndMetadata> requestInfo = new HashMap<>();
requestInfo.put(topicAndPartition, new OffsetAndMetadata(readOffset, "", ErrorMapping.NoError()));
OffsetCommitRequest offsetCommitRequest = new OffsetCommitRequest(groupName, requestInfo, correlationId, clientName, (short)0);
simpleConsumer.commitOffsets(offsetCommitRequest);
simpleConsumer.close();

但是当我运行它时,我的客户端出现以下错误:

java.io.EOFException: Received -1 when reading from channel, socket has likely been closed.

同样在Kafka日志中,我有以下错误:

[2015-11-24 15:38:53,566] ERROR Closing socket for /192.168.186.1 because of error (kafka.network.Processor)
java.nio.BufferUnderflowException
    at java.nio.Buffer.nextGetIndex(Buffer.java:498)
    at java.nio.HeapByteBuffer.getLong(HeapByteBuffer.java:406)
    at kafka.api.OffsetCommitRequest$$anonfun$1$$anonfun$apply$1.apply(OffsetCommitRequest.scala:73)
    at kafka.api.OffsetCommitRequest$$anonfun$1$$anonfun$apply$1.apply(OffsetCommitRequest.scala:68)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.immutable.Range.foreach(Range.scala:141)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at kafka.api.OffsetCommitRequest$$anonfun$1.apply(OffsetCommitRequest.scala:68)
    at kafka.api.OffsetCommitRequest$$anonfun$1.apply(OffsetCommitRequest.scala:65)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    at scala.collection.immutable.Range.foreach(Range.scala:141)
    at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
    at scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
    at kafka.api.OffsetCommitRequest$.readFrom(OffsetCommitRequest.scala:65)
    at kafka.api.RequestKeys$$anonfun$9.apply(RequestKeys.scala:47)
    at kafka.api.RequestKeys$$anonfun$9.apply(RequestKeys.scala:47)
    at kafka.network.RequestChannel$Request.<init>(RequestChannel.scala:55)
    at kafka.network.Processor.read(SocketServer.scala:547)
    at kafka.network.Processor.run(SocketServer.scala:405)
    at java.lang.Thread.run(Thread.java:745)

现在我还从https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.2.2/kafka_2.10-0.8.2.2.tgz下载并安装了官方的Kafka 0.8.2.2版本,它运行正常;您可以保存Kafka偏移量而不会出现任何错误。

任何人都可以给我一些指示,为什么Ambari Kafka未能保存偏移?

P.S:我知道如果versionId为0(在OffsetCommitRequest中),则偏移量实际上保存在Zookeeper中。

0 个答案:

没有答案