You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/10/14 08:56:17 UTC
[GitHub] [kafka] showuon opened a new pull request, #12748: KAFKA-13715: add generationId field in subscription
showuon opened a new pull request, #12748:
URL: https://github.com/apache/kafka/pull/12748
KIP-792
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1024726967
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -162,6 +162,17 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
return isAllSubscriptionsEqual;
}
+ // visible for testing
+ MemberData memberDataFromSubscription(Subscription subscription) {
+ if (!subscription.ownedPartitions().isEmpty() && subscription.generationId().isPresent()) {
Review Comment:
> For instance, this could happen if the group has more members than partitions.
In that case, the `subscription.generationId()` should still contain valid number. Is that right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1013722215
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -117,30 +117,41 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
isAllSubscriptionsEqual = false;
}
- MemberData memberData = memberData(subscription);
+ Optional<Integer> generation;
+ List<TopicPartition> ownedPartitionsInMetadata;
+ if (!subscription.ownedPartitions().isEmpty() && subscription.generationId() != DEFAULT_GENERATION) {
+ // In ConsumerProtocolSubscription v2 or higher, we don't need to deserialize the byte buffer
+ // and take from fields directly
+ ownedPartitionsInMetadata = subscription.ownedPartitions();
+ generation = Optional.of(subscription.generationId());
+ } else {
+ MemberData memberData = memberData(subscription);
+ ownedPartitionsInMetadata = memberData.partitions;
+ generation = memberData.generation;
+ }
Review Comment:
It seems that we also rely on the generation in `prepopulateCurrentAssignments` so I suppose that we need a similar logic over there in order to be consistent. Do we?
Knowing this, I wonder if we should update `memberData` to get the correct generation from the subscription. That would ensure that all usages of `memberData` get the correct view. What do you think?
##########
clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerPartitionAssignor.java:
##########
@@ -138,6 +146,10 @@ public Optional<String> groupInstanceId() {
return groupInstanceId;
}
+ public int generationId() {
+ return generationId;
+ }
+
@Override
public String toString() {
Review Comment:
nit: We need to update this one to include the generation.
##########
clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerPartitionAssignor.java:
##########
@@ -102,20 +104,26 @@ final class Subscription {
private final ByteBuffer userData;
private final List<TopicPartition> ownedPartitions;
private Optional<String> groupInstanceId;
+ private final int generationId;
Review Comment:
Did you consider using an Optional? That may be better than relying on `DEFAULT_GENERATION`.
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerProtocolTest.java:
##########
@@ -247,4 +245,42 @@ public void deserializeFutureAssignmentVersion() {
Assignment assignment = ConsumerProtocol.deserializeAssignment(buffer);
assertEquals(toSet(Collections.singletonList(tp1)), toSet(assignment.partitions()));
}
+
+ private ByteBuffer generateFutureSubscriptionVersionData(boolean hasGenerationId) {
+ // verify that a new version which adds a field is still parseable
+ short version = 100;
+
+ Schema subscriptionSchemaV100 = new Schema(
+ new Field("topics", new ArrayOf(Type.STRING)),
+ new Field("user_data", Type.NULLABLE_BYTES),
+ new Field("owned_partitions", new ArrayOf(
+ ConsumerProtocolSubscription.TopicPartition.SCHEMA_1)),
+ hasGenerationId ? new Field("generation_id", Type.INT32) : new Field("foo", Type.STRING),
Review Comment:
This looks weird to me. If we are testing with version 100, `generation_id` should always be there, no? The latest version of the subscription has it. `ConsumerProtocol.deserializeAssignment()` will actually use the latest version, which includes generation id, to decode the payload here regardless of this. If you don't put it, the generation may get intitialized based on the `bar`'s data.
##########
clients/src/main/resources/common/message/ConsumerProtocolAssignment.json:
##########
@@ -21,7 +21,9 @@
// The current implementation assumes that future versions will not break compatibility. When
// it encounters a newer version, it parses it using the current format. This basically means
// that new versions cannot remove or reorder any of the existing fields.
- "validVersions": "0-1",
+ //
+ // version 2 is to support a new field "GenerationId" in ConsumerProtocolSubscription.
Review Comment:
nit: `Version 2...`
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
Review Comment:
All the tests use `buildSubscriptionWithGeneration` and `buildSubscription` which rely on the old method to encode the partitions and the generation. I wonder if we should update those in order to use the latest mechanism. What do you think? Then, we should have a few tests to ensure the backward compatibility.
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerProtocolTest.java:
##########
@@ -146,43 +165,22 @@ public void deserializeNewSubscriptionWithOldVersion() {
assertNull(parsedSubscription.userData());
assertTrue(parsedSubscription.ownedPartitions().isEmpty());
assertFalse(parsedSubscription.groupInstanceId().isPresent());
+ assertEquals(DEFAULT_GENERATION, parsedSubscription.generationId());
}
- @Test
- public void deserializeFutureSubscriptionVersion() {
- // verify that a new version which adds a field is still parseable
- short version = 100;
-
- Schema subscriptionSchemaV100 = new Schema(
- new Field("topics", new ArrayOf(Type.STRING)),
- new Field("user_data", Type.NULLABLE_BYTES),
- new Field("owned_partitions", new ArrayOf(
- ConsumerProtocolSubscription.TopicPartition.SCHEMA_1)),
- new Field("foo", Type.STRING));
-
- Struct subscriptionV100 = new Struct(subscriptionSchemaV100);
- subscriptionV100.set("topics", new Object[]{"topic"});
- subscriptionV100.set("user_data", ByteBuffer.wrap(new byte[0]));
- subscriptionV100.set("owned_partitions", new Object[]{new Struct(
- ConsumerProtocolSubscription.TopicPartition.SCHEMA_1)
- .set("topic", tp2.topic())
- .set("partitions", new Object[]{tp2.partition()})});
- subscriptionV100.set("foo", "bar");
-
- Struct headerV100 = new Struct(new Schema(new Field("version", Type.INT16)));
- headerV100.set("version", version);
-
- ByteBuffer buffer = ByteBuffer.allocate(subscriptionV100.sizeOf() + headerV100.sizeOf());
- headerV100.writeTo(buffer);
- subscriptionV100.writeTo(buffer);
-
- buffer.flip();
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ public void deserializeFutureSubscriptionVersion(boolean hasGenerationId) {
+ ByteBuffer buffer = generateFutureSubscriptionVersionData(hasGenerationId);
Subscription subscription = ConsumerProtocol.deserializeSubscription(buffer);
subscription.setGroupInstanceId(groupInstanceId);
assertEquals(Collections.singleton("topic"), toSet(subscription.topics()));
assertEquals(Collections.singleton(tp2), toSet(subscription.ownedPartitions()));
assertEquals(groupInstanceId, subscription.groupInstanceId());
+ if (hasGenerationId) {
+ assertEquals(generationId, subscription.generationId());
+ }
Review Comment:
Out of curiosity, does the test pass if you had `assertEquals(DEFAULT_GENERATION, subscription.generationId())` in the `else` branch?
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
+ public void testCooperativeStickyAssignorHonorSubscriptionUserdataIfNoGenerationIdInField() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ int higherGenerationId = 2;
+ int lowerGenerationId = 1;
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(partitions(tp1)), new ConsumerGroupMetadata(groupId, higherGenerationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
Review Comment:
All the other tests rely on `buildSubscriptionWithGeneration` and `buildSubscription`, I wonder if we should do the same here. Continuing on my previous comment, we could perhaps extend or add new versions of those to differentiate the old way from the new way.
##########
clients/src/main/resources/common/message/ConsumerProtocolSubscription.json:
##########
@@ -21,7 +21,9 @@
// The current implementation assumes that future versions will not break compatibility. When
// it encounters a newer version, it parses it using the current format. This basically means
// that new versions cannot remove or reorder any of the existing fields.
- "validVersions": "0-1",
+
+ // Starting from version 2, a new field "GenerationId" is added to indicate if the member has out-of-date ownedPartitions.
Review Comment:
While we are here, could we add a comment for version 1 as well?
##########
clients/src/main/resources/common/message/ConsumerProtocolSubscription.json:
##########
@@ -32,6 +34,7 @@
{ "name": "Topic", "type": "string", "mapKey": true, "versions": "1+", "entityType": "topicName" },
{ "name": "Partitions", "type": "[]int32", "versions": "1+"}
]
- }
+ },
+ { "name": "GenerationId", "type": "int32", "versions": "2+", "default": "-1", "ignorable": true}
Review Comment:
nit: A space misses before `}`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1318195383
@dajac , thanks for the comments. PR updated. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1024795520
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -162,6 +162,17 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
return isAllSubscriptionsEqual;
}
+ // visible for testing
+ MemberData memberDataFromSubscription(Subscription subscription) {
+ if (!subscription.ownedPartitions().isEmpty() && subscription.generationId().isPresent()) {
Review Comment:
I know what you mean now. Yes, for `subscription v2` check, we should only check generationId. Will update it and add a test for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1031512818
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -44,14 +46,26 @@ public AbstractStickyAssignor createAssignor() {
}
@Override
- public Subscription buildSubscription(List<String> topics, List<TopicPartition> partitions) {
- return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions);
+ public Subscription buildSubscriptionV0(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ // cooperative sticky assignor only supports ConsumerProtocolSubscription V1 or above
+ return null;
Review Comment:
nit: If it should not be used, would it make sense to throw an exception? e.g. IllegalStateException
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon merged pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon merged PR #12748:
URL: https://github.com/apache/kafka/pull/12748
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1327047070
@dajac , thanks for the comment. And thanks to the test, I found there's one thing I missed, which is in eager rebalance protocol like StickyAssignor, the ownedPartitions will all get revoked before joining group. And that means, we have to rely on userData in StickyAssignor. I've updated the `memberDataFromSubscription` for it. Please check the latest commit: https://github.com/apache/kafka/pull/12748/commits/6081deedcf2591d407cde8fe6cc5d6dd12875fcb . Thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1034544258
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
Review Comment:
This is not true anymore, isn't it? My understanding is that we always take the data from user data.
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+
+ // In StickyAssignor, we'll serialize owned partition in assignment into userData
+ assertEquals(ownedPartitionsInUserdata, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndEqualGeneration() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+
+ // subscription containing empty owned partitions and the same generation id, and non-empty owned partition in user data,
+ // member data should honor the one in user data
+ Subscription subscription = new Subscription(topics, generateUserData(topics, ownedPartitions, generationId), Collections.emptyList(), generationId);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+ assertEquals(ownedPartitions, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndHigherGeneration() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+ int generationIdInUserData = generationId - 1;
+
+ Subscription subscription = new Subscription(topics, generateUserData(topics, ownedPartitions, generationId - 1), Collections.emptyList(), generationId);
Review Comment:
nit: Could we reuse `generationIdInUserData` instead of `generationId - 1`?
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+
+ // In StickyAssignor, we'll serialize owned partition in assignment into userData
+ assertEquals(ownedPartitionsInUserdata, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndEqualGeneration() {
Review Comment:
I wonder if this test is useful with the last version. We always take from user data anyway.
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+
+ // In StickyAssignor, we'll serialize owned partition in assignment into userData
+ assertEquals(ownedPartitionsInUserdata, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndEqualGeneration() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+
+ // subscription containing empty owned partitions and the same generation id, and non-empty owned partition in user data,
+ // member data should honor the one in user data
+ Subscription subscription = new Subscription(topics, generateUserData(topics, ownedPartitions, generationId), Collections.emptyList(), generationId);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+ assertEquals(ownedPartitions, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndHigherGeneration() {
Review Comment:
nit: Should we name this test to reflect that we always take from the user data?
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -116,6 +130,74 @@ public void testAllConsumersHaveOwnedPartitionInvalidatedWhenClaimedByMultipleCo
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+ // In CooperativeStickyAssignor, we'll serialize owned partition in subscription into userData
Review Comment:
Is this sentence correct? In CooperativeStickyAssignor, only the generation is put in user data, no?
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -44,14 +46,26 @@ public AbstractStickyAssignor createAssignor() {
}
@Override
- public Subscription buildSubscription(List<String> topics, List<TopicPartition> partitions) {
- return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions);
+ public Subscription buildSubscriptionV0(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ // cooperative sticky assignor only supports ConsumerProtocolSubscription V1 or above
+ return null;
}
@Override
- public Subscription buildSubscriptionWithGeneration(List<String> topics, List<TopicPartition> partitions, int generation) {
- assignor.onAssignment(null, new ConsumerGroupMetadata("dummy-group-id", generation, "dummy-member-id", Optional.empty()));
- return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions);
+ public Subscription buildSubscriptionV1(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(partitions), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions, DEFAULT_GENERATION);
+ }
+
+ @Override
+ public Subscription buildSubscriptionV2Above(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ return new Subscription(topics, null, partitions, generationId);
Review Comment:
Using `null` is not 100% correct here, isn't it? My understanding is that the implementation always serializes the user data, even with version >= 2.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1017395458
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerProtocolTest.java:
##########
@@ -247,4 +245,42 @@ public void deserializeFutureAssignmentVersion() {
Assignment assignment = ConsumerProtocol.deserializeAssignment(buffer);
assertEquals(toSet(Collections.singletonList(tp1)), toSet(assignment.partitions()));
}
+
+ private ByteBuffer generateFutureSubscriptionVersionData(boolean hasGenerationId) {
+ // verify that a new version which adds a field is still parseable
+ short version = 100;
+
+ Schema subscriptionSchemaV100 = new Schema(
+ new Field("topics", new ArrayOf(Type.STRING)),
+ new Field("user_data", Type.NULLABLE_BYTES),
+ new Field("owned_partitions", new ArrayOf(
+ ConsumerProtocolSubscription.TopicPartition.SCHEMA_1)),
+ hasGenerationId ? new Field("generation_id", Type.INT32) : new Field("foo", Type.STRING),
Review Comment:
I think you're right. The generation_id should always be there. I think this test is just to test we will always get the correct data no matter what new fields added. Updated the test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1296682750
@dajac @guozhangwang , call for review. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1034451061
##########
clients/src/main/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignor.java:
##########
@@ -84,6 +84,11 @@ public ByteBuffer subscriptionUserData(Set<String> topics) {
@Override
protected MemberData memberData(Subscription subscription) {
+ // In ConsumerProtocolSubscription v2 or higher, we can take member data from fields directly
+ if (subscription.generationId().isPresent()) {
+ return new MemberData(subscription.ownedPartitions(), subscription.generationId());
+ }
Review Comment:
In cooperativeStickyAssignor, we can directly adopt the new generation fields if existed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1034452624
##########
clients/src/main/java/org/apache/kafka/clients/consumer/StickyAssignor.java:
##########
@@ -216,6 +216,8 @@ public ByteBuffer subscriptionUserData(Set<String> topics) {
@Override
protected MemberData memberData(Subscription subscription) {
+ // Always deserialize ownedPartitions and generation id from user data
+ // since StickyAssignor is an eager rebalance protocol that will revoke all existing partitions before joining group
Review Comment:
In StickyAssignor, we still deserialize the user data to retrieve all the data since it is an eager rebalance protocol.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1310065769
@dajac , PR updated. Please take a look when available. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1283533387
@dajac , sorry for delay. It's good for review now. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1333272289
All tests passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1024795520
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -162,6 +162,17 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
return isAllSubscriptionsEqual;
}
+ // visible for testing
+ MemberData memberDataFromSubscription(Subscription subscription) {
+ if (!subscription.ownedPartitions().isEmpty() && subscription.generationId().isPresent()) {
Review Comment:
I know what you mean now. Yes, for `subscription v3` check, we should only check generationId. Will update it and add a test for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1296693798
Will review it this week. Thanks for the PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1017394471
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
Review Comment:
I agree we should add tests for the latest mechanism, but I think we should still keep the tests for old schema. These are unit tests, which will not take too long. I added variable to test old and new schemas.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1024071860
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignorTest.java:
##########
@@ -73,6 +88,74 @@ public void setUp() {
}
}
+ @Test
+ public void testMemberDataFromSubscription() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+ List<Subscription> subscriptions = new ArrayList<>();
+ // add all subscription in ConsumerProtocolSubscription versions
+ subscriptions.add(buildSubscriptionV0(topics, ownedPartitions, generationId));
+ subscriptions.add(buildSubscriptionV1(topics, ownedPartitions, generationId));
+ subscriptions.add(buildSubscriptionV2Above(topics, ownedPartitions, generationId));
+ for (Subscription subscription : subscriptions) {
+ if (subscription != null) {
+ AbstractStickyAssignor.MemberData memberData = assignor.memberDataFromSubscription(subscription);
+ assertEquals(ownedPartitions, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+ }
+ }
+
+ @Test
+ public void testMemberDataFromSubscriptionWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = assignor.memberDataFromSubscription(subscription);
+ // in CooperativeStickyAssignor, we'll serialize owned partition in subscription into userData
+ // but in StickyAssignor, we'll serialize owned partition in assignment into userData
+ if (assignor instanceof CooperativeStickyAssignor) {
Review Comment:
This is not very elegant given that we have subclasses for each. Should we move this test to the respective subclasses?
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignorTest.java:
##########
@@ -73,6 +88,74 @@ public void setUp() {
}
}
+ @Test
+ public void testMemberDataFromSubscription() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+ List<Subscription> subscriptions = new ArrayList<>();
+ // add all subscription in ConsumerProtocolSubscription versions
+ subscriptions.add(buildSubscriptionV0(topics, ownedPartitions, generationId));
+ subscriptions.add(buildSubscriptionV1(topics, ownedPartitions, generationId));
+ subscriptions.add(buildSubscriptionV2Above(topics, ownedPartitions, generationId));
+ for (Subscription subscription : subscriptions) {
+ if (subscription != null) {
+ AbstractStickyAssignor.MemberData memberData = assignor.memberDataFromSubscription(subscription);
+ assertEquals(ownedPartitions, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+ }
+ }
+
+ @Test
+ public void testMemberDataFromSubscriptionWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = assignor.memberDataFromSubscription(subscription);
+ // in CooperativeStickyAssignor, we'll serialize owned partition in subscription into userData
+ // but in StickyAssignor, we'll serialize owned partition in assignment into userData
+ if (assignor instanceof CooperativeStickyAssignor) {
+ assertEquals(ownedPartitionsInSubscription, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ } else {
+ assertEquals(ownedPartitionsInUserdata, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ }
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testAssignorWithOldVersionSubscriptions() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic1, 3);
+
+ List<String> subscribedTopics = topics(topic1);
+
+ // cooperative sticky assignor only supports ConsumerProtocolSubscription V1 or above
+ if (assignor instanceof CooperativeStickyAssignor) {
Review Comment:
ditto.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1018909824
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
Review Comment:
OK, tests updated. For existing tests, we'll use the latest scheme to build subscription. And added some backward compatibility tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1035598812
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+
+ // In StickyAssignor, we'll serialize owned partition in assignment into userData
+ assertEquals(ownedPartitionsInUserdata, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndEqualGeneration() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+
+ // subscription containing empty owned partitions and the same generation id, and non-empty owned partition in user data,
+ // member data should honor the one in user data
+ Subscription subscription = new Subscription(topics, generateUserData(topics, ownedPartitions, generationId), Collections.emptyList(), generationId);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+ assertEquals(ownedPartitions, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndHigherGeneration() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+ int generationIdInUserData = generationId - 1;
+
+ Subscription subscription = new Subscription(topics, generateUserData(topics, ownedPartitions, generationId - 1), Collections.emptyList(), generationId);
Review Comment:
Ah, that's my intent. Forgot to change it. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1035599008
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+
+ // In StickyAssignor, we'll serialize owned partition in assignment into userData
+ assertEquals(ownedPartitionsInUserdata, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndEqualGeneration() {
+ List<String> topics = topics(topic);
+ List<TopicPartition> ownedPartitions = partitions(tp(topic1, 0), tp(topic2, 1));
+
+ // subscription containing empty owned partitions and the same generation id, and non-empty owned partition in user data,
+ // member data should honor the one in user data
+ Subscription subscription = new Subscription(topics, generateUserData(topics, ownedPartitions, generationId), Collections.emptyList(), generationId);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+ assertEquals(ownedPartitions, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndHigherGeneration() {
Review Comment:
Updated to `testMemberDataWillHonorUserData`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1017442642
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
+ public void testCooperativeStickyAssignorHonorSubscriptionUserdataIfNoGenerationIdInField() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ int higherGenerationId = 2;
+ int lowerGenerationId = 1;
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(partitions(tp1)), new ConsumerGroupMetadata(groupId, higherGenerationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
Review Comment:
We can use `buildSubscriptionWithGeneration` for consumer2 here, but not for consumer1. Please note, the consumer1 provides different owned partitions and generation id as the one provided in subscription. I'm trying to test which data we should honor in different cases. I've updated the comment to make it clear.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1035598601
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+
+ // In StickyAssignor, we'll serialize owned partition in assignment into userData
+ assertEquals(ownedPartitionsInUserdata, memberData.partitions, "subscription: " + subscription + " doesn't have expected owned partition");
+ assertEquals(generationId, memberData.generation.orElse(-1), "subscription: " + subscription + " doesn't have expected generation id");
+ }
+
+ @Test
+ public void testMemberDataWithEmptyPartitionsAndEqualGeneration() {
Review Comment:
Make sense. Removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1035599539
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -116,6 +130,74 @@ public void testAllConsumersHaveOwnedPartitionInvalidatedWhenClaimedByMultipleCo
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
+ Subscription subscription = new Subscription(topics(topic), userDataWithHigherGenerationId, ownedPartitionsInSubscription);
+
+ AbstractStickyAssignor.MemberData memberData = memberData(subscription);
+ // In CooperativeStickyAssignor, we'll serialize owned partition in subscription into userData
Review Comment:
You're right! In CooperativeStickyAssignor, only the generation is put in user data. Updated to:
`// In CooperativeStickyAssignor, we only serialize generation id into userData`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1032023101
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -44,14 +46,26 @@ public AbstractStickyAssignor createAssignor() {
}
@Override
- public Subscription buildSubscription(List<String> topics, List<TopicPartition> partitions) {
- return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions);
+ public Subscription buildSubscriptionV0(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ // cooperative sticky assignor only supports ConsumerProtocolSubscription V1 or above
+ return null;
Review Comment:
Thanks David, but in `testMemberDataFromSubscription` test, I did use `null` check to make sure we will skip ConsumerProtocolSubscription v0 in cooperativeStickyAssignor. We can throw exception here, but that would make the test more complicated and that's unnecessary IMO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1033405223
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -162,6 +162,28 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
return isAllSubscriptionsEqual;
}
+ // visible for testing
+ MemberData memberDataFromSubscription(Subscription subscription) {
Review Comment:
@showuon This method is getting less and less generic. Would it make sense to push to version handling into `memberData` method? This would let each assignor handle subscription v2 based on their specifics instead of having those conditions here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1034454065
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -162,6 +162,28 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
return isAllSubscriptionsEqual;
}
+ // visible for testing
+ MemberData memberDataFromSubscription(Subscription subscription) {
Review Comment:
> @showuon This method is getting less and less generic. Would it make sense to push to version handling into `memberData` method? This would let each assignor handle subscription v2 based on their specifics instead of having those conditions here.
I agree it makes it much clear to move the version handling into `memberData` method in each assignor. I've updated the PR. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1017395682
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerProtocolTest.java:
##########
@@ -146,43 +165,22 @@ public void deserializeNewSubscriptionWithOldVersion() {
assertNull(parsedSubscription.userData());
assertTrue(parsedSubscription.ownedPartitions().isEmpty());
assertFalse(parsedSubscription.groupInstanceId().isPresent());
+ assertEquals(DEFAULT_GENERATION, parsedSubscription.generationId());
}
- @Test
- public void deserializeFutureSubscriptionVersion() {
- // verify that a new version which adds a field is still parseable
- short version = 100;
-
- Schema subscriptionSchemaV100 = new Schema(
- new Field("topics", new ArrayOf(Type.STRING)),
- new Field("user_data", Type.NULLABLE_BYTES),
- new Field("owned_partitions", new ArrayOf(
- ConsumerProtocolSubscription.TopicPartition.SCHEMA_1)),
- new Field("foo", Type.STRING));
-
- Struct subscriptionV100 = new Struct(subscriptionSchemaV100);
- subscriptionV100.set("topics", new Object[]{"topic"});
- subscriptionV100.set("user_data", ByteBuffer.wrap(new byte[0]));
- subscriptionV100.set("owned_partitions", new Object[]{new Struct(
- ConsumerProtocolSubscription.TopicPartition.SCHEMA_1)
- .set("topic", tp2.topic())
- .set("partitions", new Object[]{tp2.partition()})});
- subscriptionV100.set("foo", "bar");
-
- Struct headerV100 = new Struct(new Schema(new Field("version", Type.INT16)));
- headerV100.set("version", version);
-
- ByteBuffer buffer = ByteBuffer.allocate(subscriptionV100.sizeOf() + headerV100.sizeOf());
- headerV100.writeTo(buffer);
- subscriptionV100.writeTo(buffer);
-
- buffer.flip();
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ public void deserializeFutureSubscriptionVersion(boolean hasGenerationId) {
+ ByteBuffer buffer = generateFutureSubscriptionVersionData(hasGenerationId);
Subscription subscription = ConsumerProtocol.deserializeSubscription(buffer);
subscription.setGroupInstanceId(groupInstanceId);
assertEquals(Collections.singleton("topic"), toSet(subscription.topics()));
assertEquals(Collections.singleton(tp2), toSet(subscription.ownedPartitions()));
assertEquals(groupInstanceId, subscription.groupInstanceId());
+ if (hasGenerationId) {
+ assertEquals(generationId, subscription.generationId());
+ }
Review Comment:
test updated, no `hasGenerationId` anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1035598438
##########
clients/src/test/java/org/apache/kafka/clients/consumer/StickyAssignorTest.java:
##########
@@ -272,6 +284,73 @@ public void testSchemaBackwardCompatibility() {
assertTrue(isFullyBalanced(assignment));
}
+ @Test
+ public void testMemberDataWithInconsistentData() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ List<TopicPartition> ownedPartitionsInUserdata = partitions(tp1);
+ List<TopicPartition> ownedPartitionsInSubscription = partitions(tp0);
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(ownedPartitionsInUserdata), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
+ // The owned partitions and generation id are provided in user data and different owned partition is provided in subscription without generation id
+ // If subscription provides no generation id, we'll honor the generation id in userData and owned partitions in subscription
Review Comment:
You're right! Updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1015224638
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -117,30 +117,41 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
isAllSubscriptionsEqual = false;
}
- MemberData memberData = memberData(subscription);
+ Optional<Integer> generation;
+ List<TopicPartition> ownedPartitionsInMetadata;
+ if (!subscription.ownedPartitions().isEmpty() && subscription.generationId() != DEFAULT_GENERATION) {
+ // In ConsumerProtocolSubscription v2 or higher, we don't need to deserialize the byte buffer
+ // and take from fields directly
+ ownedPartitionsInMetadata = subscription.ownedPartitions();
+ generation = Optional.of(subscription.generationId());
+ } else {
+ MemberData memberData = memberData(subscription);
+ ownedPartitionsInMetadata = memberData.partitions;
+ generation = memberData.generation;
+ }
Review Comment:
> It seems that we also rely on the generation in prepopulateCurrentAssignments so I suppose that we need a similar logic over there in order to be consistent. Do we?
Good point! Will update it.
> Knowing this, I wonder if we should update memberData to get the correct generation from the subscription. That would ensure that all usages of memberData get the correct view. What do you think?
Do you mean in L130, we should use the generationId from subscription? I don't think that's correct because the generationId is bound to the owned partition in memberData.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1308231893
@dajac , I've addressed all comments. Please take a look when available. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1017743686
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
Review Comment:
I am not entirely convinced by adding version to all tests because it makes the tests harder to read. I would rather used the most up to date scheme in the tests and add new unit test for the backward compatibility. This seems more explicit and would keep existing test simpler to read.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1018908171
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
+ public void testCooperativeStickyAssignorHonorSubscriptionUserdataIfNoGenerationIdInField() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ int higherGenerationId = 2;
+ int lowerGenerationId = 1;
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(partitions(tp1)), new ConsumerGroupMetadata(groupId, higherGenerationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
Review Comment:
You're right. Change to test `memberDataFromSubscription`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1018917087
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignorTest.java:
##########
@@ -55,12 +60,22 @@ public abstract class AbstractStickyAssignorTest {
protected String topic1 = "topic1";
protected String topic2 = "topic2";
protected String topic3 = "topic3";
+ protected TopicPartition tp0 = tp(topic, 0);
+ protected TopicPartition tp1 = tp(topic, 1);
+ protected TopicPartition tp2 = tp(topic, 2);
+ protected String groupId = "group";
+ protected int generationId = 1;
protected abstract AbstractStickyAssignor createAssignor();
- protected abstract Subscription buildSubscription(List<String> topics, List<TopicPartition> partitions);
+ // simulate ConsumerProtocolSubscription V0 protocol
+ protected abstract Subscription buildSubscriptionV0(List<String> topics, List<TopicPartition> partitions, int generationId);
- protected abstract Subscription buildSubscriptionWithGeneration(List<String> topics, List<TopicPartition> partitions, int generation);
+ // simulate ConsumerProtocolSubscription V1 protocol
+ protected abstract Subscription buildSubscriptionV1(List<String> topics, List<TopicPartition> partitions, int generationId);
+
+ // simulate ConsumerProtocolSubscription V2 or above protocol
+ protected abstract Subscription buildSubscriptionV2Above(List<String> topics, List<TopicPartition> partitions, int generation);
Review Comment:
Created `buildSubscriptionV0`, `buildSubscriptionV1`, and `buildSubscriptionV2Above` for all versions tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1015096016
##########
clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerPartitionAssignor.java:
##########
@@ -102,20 +104,26 @@ final class Subscription {
private final ByteBuffer userData;
private final List<TopicPartition> ownedPartitions;
private Optional<String> groupInstanceId;
+ private final int generationId;
Review Comment:
Agree. Change to `Optional`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1017718371
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -1229,4 +1247,23 @@ private boolean in(Set<ConsumerPair> pairs) {
return false;
}
}
+
+ // An inner class to store ownedPartitions and generation data
+ private static class OwnedPartitionsWithGeneration {
Review Comment:
This is basically `MemberData` but with a different name. Could we reuse `MemberData` instead?
##########
clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerPartitionAssignor.java:
##########
@@ -138,13 +146,18 @@ public Optional<String> groupInstanceId() {
return groupInstanceId;
}
+ public Optional<Integer> generationId() {
+ return generationId;
+ }
+
@Override
public String toString() {
return "Subscription(" +
"topics=" + topics +
(userData == null ? "" : ", userDataSize=" + userData.remaining()) +
", ownedPartitions=" + ownedPartitions +
", groupInstanceId=" + (groupInstanceId.map(String::toString).orElse("null")) +
+ ", generationId=" + (generationId.orElse(-1)) +
Review Comment:
nit: Are the parenthesis needed here?
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -162,6 +162,23 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
return isAllSubscriptionsEqual;
}
+ private OwnedPartitionsWithGeneration findOwnedPartitionsWithGeneration(Subscription subscription) {
Review Comment:
nit: Starting with `find` is a bit weird here. Following on my previous comment, how about `memberDataFromSubscription`?
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -78,6 +80,26 @@ public void testDecodeGeneration() {
assertFalse(((CooperativeStickyAssignor) assignor).memberData(subscription).generation.isPresent());
}
+ @Test
+ public void testCooperativeStickyAssignorHonorSubscriptionUserdataIfNoGenerationIdInField() {
+ Map<String, Integer> partitionsPerTopic = new HashMap<>();
+ partitionsPerTopic.put(topic, 2);
+ int higherGenerationId = 2;
+ int lowerGenerationId = 1;
+
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(partitions(tp1)), new ConsumerGroupMetadata(groupId, higherGenerationId, consumer1, Optional.empty()));
+ ByteBuffer userDataWithHigherGenerationId = assignor.subscriptionUserData(new HashSet<>(topics(topic)));
Review Comment:
I think that your goal is to basically ensure that `findOwnedPartitionsWithGeneration` works as expected given all the possible inputs. Should we just add a unit test for this method for both assignors with all the possible inputs? The intent would be clearer in my opinion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1018907375
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -1229,4 +1247,23 @@ private boolean in(Set<ConsumerPair> pairs) {
return false;
}
}
+
+ // An inner class to store ownedPartitions and generation data
+ private static class OwnedPartitionsWithGeneration {
Review Comment:
Good point! I should have thought about it. Thanks for the suggestion!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1282700266
Thanks for the PR, @showuon. Is it ready for review? I will help you to get it in.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] dajac commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1024047722
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -162,6 +162,17 @@ private boolean allSubscriptionsEqual(Set<String> allTopics,
return isAllSubscriptionsEqual;
}
+ // visible for testing
+ MemberData memberDataFromSubscription(Subscription subscription) {
+ if (!subscription.ownedPartitions().isEmpty() && subscription.generationId().isPresent()) {
Review Comment:
I wonder if this is 100% correct. Could we have a case where subscription v3 is used but no owned partitions are reported by the member? For instance, this could happen if the group has more members than partitions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a diff in pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12748:
URL: https://github.com/apache/kafka/pull/12748#discussion_r1035600480
##########
clients/src/test/java/org/apache/kafka/clients/consumer/CooperativeStickyAssignorTest.java:
##########
@@ -44,14 +46,26 @@ public AbstractStickyAssignor createAssignor() {
}
@Override
- public Subscription buildSubscription(List<String> topics, List<TopicPartition> partitions) {
- return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions);
+ public Subscription buildSubscriptionV0(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ // cooperative sticky assignor only supports ConsumerProtocolSubscription V1 or above
+ return null;
}
@Override
- public Subscription buildSubscriptionWithGeneration(List<String> topics, List<TopicPartition> partitions, int generation) {
- assignor.onAssignment(null, new ConsumerGroupMetadata("dummy-group-id", generation, "dummy-member-id", Optional.empty()));
- return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions);
+ public Subscription buildSubscriptionV1(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ assignor.onAssignment(new ConsumerPartitionAssignor.Assignment(partitions), new ConsumerGroupMetadata(groupId, generationId, consumer1, Optional.empty()));
+ return new Subscription(topics, assignor.subscriptionUserData(new HashSet<>(topics)), partitions, DEFAULT_GENERATION);
+ }
+
+ @Override
+ public Subscription buildSubscriptionV2Above(List<String> topics, List<TopicPartition> partitions, int generationId) {
+ return new Subscription(topics, null, partitions, generationId);
Review Comment:
Yes, the user data is always provided, although we ignored. Updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #12748: KAFKA-13715: add generationId field in subscription
Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12748:
URL: https://github.com/apache/kafka/pull/12748#issuecomment-1331732502
@dajac , Thanks for the comments. PR updated. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org