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

Clarify the behavior in the partition assigner protocol #544

Merged

Conversation

ankon
Copy link
Contributor

@ankon ankon commented Nov 5, 2019

The existing typing was off, and made it look like the user data would be provided to the protocol and assign functions as argument fields.

Reading through https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-GroupMembershipAPI and the KafkaJS code is not true at all. What actually happens is that

  1. each assigners' protocol function can provide user data (by encoding it into the result), then
  2. Kafka will select a leader, and provide that one in the JoinGroupResponse with an array of all members and the metadata they provided, which
  3. the group leader will then process through the assign function. At this point it can take the user data into account, and it can produce new user data*

The first commit in this PR updates the TypeScript types to match this behavior and adds a integration test to demonstrate it, the second commit then cleans up the roundRobinAssigner's code to remove the "obviously unused" argument fields.


@ankon
Copy link
Contributor Author

ankon commented Nov 7, 2019

#231 may need to be reviewed: It added the userData parameter in some places where this PR removes it again from.

The user data isn't provided to the 'assign' function as field in the argument object, but rather it is
part of the 'members' array.

This commit adds an integration test showing how to use the user data.
This assigner doesn't use the user data, and with the previous commit is also clear that the data isn't
provided as fields in the argument objects, but rather would have been produced here.
@ankon ankon force-pushed the pr/clarify-assigner-user-data-behavior branch from 8611713 to 354437e Compare January 2, 2020 09:13
@ankon
Copy link
Contributor Author

ankon commented Jan 2, 2020

This looks "big", but is actually just typing fixes + a unit test that this actually "works".

@@ -59,18 +63,16 @@ module.exports = ({ cluster }) => ({
memberAssignment: MemberAssignment.encode({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it provide the userData for that member in the MemberAssignment? The only difference is that the assign method gets the userData from each member (as memberMetadata). Maybe I'm missing something.

Copy link
Contributor Author

@ankon ankon Jan 6, 2020

Choose a reason for hiding this comment

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

The user data is part of the members, encoded into the memberMetadata by the protocol function.

The protocol function decides about the user data (in the RR assigner: nothing), and sends that to the broker as part of the member metadata. The broker then collects the members (and their metadata), and triggers the assign call (for the selected leader). The assign function implementation then can pull out the user data from the provided content.

The flow is indeed a bit odd, and I was arguing with myself here whether to leave some references lying around, but ultimately the RR assigner doesn't use any user data, and having it here is just confusing. Instead I added the unit test to show how to pass user data. Maybe a "how to write your own assigner" article could also help.

@Nevon
Copy link
Collaborator

Nevon commented Jan 5, 2020

Sorry that it's taking forever to get this reviewed. I'm on vacation at the moment, and I suspect Tulio has his plate full.

@Nevon Nevon merged commit 1904481 into tulios:master Jan 8, 2020
@ankon ankon deleted the pr/clarify-assigner-user-data-behavior branch January 8, 2020 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants