Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flink 在Flink中的有状态流运算符函数中使用有状态帮助器类_Apache Flink - Fatal编程技术网

Apache flink 在Flink中的有状态流运算符函数中使用有状态帮助器类

Apache flink 在Flink中的有状态流运算符函数中使用有状态帮助器类,apache-flink,Apache Flink,我们可以在Flink操作符函数中使用引用Flink状态的帮助器类吗。文档示例都显示了来自Flink state api的对象,这些对象被Operator直接引用为字段。但我想知道如果我将状态移动到另一个类中,容错性是否会受到影响,例如: ///Operator function with reference to a stateful helper class public class SomeStatefulFunction extends RichMapFunction<SomeInp

我们可以在Flink操作符函数中使用引用Flink状态的帮助器类吗。文档示例都显示了来自Flink state api的对象,这些对象被Operator直接引用为字段。但我想知道如果我将状态移动到另一个类中,容错性是否会受到影响,例如:

///Operator function with reference to a stateful helper class
public class SomeStatefulFunction extends RichMapFunction<SomeInput, SomeOutput> {

    private SomeStatefulHelper helperInstance1;
    private SomeStatefulHelper helperInstance2;

    @Override
    public SomeOutput map(SomeInput someInput) throws Exception {
        return combineOutput(helperInstance1.helperMethod(someInput), helperInstance2.helperMethod(someInput));
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);

        this.helperInstance1 = createHelper("helperConfig1", "someMapState1");
        this.helperInstance2 = createHelper("helperConfig2", "someMapState2");

    }

    private SomeStatefulHelper createHelper(String helperConfig, String stateName) {
        MapStateDescriptor<Integer, Integer> descriptor =
                new MapStateDescriptor<>(stateName, Integer.class, Integer.class);
        MapState<Integer, Integer> mapState = getRuntimeContext().getMapState(descriptor);
        return new SomeStatefulHelper(helperConfig, mapState);
    }

    private SomeOutput combineOutput(SomeOutput output1, SomeOutput output2) {
        //Some way to combine output
    }
}

///Stateful helper class
public class SomeStatefulHelper {
    private MapState<Integer, Integer> state;
    private String helperConfig;

    public SomeStatefulHelper(String helperConfig, MapState<Integer, Integer> state) {
        this.state = state;
        this.helperConfig = helperConfig;
    }

    public SomeOutput helperMethod(SomeInput input) {
        //return something based on input, state, and helperConfig
    }
}
///引用有状态帮助器类的运算符函数
公共类SomeStatefulFunction扩展了RichMapFunction{
private SomeStateful Helper HelperInstance 1;
私人状态助手状态2;
@凌驾
公共SomeOutput映射(SomeInput SomeInput)引发异常{
返回combineOutput(helperInstance1.helperMethod(someInput),helperInstance2.helperMethod(someInput));
}
@凌驾
公共void open(配置参数)引发异常{
super.open(参数);
this.helperInstance1=createHelper(“helperConfig1”、“someMapState1”);
this.helperInstance2=createHelper(“helperConfig2”、“someMapState2”);
}
私有SomeStatefHelper createHelper(字符串helperConfig,字符串stateName){
MapStateDescriptor描述符=
新的MapStateDescriptor(stateName,Integer.class,Integer.class);
MapState MapState=getRuntimeContext().getMapState(描述符);
返回新的SomeStatefHelper(helperConfig,mapState);
}
专用SomeOutput组合输出(SomeOutput输出1,SomeOutput输出2){
//组合输出的一些方法
}
}
///有状态辅助类
公共类SomeStatefulHelper{
私人国家;
私有字符串helperConfig;
public SomeStatefulHelper(字符串helperConfig,映射状态){
this.state=状态;
this.helperConfig=helperConfig;
}
公共SomeOutput helperMethod(SomeInput-input){
//根据输入、状态和helperConfig返回某些内容
}
}

我有一个使用此“模式”的作业,它在处理方面起作用,但我不确定在发生故障时是否会恢复状态?

它不应该影响状态恢复,因为状态是在单独的类中创建的还是直接在
open
方法中创建的并不重要。在状态恢复时,操作符仍将调用相同的方法。因此,只要在
open
方法中创建类,就可以了