-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-16625: Reverse lookup map from topic partitions to members #15974
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
Changes from all commits
7d92a43
f4ec728
0cb1a5f
1b7b693
e7c68b5
11b7b1f
e710fca
b74f713
0785f3b
b7c2a24
db1c601
2afb1bc
50812d5
9dada36
d63e491
e3a8b95
9fa0ab3
5c4c4ed
0d25f3a
a4ce616
9cdd729
9ca54c3
a36d59c
9d4fbfe
01a7b6e
d0a0ef9
7e6a7eb
ca53724
fa9f388
fa22563
65b82ef
d2e7ef4
5a2d2a6
729c1f3
213dfe5
505b859
91d20b0
346e618
c8e0c34
66fcd89
867103e
55c76ec
bc47eff
5de869c
3ac9c27
57a8db9
86bf48b
4055e09
f7d0af7
555b519
449b168
2eadcb3
65a2866
a99fadc
3a27648
09c11e5
756983a
e00c5ed
5bf574e
dccb583
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.coordinator.group.assignor; | ||
|
|
||
| import org.apache.kafka.common.Uuid; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * The group metadata specifications required to compute the target assignment. | ||
| */ | ||
| public interface GroupSpec { | ||
| /** | ||
| * @return Member metadata keyed by member Id. | ||
| */ | ||
| Map<String, AssignmentMemberSpec> members(); | ||
|
|
||
| /** | ||
| * @return The group's subscription type. | ||
| */ | ||
| SubscriptionType subscriptionType(); | ||
|
|
||
| /** | ||
| * @return True, if the partition is currently assigned to a member. | ||
| * False, otherwise. | ||
| */ | ||
| boolean isPartitionAssigned(Uuid topicId, int partitionId); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,15 @@ | |
| */ | ||
| package org.apache.kafka.coordinator.group.assignor; | ||
|
|
||
| import org.apache.kafka.common.Uuid; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * The assignment specification for a consumer group. | ||
| */ | ||
| public class AssignmentSpec { | ||
| public class GroupSpecImpl implements GroupSpec { | ||
| /** | ||
| * The member metadata keyed by member Id. | ||
| */ | ||
|
|
@@ -33,44 +35,76 @@ public class AssignmentSpec { | |
| */ | ||
| private final SubscriptionType subscriptionType; | ||
|
|
||
| public AssignmentSpec( | ||
| /** | ||
| * Reverse lookup map representing topic partitions with | ||
| * their current member assignments. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think i'm slightly confused again on the types of assignments. Target Assignment: the assignment we will reconcile to. Current Assignment: the previous group epoch's target assignment. is this correct?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
| */ | ||
| private final Map<Uuid, Map<Integer, String>> invertedTargetAssignment; | ||
|
|
||
| public GroupSpecImpl( | ||
| Map<String, AssignmentMemberSpec> members, | ||
| SubscriptionType subscriptionType | ||
| SubscriptionType subscriptionType, | ||
| Map<Uuid, Map<Integer, String>> invertedTargetAssignment | ||
| ) { | ||
| Objects.requireNonNull(members); | ||
| Objects.requireNonNull(subscriptionType); | ||
| Objects.requireNonNull(invertedTargetAssignment); | ||
| this.members = members; | ||
| this.subscriptionType = subscriptionType; | ||
| this.invertedTargetAssignment = invertedTargetAssignment; | ||
| } | ||
|
|
||
| /** | ||
| * @return Member metadata keyed by member Id. | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public Map<String, AssignmentMemberSpec> members() { | ||
|
rreddy-22 marked this conversation as resolved.
|
||
| return members; | ||
| } | ||
|
|
||
| /** | ||
| * @return The group's subscription type. | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public SubscriptionType subscriptionType() { | ||
|
rreddy-22 marked this conversation as resolved.
|
||
| return subscriptionType; | ||
| } | ||
|
|
||
| /** | ||
|
rreddy-22 marked this conversation as resolved.
|
||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public boolean isPartitionAssigned(Uuid topicId, int partitionId) { | ||
|
rreddy-22 marked this conversation as resolved.
|
||
| Map<Integer, String> partitionMap = invertedTargetAssignment.get(topicId); | ||
| if (partitionMap == null) { | ||
| return false; | ||
| } | ||
| return partitionMap.containsKey(partitionId); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| AssignmentSpec that = (AssignmentSpec) o; | ||
| GroupSpecImpl that = (GroupSpecImpl) o; | ||
| return subscriptionType == that.subscriptionType && | ||
| members.equals(that.members); | ||
| members.equals(that.members) && | ||
| invertedTargetAssignment.equals(that.invertedTargetAssignment); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(members, subscriptionType); | ||
| int result = members.hashCode(); | ||
| result = 31 * result + subscriptionType.hashCode(); | ||
| result = 31 * result + invertedTargetAssignment.hashCode(); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "AssignmentSpec(members=" + members + ", subscriptionType=" + subscriptionType.toString() + ')'; | ||
| return "GroupSpecImpl(members=" + members + | ||
| ", subscriptionType=" + subscriptionType + | ||
| ", invertedTargetAssignment=" + invertedTargetAssignment + | ||
| ')'; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.