Class UniformShardAssigner
- java.lang.Object
-
- org.apache.flink.streaming.connectors.kinesis.util.UniformShardAssigner
-
- All Implemented Interfaces:
Serializable,KinesisShardAssigner
@PublicEvolving public class UniformShardAssigner extends Object implements KinesisShardAssigner
AKinesisShardAssignerthat maps Kinesis shard hash-key ranges to Flink subtasks. It creates a more uniform distribution of shards across subtasks thanorg.apache.flink.streaming.connectors.kinesis.internals.KinesisDataFetcher#DEFAULT_SHARD_ASSIGNERwhen the Kinesis records in the stream have hash keys that are uniformly distributed over all possible hash keys, which is the case if records have randomly-generated partition keys. (This is the same assumption made if you use the Kinesis UpdateShardCount operation with UNIFORM_SCALING.)- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description UniformShardAssigner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intassign(StreamShardHandle streamShardHandle, int nSubtasks)Returns the index of the target subtask that a specific shard should be assigned to.
-
-
-
Method Detail
-
assign
public int assign(StreamShardHandle streamShardHandle, int nSubtasks)
Description copied from interface:KinesisShardAssignerReturns the index of the target subtask that a specific shard should be assigned to. For return values outside the subtask range, modulus operation will be applied automatically, hence it is also valid to just return a hash code.The resulting distribution of shards should have the following contract:
- 1. Uniform distribution across subtasks
- 2. Deterministic, calls for a given shard always return same index.
The above contract is crucial and cannot be broken. Consumer subtasks rely on this contract to filter out shards that they should not subscribe to, guaranteeing that each shard of a stream will always be assigned to one subtask in a uniformly distributed manner.
- Specified by:
assignin interfaceKinesisShardAssigner- Parameters:
streamShardHandle- the shard to determinenSubtasks- total number of subtasks- Returns:
- target index, if index falls outside of the range, modulus operation will be applied
-
-