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

KAFKA-9987: optimize sticky assignment algorithm for same-subscription case #8668

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,20 @@ public List<RebalanceProtocol> supportedProtocols() {

@Override
protected MemberData memberData(Subscription subscription) {
return new MemberData(subscription.ownedPartitions(), Optional.empty());
return new MemberData(subscription.ownedPartitions(), Optional.of(1));
}

@Override
public Map<String, List<TopicPartition>> assign(Map<String, Integer> partitionsPerTopic,
Map<String, Subscription> subscriptions) {

final Map<String, List<TopicPartition>> assignments = super.assign(partitionsPerTopic, subscriptions);
Map<String, List<TopicPartition>> assignments = super.assign(partitionsPerTopic, subscriptions);
adjustAssignment(subscriptions, assignments);
return assignments;
}

// Following the cooperative rebalancing protocol requires removing partitions that must first be revoked from the assignment
private void adjustAssignment(final Map<String, Subscription> subscriptions,
final Map<String, List<TopicPartition>> assignments) {

private void adjustAssignment(Map<String, Subscription> subscriptions,
Map<String, List<TopicPartition>> assignments) {
Map<TopicPartition, String> allAddedPartitions = new HashMap<>();
Set<TopicPartition> allRevokedPartitions = new HashSet<>();

Expand All @@ -87,7 +85,7 @@ private void adjustAssignment(final Map<String, Subscription> subscriptions,
allAddedPartitions.put(tp, consumer);
}

final Set<TopicPartition> revokedPartitions = new HashSet<>(ownedPartitions);
Set<TopicPartition> revokedPartitions = new HashSet<>(ownedPartitions);
revokedPartitions.removeAll(assignedPartitions);
allRevokedPartitions.addAll(revokedPartitions);
}
Expand Down
Loading