Apache Flink资源管理器(App Master)在第一个任务管理器在空闲超时后被杀死后无法分配新的任务管理器。
创始人
2024-09-04 02:01:39
0

在Apache Flink中,可以通过设置slot.timeout属性来解决任务管理器空闲超时问题。以下是一个示例代码,说明如何设置slot.timeout属性:

import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.JobManagerOptions;
import org.apache.flink.runtime.jobmaster.JobMaster;
import org.apache.flink.runtime.jobmaster.slotpool.SlotPool;
import org.apache.flink.runtime.jobmaster.slotpool.SlotReport;
import org.apache.flink.runtime.jobmaster.slotpool.SlotRequest;
import org.apache.flink.runtime.resourcemanager.ResourceManager;
import org.apache.flink.runtime.resourcemanager.SlotRequestTimeoutListener;
import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager;
import org.apache.flink.runtime.taskexecutor.slot.SlotOffer;
import org.apache.flink.util.Preconditions;

import javax.annotation.Nullable;

public class CustomResourceManager extends ResourceManager {

    // 定义空闲超时时间
    private final long idleTimeout;

    public CustomResourceManager(
            Configuration configuration,
            SlotManager slotManager,
            SlotPool slotPool,
            JobMaster jobMaster,
            long idleTimeout) {
        super(configuration, slotManager, slotPool, jobMaster);

        Preconditions.checkArgument(idleTimeout >= 0, "Idle timeout must be >= 0");
        this.idleTimeout = idleTimeout;
    }

    @Override
    public void start() throws Exception {
        super.start();

        // 注册空闲超时监听器
        getFencingToken().getLeaderElectionService().addListener(
                new SlotRequestTimeoutListener(getFencingToken().toUUID(), getIdleTimeout()));
    }

    public long getIdleTimeout() {
        return idleTimeout;
    }

    public static CustomResourceManager create(
            Configuration configuration,
            SlotManager slotManager,
            SlotPool slotPool,
            JobMaster jobMaster,
            long idleTimeout) throws Exception {
        return new CustomResourceManager(configuration, slotManager, slotPool, jobMaster, idleTimeout);
    }

    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration();
        // 设置任务管理器空闲超时时间为10分钟
        configuration.setLong(JobManagerOptions.SLOT_IDLE_TIMEOUT, 600000);

        // 创建自定义资源管理器
        CustomResourceManager resourceManager = create(
                configuration,
                slotManager,
                slotPool,
                jobMaster,
                600000);

        // 启动资源管理器
        resourceManager.start();
    }
}

在上述代码中,CustomResourceManager类继承自ResourceManager类,并添加了一个idleTimeout成员变量,表示任务管理器空闲超时时间。在start()方法中,注册了一个空闲超时监听器,当任务管理器空闲超时时,会触发该监听器。

main()方法中,通过JobManagerOptions.SLOT_IDLE_TIMEOUT属性设置了任务管理器的空闲超时时间为10分钟(600000毫秒),然后创建了一个CustomResourceManager实例,并调用start()方法启动资源管理器。

请根据你的实际情况调整超时时间和其他配置。

相关内容

热门资讯

安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
避免在粘贴双引号时向VS 20... 在粘贴双引号时向VS 2022添加反斜杠的问题通常是由于编辑器的自动转义功能引起的。为了避免这个问题...
Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
omi系统和安卓系统哪个好,揭... OMI系统和安卓系统哪个好?这个问题就像是在问“苹果和橘子哪个更甜”,每个人都有自己的答案。今天,我...
原生ios和安卓系统,原生对比... 亲爱的读者们,你是否曾好奇过,为什么你的iPhone和安卓手机在操作体验上有着天壤之别?今天,就让我...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...