我在flink中有一个MapState。我将 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?
最佳答案
您好,您的假设是正确的。
If a TTL is configured and a state value has expired, the stored value will be cleaned up on a best effort basis.
因此,即使 TTL 已过,该值仍可能被存储,状态可见性配置将控制是否返回该值。
StateTtlConfig.StateVisibility.NeverReturnExpired - 过期值为 再也没有回来
StateTtlConfig.StateVisibility.ReturnExpiredIfNotCleanedUp - 返回 如果仍然可用
有关 state TTL 的更多信息
关于state - flink MapState 的 TTL 是针对整个 MapState 实例还是针对 MapState 中的每个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58398867/