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

feat: add option to propagate OffsetOutOfRange error #2252

Merged
Merged
Show file tree
Hide file tree
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: 10 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,17 @@ type Config struct {
// coordinator for the group.
UserData []byte
}

// support KIP-345
InstanceId string

// If true, consumer offsets will be automatically reset to configured Initial value
// if the fetched consumer offset is out of range of available offsets. Out of range
// can happen if the data has been deleted from the server, or during situations of
// under-replication where a replica does not have all the data yet. It can be
// dangerous to reset the offset automatically, particularly in the latter case. Defaults
// to true to maintain existing behavior.
ResetInvalidOffsets bool
}

Retry struct {
Expand Down Expand Up @@ -499,6 +508,7 @@ func NewConfig() *Config {
c.Consumer.Group.Rebalance.Timeout = 60 * time.Second
c.Consumer.Group.Rebalance.Retry.Max = 4
c.Consumer.Group.Rebalance.Retry.Backoff = 2 * time.Second
c.Consumer.Group.ResetInvalidOffsets = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment says "default to true" but it's not reflected here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter is so dangerous. It should be true by default.
If this parameter is false, the resetting of offsets is invalid, which can cause an infinite loop of closing and adding subscriptions.


c.ClientID = defaultClientID
c.ChannelBufferSize = 256
Expand Down
3 changes: 2 additions & 1 deletion consumer_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,8 @@ type consumerGroupClaim struct {

func newConsumerGroupClaim(sess *consumerGroupSession, topic string, partition int32, offset int64) (*consumerGroupClaim, error) {
pcm, err := sess.parent.consumer.ConsumePartition(topic, partition, offset)
if errors.Is(err, ErrOffsetOutOfRange) {

if errors.Is(err, ErrOffsetOutOfRange) && sess.parent.config.Consumer.Group.ResetInvalidOffsets {
offset = sess.parent.config.Consumer.Offsets.Initial
pcm, err = sess.parent.consumer.ConsumePartition(topic, partition, offset)
}
Expand Down