org.apache.flink.runtime.state.filesystem.FsStateBackendFactory Java Examples

The following examples show how to use org.apache.flink.runtime.state.filesystem.FsStateBackendFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateBackendLoadingTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Validates loading a file system state backend with additional parameters from the cluster configuration.
 */
@Test
public void testLoadFileSystemStateBackend() throws Exception {
	final String checkpointDir = new Path(tmp.newFolder().toURI()).toString();
	final String savepointDir = new Path(tmp.newFolder().toURI()).toString();
	final Path expectedCheckpointsPath = new Path(checkpointDir);
	final Path expectedSavepointsPath = new Path(savepointDir);
	final int threshold = 1000000;
	final boolean async = !CheckpointingOptions.ASYNC_SNAPSHOTS.defaultValue();

	// we configure with the explicit string (rather than AbstractStateBackend#X_STATE_BACKEND_NAME)
	// to guard against config-breaking changes of the name 
	final Configuration config1 = new Configuration();
	config1.setString(backendKey, "filesystem");
	config1.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
	config1.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
	config1.setInteger(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
	config1.setBoolean(CheckpointingOptions.ASYNC_SNAPSHOTS, async);

	final Configuration config2 = new Configuration();
	config2.setString(backendKey, FsStateBackendFactory.class.getName());
	config2.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
	config2.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
	config2.setInteger(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
	config2.setBoolean(CheckpointingOptions.ASYNC_SNAPSHOTS, async);

	StateBackend backend1 = StateBackendLoader.loadStateBackendFromConfig(config1, cl, null);
	StateBackend backend2 = StateBackendLoader.loadStateBackendFromConfig(config2, cl, null);

	assertTrue(backend1 instanceof FsStateBackend);
	assertTrue(backend2 instanceof FsStateBackend);

	FsStateBackend fs1 = (FsStateBackend) backend1;
	FsStateBackend fs2 = (FsStateBackend) backend2;

	assertEquals(expectedCheckpointsPath, fs1.getCheckpointPath());
	assertEquals(expectedCheckpointsPath, fs2.getCheckpointPath());
	assertEquals(expectedSavepointsPath, fs1.getSavepointPath());
	assertEquals(expectedSavepointsPath, fs2.getSavepointPath());
	assertEquals(threshold, fs1.getMinFileSizeThreshold());
	assertEquals(threshold, fs2.getMinFileSizeThreshold());
	assertEquals(async, fs1.isUsingAsynchronousSnapshots());
	assertEquals(async, fs2.isUsingAsynchronousSnapshots());
}
 
Example #2
Source File: StateBackendLoadingTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Validates loading a file system state backend with additional parameters from the cluster configuration.
 */
@Test
public void testLoadFileSystemStateBackend() throws Exception {
	final String checkpointDir = new Path(tmp.newFolder().toURI()).toString();
	final String savepointDir = new Path(tmp.newFolder().toURI()).toString();
	final Path expectedCheckpointsPath = new Path(checkpointDir);
	final Path expectedSavepointsPath = new Path(savepointDir);
	final int threshold = 1000000;
	final int minWriteBufferSize = 1024;
	final boolean async = !CheckpointingOptions.ASYNC_SNAPSHOTS.defaultValue();

	// we configure with the explicit string (rather than AbstractStateBackend#X_STATE_BACKEND_NAME)
	// to guard against config-breaking changes of the name 
	final Configuration config1 = new Configuration();
	config1.setString(backendKey, "filesystem");
	config1.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
	config1.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
	config1.setInteger(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
	config1.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, minWriteBufferSize);
	config1.setBoolean(CheckpointingOptions.ASYNC_SNAPSHOTS, async);

	final Configuration config2 = new Configuration();
	config2.setString(backendKey, FsStateBackendFactory.class.getName());
	config2.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
	config2.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
	config2.setInteger(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
	config1.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, minWriteBufferSize);
	config2.setBoolean(CheckpointingOptions.ASYNC_SNAPSHOTS, async);

	StateBackend backend1 = StateBackendLoader.loadStateBackendFromConfig(config1, cl, null);
	StateBackend backend2 = StateBackendLoader.loadStateBackendFromConfig(config2, cl, null);

	assertTrue(backend1 instanceof FsStateBackend);
	assertTrue(backend2 instanceof FsStateBackend);

	FsStateBackend fs1 = (FsStateBackend) backend1;
	FsStateBackend fs2 = (FsStateBackend) backend2;

	assertEquals(expectedCheckpointsPath, fs1.getCheckpointPath());
	assertEquals(expectedCheckpointsPath, fs2.getCheckpointPath());
	assertEquals(expectedSavepointsPath, fs1.getSavepointPath());
	assertEquals(expectedSavepointsPath, fs2.getSavepointPath());
	assertEquals(threshold, fs1.getMinFileSizeThreshold());
	assertEquals(threshold, fs2.getMinFileSizeThreshold());
	assertEquals(Math.max(threshold, minWriteBufferSize), fs1.getWriteBufferSize());
	assertEquals(Math.max(threshold, minWriteBufferSize), fs2.getWriteBufferSize());
	assertEquals(async, fs1.isUsingAsynchronousSnapshots());
	assertEquals(async, fs2.isUsingAsynchronousSnapshots());
}
 
Example #3
Source File: StateBackendLoadingTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Validates loading a file system state backend with additional parameters from the cluster configuration.
 */
@Test
public void testLoadFileSystemStateBackend() throws Exception {
	final String checkpointDir = new Path(tmp.newFolder().toURI()).toString();
	final String savepointDir = new Path(tmp.newFolder().toURI()).toString();
	final Path expectedCheckpointsPath = new Path(checkpointDir);
	final Path expectedSavepointsPath = new Path(savepointDir);
	final MemorySize threshold = MemorySize.parse("900kb");
	final int minWriteBufferSize = 1024;
	final boolean async = !CheckpointingOptions.ASYNC_SNAPSHOTS.defaultValue();

	// we configure with the explicit string (rather than AbstractStateBackend#X_STATE_BACKEND_NAME)
	// to guard against config-breaking changes of the name 
	final Configuration config1 = new Configuration();
	config1.setString(backendKey, "filesystem");
	config1.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
	config1.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
	config1.set(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
	config1.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, minWriteBufferSize);
	config1.setBoolean(CheckpointingOptions.ASYNC_SNAPSHOTS, async);

	final Configuration config2 = new Configuration();
	config2.setString(backendKey, FsStateBackendFactory.class.getName());
	config2.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
	config2.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
	config2.set(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
	config1.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, minWriteBufferSize);
	config2.setBoolean(CheckpointingOptions.ASYNC_SNAPSHOTS, async);

	StateBackend backend1 = StateBackendLoader.loadStateBackendFromConfig(config1, cl, null);
	StateBackend backend2 = StateBackendLoader.loadStateBackendFromConfig(config2, cl, null);

	assertTrue(backend1 instanceof FsStateBackend);
	assertTrue(backend2 instanceof FsStateBackend);

	FsStateBackend fs1 = (FsStateBackend) backend1;
	FsStateBackend fs2 = (FsStateBackend) backend2;

	assertEquals(expectedCheckpointsPath, fs1.getCheckpointPath());
	assertEquals(expectedCheckpointsPath, fs2.getCheckpointPath());
	assertEquals(expectedSavepointsPath, fs1.getSavepointPath());
	assertEquals(expectedSavepointsPath, fs2.getSavepointPath());
	assertEquals(threshold.getBytes(), fs1.getMinFileSizeThreshold());
	assertEquals(threshold.getBytes(), fs2.getMinFileSizeThreshold());
	assertEquals(Math.max(threshold.getBytes(), minWriteBufferSize), fs1.getWriteBufferSize());
	assertEquals(Math.max(threshold.getBytes(), minWriteBufferSize), fs2.getWriteBufferSize());
	assertEquals(async, fs1.isUsingAsynchronousSnapshots());
	assertEquals(async, fs2.isUsingAsynchronousSnapshots());
}