Skip to content

KafkaItemReader reset offset to zero for new job instance #3631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gmadalon opened this issue Dec 18, 2019 · 6 comments
Closed

KafkaItemReader reset offset to zero for new job instance #3631

gmadalon opened this issue Dec 18, 2019 · 6 comments
Labels
status: duplicate Issues that are duplicates of other issues

Comments

@gmadalon
Copy link

OBSERVED BEHAVIOR

KafkaItemReader always reset offset to zero even when the last job execution was finished OK.
So, if my batch runs every night to process a Kafka topic it doesn't work because it will read all messages every night not just the messages not processed.

ROOT CAUSE

KafkaItemReader line 248:

	for (TopicPartition topicPartition : this.topicPartitions) {
		this.partitionOffsets.put(topicPartition, 0L);
	}

PROPOSED SOLUTIONS

Remove these lines and don't set offset to 0 anymore.

@fmbenhassine fmbenhassine added the status: waiting-for-triage Issues that we did not analyse yet label Dec 20, 2019
@alexisgra
Copy link

Looks like someone fixed the problem in this PR : #737 , the fix should be embedded in version 4.3.0.

@gmadalon
Copy link
Author

gmadalon commented Jan 28, 2020

Hi @alexisgra,
You are right, thank you for your comment.
I'll close this issue.

@fmbenhassine fmbenhassine added status: duplicate Issues that are duplicates of other issues and removed status: waiting-for-triage Issues that we did not analyse yet labels Jan 5, 2021
@Vickd811
Copy link

Hi, I am still observing this behaviour. I have 4.3.3 version of Spring-Batch, I am running it with Spring boot parent 2.5.0.
With auto.offset.reset set as "earliest" when i restart my server, it goes back to offset 0. if i keep value to "latest", it does not read anything until messages are published while batch is active. I am using MapJobRepository with spring-batch, no database for storing spring execution context. Sorry, to comment on a closed thread, i am totally stuck on it.

@fmbenhassine
Copy link
Contributor

@Vickd811 please check this answer on StackOverflow: https://stackoverflow.com/a/65882465/5019386. If you still need support, please add a comment on that SO thread or ask a new question on SO. Thank you.

@Vickd811
Copy link

Vickd811 commented Sep 9, 2021

Thanks @benas , it resolved the issue. The other behavior i am observing is re-process of last processed offset for a fixed delay scheduled job. So, i am using kafka reader for one of my job where i need to submit the job after every 10 seconds of previous job completion. It is scheduled with a fixed delay, so once first instance of the job is completed, scheduler submits another instance after 10 seconds, the second instance is still picking up the last offset of previous job run. Would you know how to circumvent this? It doesn’t happen when I completely kill the process and restart.

@fmbenhassine
Copy link
Contributor

@Vickd811 Glad it helped. For the other question, please ask it on StackOverflow. We would like to keep the issue tracker exclusively for bug reports and feature requests, see https://github.com/spring-projects/spring-batch/blob/main/SUPPORT.md. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate Issues that are duplicates of other issues
Projects
None yet
Development

No branches or pull requests

4 participants