如何在 KeyedStream 中获取插槽分布
How to get the slot distribution in a KeyedStream
我使用的是 flink 版本 1.13.0.
由于某些原因,我需要在任务管理器中跟踪指定键的日志,但我不知道该键将分配给哪个任务管理器。
所以我想知道当我使用keyBy函数时会分配给哪个slot,有没有一些分区算法可以通过key计算出slot id?
这需要几个步骤。键映射到键组,键组分配给槽。您将在 org.apache.flink.runtime.state.KeyGroupRangeAssignment
中找到所有相关代码。开始 here:
/**
* Assigns the given key to a parallel operator index.
*
* @param key the key to assign
* @param maxParallelism the maximum supported parallelism, aka the number of key-groups.
* @param parallelism the current parallelism of the operator
* @return the index of the parallel operator to which the given key should be routed.
*/
public static int assignKeyToParallelOperator(Object key, int maxParallelism, int parallelism) {
Preconditions.checkNotNull(key, "Assigned key must not be null!");
return computeOperatorIndexForKeyGroup(
maxParallelism, parallelism, assignToKeyGroup(key, maxParallelism));
}
我使用的是 flink 版本 1.13.0.
由于某些原因,我需要在任务管理器中跟踪指定键的日志,但我不知道该键将分配给哪个任务管理器。
所以我想知道当我使用keyBy函数时会分配给哪个slot,有没有一些分区算法可以通过key计算出slot id?
这需要几个步骤。键映射到键组,键组分配给槽。您将在 org.apache.flink.runtime.state.KeyGroupRangeAssignment
中找到所有相关代码。开始 here:
/**
* Assigns the given key to a parallel operator index.
*
* @param key the key to assign
* @param maxParallelism the maximum supported parallelism, aka the number of key-groups.
* @param parallelism the current parallelism of the operator
* @return the index of the parallel operator to which the given key should be routed.
*/
public static int assignKeyToParallelOperator(Object key, int maxParallelism, int parallelism) {
Preconditions.checkNotNull(key, "Assigned key must not be null!");
return computeOperatorIndexForKeyGroup(
maxParallelism, parallelism, assignToKeyGroup(key, maxParallelism));
}