question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] KafkaConsumer.position() Method should give the offset one larger than the last record

See original GitHub issue

Describe the bug According to Kafka Conusmer API Doc: https://kafka.apache.org/22/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html

The position of the consumer gives the offset of the next record that will be given out. It will be one larger than the highest offset the consumer has seen in that partition. It automatically advances every time the consumer receives messages in a call to poll(Duration).

While currently, KoP will return the offset of the last record, without adding one to it

To Reproduce Steps to reproduce the behavior:

  1. Suscribe to a Kafka topic or a KoP topic
  2. Call conusmer.seekToEnd() and then print conusmer.position() result
  3. Kafka will return the offset one larger than last record, while KoP not.

Expected behavior KafkaConsumer.position() Method should give the offset one larger than the last record

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
BewareMyPowercommented, Dec 21, 2020

Got it. I’ll try to fix this issue after KoP 2.7.0 is released.


and I’am a little comfused why we need to request.offset - 1 when fetch.

When Kafka handles fetch requests, it reads data from request.offset.

However when KoP handles fetch requests, the workflow is:

  1. Convert request.offset to a message id;
  2. Read data after the message id.

Kafka consumer maintains an internal offset to construct FETCH request. The offset will be updated after resetOffsetsAsync. Currently KoP returns a latestOffset not latestOffset + 1 if consumer resets offset to latest. If we change it to latestOffset + 1, the consumer may fetch after latestOffset + 1.

0reactions
WalterMacommented, Dec 21, 2020

As for how to fix this issure, please allow me to make a few comments. I’am not familiar with this project, so if any wrong, please correct me.

Can we add one to lastOffset only for the postsion() request ?

when consumer send FETCH requests, KoP did like fetchFromOffset(request.offset - 1)

, and I’am a little comfused why we need to request.offset - 1 when fetch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KafkaConsumer Position() vs Committed() - Stack Overflow
It will be one larger than the highest offset the consumer has seen in that partition. It automatically advances every time the consumer ......
Read more >
KafkaConsumer (kafka 2.4.0 API)
The position of the consumer gives the offset of the next record that will be given out. It will be one larger than...
Read more >
Apache Kafka Offset Management - Learning Journal
The offset is a simple integer number that is used by Kafka to maintain the current position of a consumer. That's it. The...
Read more >
Chapter 4. Kafka Consumers: Reading Data from Kafka
Applications that need to read data from Kafka use a KafkaConsumer to ... If the committed offset is larger than the offset of...
Read more >
KafkaConsumer (clients 5.3.0-ccs API)
The position of the consumer gives the offset of the next record that will be given out. It will be one larger than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found