Skip to content
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

fix: Use separate variable to track the consume offset #15095

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/kafka/partition/reader_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,16 @@ func (s *ReaderService) starting(ctx context.Context) error {

if lastCommittedOffset == int64(KafkaEndOffset) {
level.Warn(s.logger).Log("msg", fmt.Sprintf("no committed offset found, starting from %d", kafkaStartOffset))
lastCommittedOffset = int64(KafkaStartOffset)
} else {
level.Debug(s.logger).Log("msg", "last committed offset", "offset", lastCommittedOffset)
}

consumeOffset := int64(kafkaStartOffset)
if lastCommittedOffset >= 0 {
lastCommittedOffset++ // We want to begin to read from the next offset, but only if we've previously committed an offset.
// Read from the next offset.
consumeOffset = lastCommittedOffset + 1
}

s.reader.SetOffsetForConsumption(lastCommittedOffset)
s.reader.SetOffsetForConsumption(consumeOffset)

if targetLag, maxLag := s.cfg.TargetConsumerLagAtStartup, s.cfg.MaxConsumerLagAtStartup; targetLag > 0 && maxLag > 0 {
consumer, err := s.consumerFactory(s.committer)
Expand Down
Loading