Class StreamsPartitionAssignor
- java.lang.Object
-
- org.apache.kafka.streams.processor.internals.StreamsPartitionAssignor
-
- All Implemented Interfaces:
ConsumerPartitionAssignor
,Configurable
public class StreamsPartitionAssignor extends Object implements ConsumerPartitionAssignor, Configurable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.kafka.clients.consumer.ConsumerPartitionAssignor
ConsumerPartitionAssignor.Assignment, ConsumerPartitionAssignor.GroupAssignment, ConsumerPartitionAssignor.GroupSubscription, ConsumerPartitionAssignor.RebalanceProtocol, ConsumerPartitionAssignor.Subscription
-
-
Field Summary
Fields Modifier and Type Field Description protected static Comparator<TopicPartition>
PARTITION_COMPARATOR
protected int
usedSubscriptionMetadataVersion
-
Constructor Summary
Constructors Constructor Description StreamsPartitionAssignor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConsumerPartitionAssignor.GroupAssignment
assign(Cluster metadata, ConsumerPartitionAssignor.GroupSubscription groupSubscription)
Perform the group assignment given the member subscriptions and current cluster metadata.void
configure(Map<String,?> configs)
We need to have the PartitionAssignor and its StreamThread to be mutually accessible since the former needs later's cached metadata while sending subscriptions, and the latter needs former's returned assignment when adding tasks.protected static Map<TaskId,Set<TopicPartition>>
getActiveTasks(List<TopicPartition> partitions, AssignmentInfo info)
protected void
handleRebalanceStart(Set<String> topics)
protected boolean
maybeUpdateSubscriptionVersion(int receivedAssignmentMetadataVersion, int latestCommonlySupportedVersion)
String
name()
Unique name for this assignor (e.g.void
onAssignment(ConsumerPartitionAssignor.Assignment assignment, ConsumerGroupMetadata metadata)
Callback which is invoked when a group member receives its assignment from the leader.ByteBuffer
subscriptionUserData(Set<String> topics)
Return serialized data that will be included in theConsumerPartitionAssignor.Subscription
sent to the leader and can be leveraged inConsumerPartitionAssignor.assign(Cluster, GroupSubscription)
((e.g.List<ConsumerPartitionAssignor.RebalanceProtocol>
supportedProtocols()
Indicate which rebalance protocol this assignor works with; By default it should always work withConsumerPartitionAssignor.RebalanceProtocol.EAGER
.protected TaskManager
taskManager()
protected byte
uniqueField()
protected String
userEndPoint()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.kafka.clients.consumer.ConsumerPartitionAssignor
version
-
-
-
-
Field Detail
-
PARTITION_COMPARATOR
protected static final Comparator<TopicPartition> PARTITION_COMPARATOR
-
usedSubscriptionMetadataVersion
protected int usedSubscriptionMetadataVersion
-
-
Method Detail
-
configure
public void configure(Map<String,?> configs)
We need to have the PartitionAssignor and its StreamThread to be mutually accessible since the former needs later's cached metadata while sending subscriptions, and the latter needs former's returned assignment when adding tasks.- Specified by:
configure
in interfaceConfigurable
- Throws:
KafkaException
- if the stream thread is not specified
-
name
public String name()
Description copied from interface:ConsumerPartitionAssignor
Unique name for this assignor (e.g. "range" or "roundrobin" or "sticky"). Note, this is not required to be the same as the class name specified inConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG
- Specified by:
name
in interfaceConsumerPartitionAssignor
- Returns:
- non-null unique name
-
supportedProtocols
public List<ConsumerPartitionAssignor.RebalanceProtocol> supportedProtocols()
Description copied from interface:ConsumerPartitionAssignor
Indicate which rebalance protocol this assignor works with; By default it should always work withConsumerPartitionAssignor.RebalanceProtocol.EAGER
.- Specified by:
supportedProtocols
in interfaceConsumerPartitionAssignor
-
subscriptionUserData
public ByteBuffer subscriptionUserData(Set<String> topics)
Description copied from interface:ConsumerPartitionAssignor
Return serialized data that will be included in theConsumerPartitionAssignor.Subscription
sent to the leader and can be leveraged inConsumerPartitionAssignor.assign(Cluster, GroupSubscription)
((e.g. local host/rack information)- Specified by:
subscriptionUserData
in interfaceConsumerPartitionAssignor
- Parameters:
topics
- Topics subscribed to throughKafkaConsumer.subscribe(java.util.Collection)
and variants- Returns:
- nullable subscription user data
-
assign
public ConsumerPartitionAssignor.GroupAssignment assign(Cluster metadata, ConsumerPartitionAssignor.GroupSubscription groupSubscription)
Description copied from interface:ConsumerPartitionAssignor
Perform the group assignment given the member subscriptions and current cluster metadata.- Specified by:
assign
in interfaceConsumerPartitionAssignor
- Parameters:
metadata
- Current topic/broker metadata known by consumergroupSubscription
- Subscriptions from all members including metadata provided throughConsumerPartitionAssignor.subscriptionUserData(Set)
- Returns:
- A map from the members to their respective assignments. This should have one entry for each member in the input subscription map.
-
maybeUpdateSubscriptionVersion
protected boolean maybeUpdateSubscriptionVersion(int receivedAssignmentMetadataVersion, int latestCommonlySupportedVersion)
-
onAssignment
public void onAssignment(ConsumerPartitionAssignor.Assignment assignment, ConsumerGroupMetadata metadata)
Description copied from interface:ConsumerPartitionAssignor
Callback which is invoked when a group member receives its assignment from the leader.- Specified by:
onAssignment
in interfaceConsumerPartitionAssignor
- Parameters:
assignment
- The local member's assignment as provided by the leader inConsumerPartitionAssignor.assign(Cluster, GroupSubscription)
metadata
- Additional metadata on the consumer (optional)- Throws:
TaskAssignmentException
- if there is no task id for one of the partitions specified
-
getActiveTasks
protected static Map<TaskId,Set<TopicPartition>> getActiveTasks(List<TopicPartition> partitions, AssignmentInfo info)
-
userEndPoint
protected String userEndPoint()
-
taskManager
protected TaskManager taskManager()
-
uniqueField
protected byte uniqueField()
-
-