Search code examples
apache-flink

How to set state.backend.rocksdb.localdir with code


I write and execute flink code in my local IDE using RocksDBStateBackend as the state backend.

The path specified in the RocksDBStateBackend's constructor is the path that is the checkpoint path that the local state data will be written into this path during checkpoint phrase.

There is an option state.backend.rocksdb.localdir that can be used to set the local rocksdb path,I would ask how to set this option with code, so that, I can specify the local storage path for the RocksDB state backend in my code,

state.checkpoints.num-retained is also another option that I want to set with code.

Thanks


Solution

  • You can do something like this:

    Configuration conf = new Configuration();
    conf.setString("state.backend", "rocksdb");
    conf.setString("state.backend.rocksdb.localdir", "/tmp");
    conf.setString("state.checkpoints.dir", "s3:///bucket/checkpoints");
    conf.setString("execution.checkpointing.interval", "10s");
    conf.setString("state.checkpoints.num-retained", "2");
    
    StreamExecutionEnvironment env =
      StreamExecutionEnvironment.getExecutionEnvironment(conf);