Search in sources :

Example 26 with FsStateBackend

use of org.apache.flink.runtime.state.filesystem.FsStateBackend in project flink by apache.

the class CustomKvStateProgram method main.

public static void main(String[] args) throws Exception {
    final int parallelism = Integer.parseInt(args[0]);
    final String checkpointPath = args[1];
    final int checkpointingInterval = Integer.parseInt(args[2]);
    final String outputPath = args[3];
    final Optional<Boolean> unalignedCheckpoints = args.length > 4 ? Optional.of(Boolean.parseBoolean(args[4])) : Optional.empty();
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(parallelism);
    env.enableCheckpointing(checkpointingInterval);
    unalignedCheckpoints.ifPresent(value -> env.getCheckpointConfig().enableUnalignedCheckpoints(value));
    env.setStateBackend(new FsStateBackend(checkpointPath));
    DataStream<Integer> source = env.addSource(new InfiniteIntegerSource());
    source.map(new MapFunction<Integer, Tuple2<Integer, Integer>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Tuple2<Integer, Integer> map(Integer value) throws Exception {
            return new Tuple2<>(ThreadLocalRandom.current().nextInt(parallelism), value);
        }
    }).keyBy(new KeySelector<Tuple2<Integer, Integer>, Integer>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Integer getKey(Tuple2<Integer, Integer> value) throws Exception {
            return value.f0;
        }
    }).flatMap(new ReducingStateFlatMap()).writeAsText(outputPath);
    env.execute();
}
Also used : InfiniteIntegerSource(org.apache.flink.test.util.InfiniteIntegerSource) RichFlatMapFunction(org.apache.flink.api.common.functions.RichFlatMapFunction) MapFunction(org.apache.flink.api.common.functions.MapFunction) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend)

Example 27 with FsStateBackend

use of org.apache.flink.runtime.state.filesystem.FsStateBackend in project flink by apache.

the class KeyedStateCheckpointingITCase method testWithFsBackendAsync.

@Test
public void testWithFsBackendAsync() throws Exception {
    FsStateBackend asyncFsBackend = new FsStateBackend(tmpFolder.newFolder().toURI().toString(), true);
    testProgramWithBackend(asyncFsBackend);
}
Also used : FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) Test(org.junit.Test)

Example 28 with FsStateBackend

use of org.apache.flink.runtime.state.filesystem.FsStateBackend in project flink by apache.

the class KeyedStateCheckpointingITCase method testWithFsBackendSync.

@Test
public void testWithFsBackendSync() throws Exception {
    FsStateBackend syncFsBackend = new FsStateBackend(tmpFolder.newFolder().toURI().toString(), false);
    testProgramWithBackend(syncFsBackend);
}
Also used : FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) Test(org.junit.Test)

Aggregations

FsStateBackend (org.apache.flink.runtime.state.filesystem.FsStateBackend)28 Test (org.junit.Test)13 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)10 IOException (java.io.IOException)8 File (java.io.File)7 Configuration (org.apache.flink.configuration.Configuration)7 RocksDBStateBackend (org.apache.flink.contrib.streaming.state.RocksDBStateBackend)6 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)5 StateBackend (org.apache.flink.runtime.state.StateBackend)5 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)5 JobID (org.apache.flink.api.common.JobID)4 Path (org.apache.flink.core.fs.Path)4 Random (java.util.Random)3 RichFlatMapFunction (org.apache.flink.api.common.functions.RichFlatMapFunction)3 HashMapStateBackend (org.apache.flink.runtime.state.hashmap.HashMapStateBackend)3 URI (java.net.URI)2 FilterFunction (org.apache.flink.api.common.functions.FilterFunction)2 MapFunction (org.apache.flink.api.common.functions.MapFunction)2 ListState (org.apache.flink.api.common.state.ListState)2 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)2