问题
In my case, I use Flink's queryable state only. In particular, I do not care about checkpoints.
Upon an event, I query the queryable state only after a maximum of X minutes. Ideally, I would delete the "old" state to save on space.
That's why I wonder: can I signal Flink's state to clear itself after some time? Through configuration? Through specific event signals? How?
回答1:
One way to clear state is to explicitly call clear()
on the state object (e.g., a ValueState object) when you no longer need it for a particular key. This is typically done in an onTimer()
callback in a ProcessFunction
.
Another possible approach would be to use state time-to-live to manage its lifecycle.
I haven't tried using state TTL with queryable state, but I can't see any reason why it shouldn't work. However, as of Flink 1.7, state TTL only actually clears state (for a key) when the state is accessed (for that key), or when taking a full state snapshot. So in your particular case, this state TTL mechanism may not be very useful.
来源:https://stackoverflow.com/questions/54330034/flink-possible-to-delete-queryable-state-after-x-time