一,在需要使用Flink,需要使用state过期的时候,没百度到怎么使用代码,我只记得自己以前写过一篇,还好翻出来了。
地址链接:https://blog.csdn.net/qq_31866793/article/details/102947285
二,目前Flink版本升级了,代码可能发生了一点点变化
如下所示:
1,启动过期清理
StateTtlConfig ttlConfig = StateTtlConfig
.newBuilder(org.apache.flink.api.common.time.Time.seconds(1))
.setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite)
.setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
.build();
MapStateDescriptor<String, Integer> mapStateDescriptor = new MapStateDescriptor<>(
"mapState",
String.class,
Integer.class);
mapStateDescriptor.enableTimeToLive(ttlConfig);
testMap = getRuntimeContext().getMapState(mapStateDescriptor);
2,完整快照清理
StateTtlConfig ttlConfig = StateTtlConfig
.newBuilder(org.apache.flink.api.common.time.Time.seconds(1))
.cleanupFullSnapshot()
.build();
MapStateDescriptor<String, Integer> mapStateDescriptor = new MapStateDescriptor<>(
"mapState",
String.class,
Integer.class);
m