Skip to content

Commit

Permalink
fix(kafka): Read from beginning if no committed offset (#14865)
Browse files Browse the repository at this point in the history
  • Loading branch information
benclive authored Nov 12, 2024
1 parent ec95ed1 commit 1b6da11
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/kafka/partition/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (p *Reader) start(ctx context.Context) error {

// We manage our commits manually, so we must fetch the last offset for our consumer group to find out where to read from.
lastCommittedOffset := p.fetchLastCommittedOffset(ctx)
if lastCommittedOffset == kafkaEndOffset {
level.Warn(p.logger).Log("msg", "no committed offset found for partition, starting from the beginning", "partition", p.partitionID, "consumer_group", p.consumerGroup)
lastCommittedOffset = kafkaStartOffset // If we haven't committed any offsets yet, we start reading from the beginning.
}
if lastCommittedOffset > 0 {
lastCommittedOffset++ // We want to begin to read from the next offset, but only if we've previously committed an offset.
}
Expand Down

0 comments on commit 1b6da11

Please sign in to comment.