我在Flink有个Map州。我把ttl设置为10分钟。ttl是针对整个mapstate示例还是针对每个元素?
val ttlConfig = StateTtlConfig
.newBuilder(Time.minutes(10))
.setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite)
.setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
.build
val myMapState: MapState[String, Upload] = ....
myMapState.put("a", "x")
// 5 minutes later
myMapState.put("b", "y")
// Again 6 minutes later, is the myMapState still available?
// I assume myMapState is still available and it still has key "b" for 4 minutes. Is that correct?
1条答案
按热度按时间41ik7eoe1#
嗨,你的假设是正确的。
如果配置了ttl并且状态值已过期,则将尽最大努力清除存储的值。
因此,即使ttl已通过,也可能仍会存储该值,状态可见性配置将控制是否返回该值。
statettlconfig.statevisibility.neverreturnexpired-从不返回过期值
statettlconfig.statevisibility.ReturnExpireDefNotCleanedUp-如果仍然可用,则返回
有关州ttl的详细信息