检查点故障恢复期间RichFunctions的生命周期是什么?

时间:2020-07-05 15:39:12

标签: apache-flink

我想知道对于扩展RichFunction的运营商, 发生异常后,Flink将为每个运算符调用close, 即使在运算符的open函数中引发了异常, 并且Flink在尝试从检查点恢复作业时是否再次调用open

对于上下文,我有一个过滤运算符,每个工作JVM应该有一个类的单个实例, 所以我使用静态原子引用

private static final AtomicReference<MyClass> SINGLETON = new AtomicReference<>(null);

@Override
public void open(Configuration parameters) throws Exception {
    super.open(parameters);
    SINGLETON.compareAndSet(null, new MyClass());
    SINGLETON.get().open(); // synchronized
}

@Override
public boolean filter(JsonNode value) {
    ...
    SINGLETON.get().doSomething();
    ...
}

@Override
public void close() throws Exception {
    MyClass singleton = SINGLETON.getAndSet(null);
    if (singleton != null) singleton.close();
}

但是,我见过SINGLETON.get().doSomething()最终抛出NullPointerException的系统。 从日志中脱颖而出的唯一一件事是作业最初失败并由于消息总线未准备好而重新启动 (过滤器运算符本身并未引发任何异常), 而且我不知道为什么有时候单身汉最终会变成null。

0 个答案:

没有答案
相关问题