samza 0.14.1未正确处理OffsetAutoFrangeException异常?

oiopk7p5  于 2021-06-06  发布在  Kafka
关注(0)|答案(1)|浏览(375)

我们正面临一个与本文描述的相同的问题。
这里-samza请求的kafka分区偏移量太旧(即kafka日志已向前移动)。我们正在设置属性 consumer.auto.offset.resetsmallest 因此期望samza在这种情况下将其检查点重置为最早可用的分区偏移量。但事实并非如此,我们不断收到这种形式的例外:

INFO [2018-08-21 19:26:20,924] [U:669,F:454,T:1,123,M:2,658]
kafka.producer.SyncProducer:[Logging_class:info:66] - [main] -
Disconnecting from vrni-platform-release:9092
INFO [2018-08-21 19:26:20,924] [U:669,F:454,T:1,123,M:2,658]
system.kafka.GetOffset:[Logging_class:info:63] - [main] - Validating offset
56443499 for topic and partition Topic3-0
WARN [2018-08-21 19:26:20,925] [U:669,F:454,T:1,123,M:2,658]
system.kafka.KafkaSystemConsumer:[Logging_class:warn:74] - [main] - While
refreshing brokers for Topic3-0:
org.apache.kafka.common.errors.OffsetOutOfRangeException: The requested
offset is not within the range of offsets maintained by the server..
Retrying

版本详细信息
Samza:2.11-0.14.1
Kafka客户端:1.1.0
kafka服务器:1.1.0 scala 2.11
浏览代码时,似乎 GetOffset::isValidOffset 应该能够捕获异常 OffsetOutOfRangeException 并将其转换为假值。但这似乎没有发生。是否存在不匹配 packageException ? getoffset类正在捕获异常 import kafka.common.OffsetOutOfRangeException ,但是从日志来看,这个类的包似乎是不同的。这可能是原因吗?

def isValidOffset(consumer: DefaultFetchSimpleConsumer, topicAndPartition: TopicAndPartition, offset: String) = {
    info("Validating offset %s for topic and partition %s" format (offset, topicAndPartition))

    try {
      val messages = consumer.defaultFetch((topicAndPartition, offset.toLong))

      if (messages.hasError) {
        KafkaUtil.maybeThrowException(messages.error(topicAndPartition.topic, topicAndPartition.partition).exception())
      }

      info("Able to successfully read from offset %s for topic and partition %s. Using it to instantiate consumer." format (offset, topicAndPartition))

      true
    } catch {
      case e: OffsetOutOfRangeException => false
    }
}

而且,brokerproxy类-的调用方 GetOffset 会打印日志吗 "It appears that..." 如果它得到一个假值,但它没有记录这一行(表示在 GetOffset 方法未捕获并正在向上传播):

def addTopicPartition(tp: TopicAndPartition, nextOffset: Option[String]) = {
    debug("Adding new topic and partition %s to queue for %s" format (tp, host))

    if (nextOffsets.asJava.containsKey(tp)) {
      toss("Already consuming TopicPartition %s" format tp)
    }

    val offset = if (nextOffset.isDefined && offsetGetter.isValidOffset(simpleConsumer, tp, nextOffset.get)) {
      nextOffset
        .get
        .toLong
    } else {
      warn("It appears that we received an invalid or empty offset %s for %s. Attempting to use Kafka's auto.offset.reset setting. This can result in data loss if processing continues." format (nextOffset, tp))

      offsetGetter.getResetOffset(simpleConsumer, tp)
    }

    debug("Got offset %s for new topic and partition %s." format (offset, tp))

    nextOffsets += tp -> offset

    metrics.topicPartitions.get((host, port)).set(nextOffsets.size)
  }

这可能是由于Kafka客户端库版本不匹配,我们正在使用?是否有一个推荐的kafka客户端版本我们应该与samza 0.14.1一起使用(假设kafka服务器是1.x)?
任何有关这方面的帮助都将不胜感激。

7y4bm7vi

7y4bm7vi1#

以上是samza 0.14.0和0.14.1中的一个bug。samza-1822是bug id。
samza邮件列表中也讨论了这一点。

相关问题