Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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支持BroadcastState的状态TTL吗?_Apache Flink - Fatal编程技术网

Apache flink Flink支持BroadcastState的状态TTL吗?

Apache flink Flink支持BroadcastState的状态TTL吗?,apache-flink,Apache Flink,在Flink 1.8.1中,我尝试将状态TTL应用于BroadcastState(使用MapStateDescriptor),如下所示: (Holder是一个包含私有int变量“deger”的POJO) 。。。 StreamExecutionEnvironment envStream=StreamExecutionEnvironment.getExecutionEnvironment(); StateBackend StateBackend=新的FsStateBackend(“file://..

在Flink 1.8.1中,我尝试将状态TTL应用于BroadcastState(使用MapStateDescriptor),如下所示:

(Holder是一个包含私有int变量“deger”的POJO)

。。。
StreamExecutionEnvironment envStream=StreamExecutionEnvironment.getExecutionEnvironment();
StateBackend StateBackend=新的FsStateBackend(“file://.....");
setStateBackend(stateBackend);
envStream.enableCheckpointing(1_000L,CheckpointingMode.恰好\u一次);
...
MapStateDescriptor clientMapStateDescriptor=新的MapStateDescriptor(
“客户端广播状态”,
基本类型信息.INT\u类型信息,
TypeInformation.of(新的TypeHint(){})
);
StateTtlConfig ttlConfig=StateTtlConfig
.新造船工(时间.秒(3))
//.cleanupfullshopshot()
//.cleanupInBackground()
.增量清理(100,false)
.setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite)
.setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
.build();
clientMapStateDescriptor.enableTimeToLive(ttlConfig);
DataStream clientDataStream=envStream.fromCollection(clientList);
//clientDataStream.print(“clientDataStream”);
BroadcastStream clientBroadcastStream=clientDataStream
.广播(clientMapStateDescriptor);
列表持有者列表=新数组列表(计数);
for(int i=0;i
holderList有足够的实例来测试状态中的条目是否被逐出

但是
广播状态
中的条目不会过期

我尝试过的事情:

  • 使用不同的状态后端(
    fsstatebend
  • 启用检查点
  • 显式访问映射状态值
我可能做错了什么?BroadcastState支持StateTL吗

如果没有,您能否提供一个示例,说明如何退出BroadcastState中的条目(使用MapStateDescriptor)?

根据中的说明,StateTL仅用于键控状态

BroadcastState中存储的项只能在BroadcastProcessFunction(或键控BroadcastProcessFunction)的processBroadcastElement方法中写入或清除,这意味着您必须在处理另一个广播元素的接收时执行此操作。您需要注意在所有并行实例中使用完全相同的逻辑,因为Flink希望每个实例都与BroadcastState的内容保持一致,如果您在此处执行任何不确定性或特定于实例的操作,可能会产生奇怪的结果

一种解决方案是广播由接收者解释为命令的流记录,以使广播状态的早期记录过期

根据中的说明,stateTL仅用于键控状态

BroadcastState中存储的项只能在BroadcastProcessFunction(或键控BroadcastProcessFunction)的processBroadcastElement方法中写入或清除,这意味着您必须在处理另一个广播元素的接收时执行此操作。您需要注意在所有并行实例中使用完全相同的逻辑,因为Flink希望每个实例都与BroadcastState的内容保持一致,如果您在此处执行任何不确定性或特定于实例的操作,可能会产生奇怪的结果


一种解决方案是广播由接收者解释为命令的流记录,以使广播状态的早期记录过期

所以,
BroadcastState
不支持
StateTTL
,对吗?在
processBroadcastElement
方法中处理逐出的缺点是,除非
BroadcastState
支持
StateTL
,否则在收到新的广播元素之前,实际上没有机会逐出条目,所以,
BroadcastState
不支持
StateTL
,对吗?在
processBroadcastElement
方法中处理逐出的缺点是,在接收到新的广播元素之前,实际上没有机会逐出条目,除非
BroadcastState
支持
StateTL
...

        StreamExecutionEnvironment envStream = StreamExecutionEnvironment.getExecutionEnvironment();
        StateBackend stateBackend = new FsStateBackend("file://.....");
        envStream.setStateBackend(stateBackend);
        envStream.enableCheckpointing(1_000L, CheckpointingMode.EXACTLY_ONCE);

...

        MapStateDescriptor<Integer, Client> clientMapStateDescriptor = new MapStateDescriptor<>(
            "ClientBroadcastState",
            BasicTypeInfo.INT_TYPE_INFO,
            TypeInformation.of(new TypeHint<Client>() {})
        );
        StateTtlConfig ttlConfig = StateTtlConfig
            .newBuilder(Time.seconds(3))
            // .cleanupFullSnapshot()
            // .cleanupInBackground()
            .cleanupIncrementally(100, false)
            .setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite)
            .setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
            .build();
        clientMapStateDescriptor.enableTimeToLive(ttlConfig);

        DataStream<Client> clientDataStream = envStream.fromCollection(clientList);
        // clientDataStream.print("clientDataStream");

        BroadcastStream<Client> clientBroadcastStream = clientDataStream
            .broadcast(clientMapStateDescriptor);

        List<Holder> holderList = new ArrayList<>(count);
        for(int i = 0; i < count; i++) {
            holderList.add(new Holder(i));
        }
        DataStream<Holder> integerHolderDataStream = envStream.fromCollection(holderList);

        BroadcastConnectedStream<Holder, Client> connectedStreams = integerHolderDataStream
            .keyBy("deger")
            .connect(clientBroadcastStream);

        SingleOutputStreamOperator<Row> operator = connectedStreams.process(new KeyedBroadcastProcessFunction<Integer, Holder, Client, Row>() {

            @Override
            public void processElement(Holder value, ReadOnlyContext ctx, Collector<Row> out) throws Exception {
                for (Map.Entry<Integer, Client> entry : ctx.getBroadcastState(clientMapStateDescriptor).immutableEntries()) {
                    Client c = ctx.getBroadcastState(clientMapStateDescriptor).get(entry.getKey());
                    System.out.println(value.getDeger() + " - " + c);
                }
                Thread.sleep(1000L);
            }

            @Override
            public void processBroadcastElement(Client value, Context ctx, Collector<Row> out) throws Exception {
                ctx.getBroadcastState(clientMapStateDescriptor).put(value.getId(), value);
            }

        });

...