-
Notifications
You must be signed in to change notification settings - Fork 55
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
Can alter offsets on RebalanceBeforeAssign. #180
Open
robinp
wants to merge
1
commit into
haskell-works:main
Choose a base branch
from
robinp:fix-things
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some code to guarantee that all (and only) the partitions from the "original" assignment are passed to
rdKafkaAssign
?Currently there is a possibility for me to return
Just
a subset (or a superset) of the partitions. Which may cause problems.But if we take a list of
altered
partitions, add the "missing" ones and remove "extra" ones then it should be fine?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robinp ping ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sorry for the late reply. How about returning
IO (Maybe (TopicPartition -> Maybe PartitionOffset))
, where an inner Nothing result would mean "don't change offset". This leaves no questions what can and can't be done.If this sounds right for you and have the capacity, I don't mind you adding to the PR. Otherwise feel free to defer to me, just expect slight delay. Thanks for looking at this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robinp Hmm... From one side - yes... From the other side, do we know that we can demand a pure function here?
Perhaps
IO (Maybe (TopicPartition -> IO (Maybe PartitionOffset)))
, but it gets clunky...In my mind the original semantics
IO (Maybe [TopicPartition])
would read as "give me all you know and I'll do what I can". I.E. I could always return all the offsets of for all the partitions (for the whole topic) if I wanted, but the internals of the callback would figure out the applicable ones for a given consumer in a group...For that I would even suggest simplifying it to
IO [TopicPartition]
and say that "we will use offsets that you provide for the partitions that we actually assign" and that'd be it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IO-in-IO is not really needed, since the callback already runs in IO, it can query whatever it needs in IO, create the pure structures, and return the offset function based on those pure structures. That practically says, by the time the callback returns, it made up its mind about the offset decisions it would take.
Returning a
[TopicPartition]
would be deceiving, since suggests it would be used as-is, but as you say, we would need to make adjustments to it to fulfill the Kafka contract.If we want to cut down on the typesig a bit, then
IO (TopicPartition -> Maybe PartitionOffset)
can work, as one can always returnconst Nothing
, but an alias likedontOverrideOffsets
can be added as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, we can compute all the offsets and then construct a pure function and return it... That won't even need the first
Maybe
in this case,IO (TopicPartition -> Maybe PartitionOffset)
would be sufficient...Or perhaps even
IO (TopicPartition -> PartitionOffset)
since we can always project the original offset into the new one... But I see how this redundantMaybe
can be appealing here...Well, I myself would be happy with just
IO [TopicPartition]
+ merging, since it would be (to me) the most convenient for usage at the price of one bit of knowledge: the returned list cannot alter the list of partitions that are going to be assigned.But I am not against
IO (TopicPartition -> Maybe PartitionOffset)
orIO (TopicPartition -> PartitionOffset)
, too.One thing that we could do is to keep
setRebalanceCallback
signature the way it was before, and introducesetRebalanceCallbackWithOffsets
with the new signature.setRebalanceCallback
then could just delegate to the new function with a function that doesn't change offsets.This will allow us to avoid introducing a breaking change.
Do you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That transition path for smooth upgrade sounds nice.
Yeah, I like
IO (TopicPartition -> Maybe PartitionOffset)
because I can justconst Nothing
without having to do a mental exercise of thinking "Can I always return latest? Or unassigned? Or gather the specific value that is available?". I can trustNothing
to do the right thing, hopefully.Could drop that Maybe, but then some clear guidance is needed in the function doc which value should be returned. Wondering if there's "one true way", in which case rather implement that + have the Maybe, or if there's value in maintaining freedom about multiple behaviors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's settle on something like
I guess that it'll be close enough to the best of both having this feature and not breaking compatibility for consumers who don't care about the offsets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!