Search in sources :

Example 21 with FsStateBackend

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

the class StateBackendLoadingTest method testLoadFileSystemStateBackendMixed.

/**
 * Validates taking the application-defined file system state backend and adding with additional
 * parameters from the cluster configuration, but giving precedence to application-defined
 * parameters over configuration-defined parameters.
 */
@Test
public void testLoadFileSystemStateBackendMixed() throws Exception {
    final String appCheckpointDir = new Path(tmp.newFolder().toURI()).toString();
    final String checkpointDir = new Path(tmp.newFolder().toURI()).toString();
    final String savepointDir = new Path(tmp.newFolder().toURI()).toString();
    final Path expectedCheckpointsPath = new Path(new URI(appCheckpointDir));
    final Path expectedSavepointsPath = new Path(savepointDir);
    final int threshold = 1000000;
    final int writeBufferSize = 4000000;
    final FsStateBackend backend = new FsStateBackend(new URI(appCheckpointDir), null, threshold, writeBufferSize, TernaryBoolean.TRUE);
    final Configuration config = new Configuration();
    // this should not be picked up
    config.setString(backendKey, "jobmanager");
    config.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, // this should not be picked up
    checkpointDir);
    config.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
    config.set(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, // this should not be picked up
    MemorySize.parse("20"));
    config.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, // this should not be picked up
    3000000);
    final StateBackend loadedBackend = StateBackendLoader.fromApplicationOrConfigOrDefault(backend, TernaryBoolean.UNDEFINED, config, cl, null);
    assertTrue(loadedBackend instanceof FsStateBackend);
    final FsStateBackend fs = (FsStateBackend) loadedBackend;
    assertEquals(expectedCheckpointsPath, fs.getCheckpointPath());
    assertEquals(expectedSavepointsPath, fs.getSavepointPath());
    assertEquals(threshold, fs.getMinFileSizeThreshold());
    assertEquals(writeBufferSize, fs.getWriteBufferSize());
}
Also used : Path(org.apache.flink.core.fs.Path) Configuration(org.apache.flink.configuration.Configuration) URI(java.net.URI) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) Test(org.junit.Test)

Example 22 with FsStateBackend

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

the class RocksDBTtlStateTestBase method createStateBackend.

StateBackend createStateBackend(TernaryBoolean enableIncrementalCheckpointing) {
    String dbPath;
    String checkpointPath;
    try {
        dbPath = tempFolder.newFolder().getAbsolutePath();
        checkpointPath = tempFolder.newFolder().toURI().toString();
    } catch (IOException e) {
        throw new FlinkRuntimeException("Failed to init rocksdb test state backend");
    }
    RocksDBStateBackend backend = new RocksDBStateBackend(new FsStateBackend(checkpointPath), enableIncrementalCheckpointing);
    Configuration config = new Configuration();
    backend = backend.configure(config, Thread.currentThread().getContextClassLoader());
    backend.setDbStoragePath(dbPath);
    return backend;
}
Also used : RocksDBStateBackend(org.apache.flink.contrib.streaming.state.RocksDBStateBackend) Configuration(org.apache.flink.configuration.Configuration) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend)

Example 23 with FsStateBackend

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

the class RocksDBStateBackendMigrationTest method getStateBackend.

@Override
protected RocksDBStateBackend getStateBackend() throws IOException {
    dbPath = tempFolder.newFolder().getAbsolutePath();
    String checkpointPath = tempFolder.newFolder().toURI().toString();
    RocksDBStateBackend backend = new RocksDBStateBackend(new FsStateBackend(checkpointPath), enableIncrementalCheckpointing);
    Configuration configuration = new Configuration();
    configuration.set(RocksDBOptions.TIMER_SERVICE_FACTORY, EmbeddedRocksDBStateBackend.PriorityQueueStateType.ROCKSDB);
    backend = backend.configure(configuration, Thread.currentThread().getContextClassLoader());
    backend.setDbStoragePath(dbPath);
    return backend;
}
Also used : Configuration(org.apache.flink.configuration.Configuration) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend)

Example 24 with FsStateBackend

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

the class CheckpointCoordinatorTest method testBaseLocationsNotInitialized.

@Test
public void testBaseLocationsNotInitialized() throws Exception {
    File checkpointDir = tmpFolder.newFolder();
    JobVertexID jobVertexID = new JobVertexID();
    ExecutionGraph graph = new CheckpointCoordinatorTestingUtils.CheckpointExecutionGraphBuilder().addJobVertex(jobVertexID).setTransitToRunning(false).build();
    CheckpointCoordinator checkpointCoordinator = new CheckpointCoordinatorBuilder().setExecutionGraph(graph).setCheckpointCoordinatorConfiguration(CheckpointCoordinatorConfiguration.builder().setCheckpointInterval(Long.MAX_VALUE).build()).setCheckpointStorage(new FsStateBackend(checkpointDir.toURI())).build();
    Path jobCheckpointPath = new Path(checkpointDir.getAbsolutePath(), graph.getJobID().toString());
    FileSystem fs = FileSystem.get(checkpointDir.toURI());
    // directory will not be created if checkpointing is disabled
    Assert.assertFalse(fs.exists(jobCheckpointPath));
}
Also used : Path(org.apache.flink.core.fs.Path) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) FileSystem(org.apache.flink.core.fs.FileSystem) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) File(java.io.File) CheckpointCoordinatorBuilder(org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) Test(org.junit.Test)

Example 25 with FsStateBackend

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

the class StreamOperatorSnapshotRestoreTest method testOperatorStatesSnapshotRestoreInternal.

private void testOperatorStatesSnapshotRestoreInternal(final int mode) throws Exception {
    // -------------------------------------------------------------------------- snapshot
    StateBackend stateBackend;
    FsStateBackend fsstateBackend = createStateBackendInternal();
    switch(stateBackendEnum) {
        case FILE:
            stateBackend = fsstateBackend;
            break;
        case ROCKSDB_FULLY_ASYNC:
            stateBackend = new RocksDBStateBackend(fsstateBackend, TernaryBoolean.FALSE);
            break;
        case ROCKSDB_INCREMENTAL:
            stateBackend = new RocksDBStateBackend(fsstateBackend, TernaryBoolean.TRUE);
            break;
        default:
            throw new IllegalStateException(String.format("Do not support statebackend type %s", stateBackendEnum));
    }
    TestOneInputStreamOperator op = new TestOneInputStreamOperator(false);
    JobID jobID = new JobID();
    JobVertexID jobVertexID = new JobVertexID();
    int subtaskIdx = 0;
    LocalRecoveryDirectoryProvider directoryProvider = mode == ONLY_JM_RECOVERY ? null : new LocalRecoveryDirectoryProviderImpl(temporaryFolder.newFolder(), jobID, jobVertexID, subtaskIdx);
    LocalRecoveryConfig localRecoveryConfig = new LocalRecoveryConfig(directoryProvider);
    MockEnvironment mockEnvironment = new MockEnvironmentBuilder().setJobID(jobID).setJobVertexID(jobVertexID).setTaskName("test").setManagedMemorySize(1024L * 1024L).setInputSplitProvider(new MockInputSplitProvider()).setBufferSize(1024 * 1024).setTaskStateManager(new TestTaskStateManager(localRecoveryConfig)).setMaxParallelism(MAX_PARALLELISM).setSubtaskIndex(subtaskIdx).setUserCodeClassLoader(getClass().getClassLoader()).build();
    KeyedOneInputStreamOperatorTestHarness<Integer, Integer, Integer> testHarness = new KeyedOneInputStreamOperatorTestHarness<>(op, (KeySelector<Integer, Integer>) value -> value, TypeInformation.of(Integer.class), mockEnvironment);
    testHarness.setStateBackend(stateBackend);
    testHarness.open();
    for (int i = 0; i < 10; ++i) {
        testHarness.processElement(new StreamRecord<>(i));
    }
    OperatorSnapshotFinalizer snapshotWithLocalState = testHarness.snapshotWithLocalState(1L, 1L);
    testHarness.close();
    // -------------------------------------------------------------------------- restore
    op = new TestOneInputStreamOperator(true);
    testHarness = new KeyedOneInputStreamOperatorTestHarness<>(op, (KeySelector<Integer, Integer>) value -> value, TypeInformation.of(Integer.class), MAX_PARALLELISM, 1, /* num subtasks */
    0);
    testHarness.setTimeServiceManagerProvider(new InternalTimeServiceManager.Provider() {

        @Override
        public <K> InternalTimeServiceManager<K> create(CheckpointableKeyedStateBackend<K> keyedStatedBackend, ClassLoader userClassloader, KeyContext keyContext, ProcessingTimeService processingTimeService, Iterable<KeyGroupStatePartitionStreamProvider> rawKeyedStates) throws IOException {
            return null;
        }
    });
    testHarness.setStateBackend(stateBackend);
    OperatorSubtaskState jobManagerOwnedState = snapshotWithLocalState.getJobManagerOwnedState();
    OperatorSubtaskState taskLocalState = snapshotWithLocalState.getTaskLocalState();
    // We check if local state was created when we enabled local recovery
    Assert.assertTrue(mode > ONLY_JM_RECOVERY == (taskLocalState != null && taskLocalState.hasState()));
    if (mode == TM_REMOVE_JM_RECOVERY) {
        jobManagerOwnedState.getManagedKeyedState().discardState();
    } else if (mode == JM_REMOVE_TM_RECOVERY) {
        taskLocalState.getManagedKeyedState().discardState();
    }
    testHarness.initializeState(jobManagerOwnedState, taskLocalState);
    testHarness.open();
    for (int i = 0; i < 10; ++i) {
        testHarness.processElement(new StreamRecord<>(i));
    }
    testHarness.close();
}
Also used : InternalTimeServiceManager(org.apache.flink.streaming.api.operators.InternalTimeServiceManager) Arrays(java.util.Arrays) OperatorSnapshotFinalizer(org.apache.flink.streaming.api.operators.OperatorSnapshotFinalizer) LocalRecoveryConfig(org.apache.flink.runtime.state.LocalRecoveryConfig) KeyedOneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness) DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) ListState(org.apache.flink.api.common.state.ListState) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) StateBackend(org.apache.flink.runtime.state.StateBackend) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) TestLogger(org.apache.flink.util.TestLogger) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) Parameterized(org.junit.runners.Parameterized) LocalRecoveryDirectoryProviderImpl(org.apache.flink.runtime.state.LocalRecoveryDirectoryProviderImpl) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) StateSnapshotContext(org.apache.flink.runtime.state.StateSnapshotContext) AfterClass(org.junit.AfterClass) KeySelector(org.apache.flink.api.java.functions.KeySelector) KeyContext(org.apache.flink.streaming.api.operators.KeyContext) MockInputSplitProvider(org.apache.flink.runtime.operators.testutils.MockInputSplitProvider) Collection(java.util.Collection) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) TernaryBoolean(org.apache.flink.util.TernaryBoolean) ValueState(org.apache.flink.api.common.state.ValueState) OperatorStateCheckpointOutputStream(org.apache.flink.runtime.state.OperatorStateCheckpointOutputStream) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) LocalRecoveryDirectoryProvider(org.apache.flink.runtime.state.LocalRecoveryDirectoryProvider) StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) BeforeClass(org.junit.BeforeClass) KeyedStateCheckpointOutputStream(org.apache.flink.runtime.state.KeyedStateCheckpointOutputStream) RunWith(org.junit.runner.RunWith) Watermark(org.apache.flink.streaming.api.watermark.Watermark) DataOutputView(org.apache.flink.core.memory.DataOutputView) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) DataInputView(org.apache.flink.core.memory.DataInputView) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) CheckpointableKeyedStateBackend(org.apache.flink.runtime.state.CheckpointableKeyedStateBackend) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) ProcessingTimeService(org.apache.flink.streaming.runtime.tasks.ProcessingTimeService) Test(org.junit.Test) IOException(java.io.IOException) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) File(java.io.File) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) RocksDBStateBackend(org.apache.flink.contrib.streaming.state.RocksDBStateBackend) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) JobID(org.apache.flink.api.common.JobID) BitSet(java.util.BitSet) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) StateInitializationContext(org.apache.flink.runtime.state.StateInitializationContext) InputStream(java.io.InputStream) RocksDBStateBackend(org.apache.flink.contrib.streaming.state.RocksDBStateBackend) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) LocalRecoveryDirectoryProvider(org.apache.flink.runtime.state.LocalRecoveryDirectoryProvider) LocalRecoveryDirectoryProviderImpl(org.apache.flink.runtime.state.LocalRecoveryDirectoryProviderImpl) KeySelector(org.apache.flink.api.java.functions.KeySelector) StateBackend(org.apache.flink.runtime.state.StateBackend) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) CheckpointableKeyedStateBackend(org.apache.flink.runtime.state.CheckpointableKeyedStateBackend) RocksDBStateBackend(org.apache.flink.contrib.streaming.state.RocksDBStateBackend) KeyedOneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) KeyContext(org.apache.flink.streaming.api.operators.KeyContext) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) ProcessingTimeService(org.apache.flink.streaming.runtime.tasks.ProcessingTimeService) MockInputSplitProvider(org.apache.flink.runtime.operators.testutils.MockInputSplitProvider) InternalTimeServiceManager(org.apache.flink.streaming.api.operators.InternalTimeServiceManager) LocalRecoveryConfig(org.apache.flink.runtime.state.LocalRecoveryConfig) IOException(java.io.IOException) OperatorSnapshotFinalizer(org.apache.flink.streaming.api.operators.OperatorSnapshotFinalizer) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) JobID(org.apache.flink.api.common.JobID)

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