簡體   English   中英

Spark 設置為從最早的偏移量讀取 - 在嘗試使用 Kafka 上不再可用的偏移量時拋出錯誤

[英]Spark set to read from earliest offset - throws error on attempting to consumer an offset no longer available on Kafka

我目前正在 Dataproc 上運行 spark 作業,在嘗試重新加入組並從 kafka 主題讀取數據時遇到錯誤。 我做了一些挖掘,但不確定問題出在哪里。 我將auto.offset.reset設置為earliest ,因此它應該從最早可用的未提交偏移量讀取,最初我的火花日志如下所示:

19/04/29 16:30:30 INFO     
org.apache.kafka.clients.consumer.internals.Fetcher: [Consumer 
clientId=consumer-1, groupId=demo-group] Resetting offset for 
partition demo.topic-11 to offset 5553330.
19/04/29 16:30:30 INFO     
org.apache.kafka.clients.consumer.internals.Fetcher: [Consumer 
clientId=consumer-1, groupId=demo-group] Resetting offset for 
partition demo.topic-2 to offset 5555553.
19/04/29 16:30:30 INFO 
org.apache.kafka.clients.consumer.internals.Fetcher: [Consumer 
clientId=consumer-1, groupId=demo-group] Resetting offset for 
partition demo.topic-3 to offset 5555484.
19/04/29 16:30:30 INFO 
org.apache.kafka.clients.consumer.internals.Fetcher: [Consumer 
clientId=consumer-1, groupId=demo-group] Resetting offset for 
partition demo.topic-4 to offset 5555586.
19/04/29 16:30:30 INFO 
org.apache.kafka.clients.consumer.internals.Fetcher: [Consumer 
clientId=consumer-1, groupId=demo-group] Resetting offset for 
partition demo.topic-5 to offset 5555502.
19/04/29 16:30:30 INFO 
org.apache.kafka.clients.consumer.internals.Fetcher: [Consumer 
clientId=consumer-1, groupId=demo-group] Resetting offset for 
partition demo.topic-6 to offset 5555561.
19/04/29 16:30:30 INFO 
org.apache.kafka.clients.consumer.internals.Fetcher: [Consumer 
clientId=consumer-1, groupId=demo-group] Resetting offset for 
partition demo.topic-7 to offset 5555542.```

但是接下來的一行我在嘗試從服務器上不存在的偏移量中讀取時遇到錯誤(您可以看到分區的偏移量與上面列出的不同,所以我不知道為什么它會嘗試讀取表單該偏移量,這是下一行的錯誤:

org.apache.kafka.clients.consumer.OffsetOutOfRangeException: Offsets 
out of range with no configured reset policy for partitions: 
{demo.topic-11=4544296}

關於為什么我的 spark 作業不斷回到此偏移量 (4544296) 而不是它最初輸出的偏移量 (5553330) 的任何想法?

它似乎自相矛盾 wa) 它說的實際偏移量和它試圖讀取的偏移量和 b) 說沒有配置的重置策略

這個答案晚了一年,但希望能幫助其他面臨類似問題的人。

通常,當消費者嘗試讀取 Kafka 主題中不再存在的偏移量時,就會顯示此行為。 偏移量不再存在,通常是因為它已被 Kafka Cleaner 刪除(例如,由於保留或壓縮策略)。 但是,Kafka 仍然知道 Consumer Group,並且 Kafka 為主題“demo.topic”及其所有分區保留了組“demo-group”的最新消費消息的信息。

因此, auto.offset.reset配置沒有任何影響,因為不需要重置。 相反,Kafka 知道消費者組。

此外, Fetcher只告訴您主題的每個分區內的最新可用偏移量。 並不自動意味着它實際輪詢直到該偏移量的所有消息。 Spark 決定它實際為每個分區消耗和處理多少消息(基於例如配置maxRatePerPartition )。

要解決此問題,您可以更改消費者組(在這種特定情況下可能不是您想要的)或通過使用手動重置消費者組“demo-group”的偏移量

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --reset-offsets --group demo-group --topic demo.topic --partition 11 --to-latest

根據您的要求,您可以使用該工具為主題的每個分區重置偏移量。 幫助功能或文檔解釋了所有可用選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM