Hi, everyone! I'm having trouble to make TTL work ...
# troubleshooting
m
Hi, everyone! I'm having trouble to make TTL work in pyflink, need help I use pyflink 1.18.0 inside a docker environment, tried both hashmap and rocksdb backends. Here is an example where I would expect ttl to work and memory behave properly, but it grows linearly until the pod crashes. Flink config (also tried RocksDB, couldn't make it work either)
Copy code
taskmanager.memory.task.off-heap.size: 256mb
taskmanager.memory.managed.size: 128mb

state.backend.type: hashmap
state.backend.incremental: "true"
state.checkpoints.dir: null
state.savepoints.dir: null
TTL is 1 second with incremental cleanup I don't use checkpoints and savepoints to keep it simple. State config:
Copy code
def open(self, runtime_context: RuntimeContext):
        state_descriptor = ValueStateDescriptor(
            name="my_state",
            value_type_info=Types.STRING(),
        )

        state_descriptor.enable_time_to_live(
            ttl_config=StateTtlConfig.new_builder(Time.seconds(1))
            .cleanup_incrementally(cleanup_size=10, run_cleanup_for_every_record=True)
            .set_update_type(StateTtlConfig.UpdateType.OnCreateAndWrite)
            .set_state_visibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
            .build()
        )

        self.state = runtime_context.get_state(state_descriptor)
Sample piece of output, formatted
Copy code
LOG_TIMESTAMP:      2024-02-23 13:19:55,729
STATE VALUE TYPE:   class 'str' (expected to see `NoneType`) 
STATE VALUE PREFIX: 2024-02-23 12:12:49.374857 (I write current timestamp + some heavy string to demonstrate memory growth)
You can see in the snippet that it's been more than an hour since the state was created, but it's still there. Does anyone have a working pyflink setup with TTL he can share? Do you have any ideas what I can do to make it work? Slack Conversation