首页 > 解决方案 > 如何在 KeyedStream 中获取槽分布

问题描述

我使用 flink 版本 1.13.0。

出于某种原因,我需要在 taskmanager 中跟踪指定键的日志,但我不知道该键将分配给哪个 taskmanager。

所以我想知道当我使用 keyBy 函数时将分配给哪个插槽,是否有一些分区算法可以通过键计算插槽 id?

标签: apache-flinkflink-streaming

解决方案


这发生在几个步骤中。键映射到键组,键组分配给槽。您将在org.apache.flink.runtime.state.KeyGroupRangeAssignment. 从这里开始:

/**
  * 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));
}

推荐阅读