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

Added Consumer.OffsetsStore() #72

Merged
merged 4 commits into from
Aug 8, 2017

Conversation

ctrochalakis
Copy link
Contributor

Expose librdkafka's rd_kafka_offsets_store() introduced in v0.11.0 (not yet released).

Consumer.OffsetsStore() allows manual control over the committed offsets without sacrificing auto-commit functionality.

I am not sure if returning the storedOffsets is the correct thing to do, we could stop returning them to keep the API cleaner, or return a list of the failed TopicPartitions.

@ghost
Copy link

ghost commented Jul 10, 2017

@confluentinc It looks like @ctrochalakis just signed our Contributor License Agreement. 👍

Always at your service,

clabot

Expose librdkafka's `rd_kafka_offsets_store()` introduced in v0.11.0.

Consumer.OffsetsStore() allows manual control over the committed offsets
without sacrificing auto-commit functionality.
@edenhill
Copy link
Contributor

Thank you for this, will tend to it shortly.

Copy link
Contributor

@edenhill edenhill left a comment

Choose a reason for hiding this comment

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

Good stuff, just some minor tweaks needed

// Returns the stored offsets on success. If at least one offset couldn't be stored,
// an error and a list of offsets is returned. Each offset can be checked for
// specific errors via its `.Error` member.
func (c *Consumer) OffsetsStore(offsets []TopicPartition) (storedOffsets []TopicPartition, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be called StoreOffsets to be consistent with CommitOffsets (even though it makes it inconsistent with librdkafka, but that's a hidden gem).

@@ -54,7 +54,6 @@ func TestConsumerAPIs(t *testing.T) {
if err != nil {
t.Errorf("SubscribeTopics failed: %s", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove whitespace diff

t.Errorf("OffsetsStore() TopicPartition error: %s", toppar.Error)
}
}
stored, err = c.OffsetsStore(nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a use for accepting a nil partition set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nil is a valid value for a slice, in fact it is the default value. I wanted to make sure it is explicitly handled. In the fixup I changed that to an uninitialized (default) slice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, the data type allows it, but is there a point for the StoreOffsets API to allow it? Passing a nil slice should be considered a usage error and not something we need to explicitly handle (I do agree that error handling is necessary, but parameter checking in APIs is not as fruitful as it seems IMHO unless there is a security concern to it).

Copy link
Contributor Author

@ctrochalakis ctrochalakis Aug 8, 2017

Choose a reason for hiding this comment

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

Let's call it an empty slice. I think that the API should allow passing an empty slice, whatever that means in Go. If someone chooses to pass an empty slice no error is returned. We don't explicitly handle it (as in consumer.go code) but we explicitly test that an empty []TopicPartition is properly treated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that this part of the diff is now changed to:

        var empty []TopicPartition
        stored, err = c.StoreOffsets(empty)

which seems like a valid usage scenario.

Copy link
Contributor

@edenhill edenhill left a comment

Choose a reason for hiding this comment

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

LGTM

@edenhill edenhill merged commit e093d2b into confluentinc:master Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants