org.apache.flink.runtime.state.CheckpointedStateScope Java Examples

The following examples show how to use org.apache.flink.runtime.state.CheckpointedStateScope. 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: RocksDBStateUploaderTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test that the exception arose in the thread pool will rethrow to the main thread.
 */
@Test
public void testMultiThreadUploadThreadPoolExceptionRethrow() throws IOException {
	SpecifiedException expectedException = new SpecifiedException("throw exception while multi thread upload states.");

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream = createFailingCheckpointStateOutputStream(expectedException);
	CheckpointStreamFactory checkpointStreamFactory = (CheckpointedStateScope scope) -> outputStream;

	File file = temporaryFolder.newFile(String.valueOf(UUID.randomUUID()));
	generateRandomFileContent(file.getPath(), 20);

	Map<StateHandleID, Path> filePaths = new HashMap<>(1);
	filePaths.put(new StateHandleID("mockHandleID"), new Path(file.getPath()));
	try (RocksDBStateUploader rocksDBStateUploader = new RocksDBStateUploader(5)) {
		rocksDBStateUploader.uploadFilesToCheckpointFs(filePaths, checkpointStreamFactory, new CloseableRegistry());
		fail();
	} catch (Exception e) {
		assertEquals(expectedException, e);
	}
}
 
Example #2
Source File: RocksFullSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private SupplierWithException<CheckpointStreamWithResultProvider, Exception> createCheckpointStreamSupplier(
	long checkpointId,
	CheckpointStreamFactory primaryStreamFactory,
	CheckpointOptions checkpointOptions) {

	return localRecoveryConfig.isLocalRecoveryEnabled() &&
		(CheckpointType.SAVEPOINT != checkpointOptions.getCheckpointType()) ?

		() -> CheckpointStreamWithResultProvider.createDuplicatingStream(
			checkpointId,
			CheckpointedStateScope.EXCLUSIVE,
			primaryStreamFactory,
			localRecoveryConfig.getLocalStateDirectoryProvider()) :

		() -> CheckpointStreamWithResultProvider.createSimpleStream(
			CheckpointedStateScope.EXCLUSIVE,
			primaryStreamFactory);
}
 
Example #3
Source File: RocksDBStateUploaderTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Test that the exception arose in the thread pool will rethrow to the main thread.
 */
@Test
public void testMultiThreadUploadThreadPoolExceptionRethrow() throws IOException {
	SpecifiedException expectedException = new SpecifiedException("throw exception while multi thread upload states.");

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream = createFailingCheckpointStateOutputStream(expectedException);
	CheckpointStreamFactory checkpointStreamFactory = (CheckpointedStateScope scope) -> outputStream;

	File file = temporaryFolder.newFile(String.valueOf(UUID.randomUUID()));
	generateRandomFileContent(file.getPath(), 20);

	Map<StateHandleID, Path> filePaths = new HashMap<>(1);
	filePaths.put(new StateHandleID("mockHandleID"), new Path(file.getPath()));
	try (RocksDBStateUploader rocksDBStateUploader = new RocksDBStateUploader(5)) {
		rocksDBStateUploader.uploadFilesToCheckpointFs(filePaths, checkpointStreamFactory, new CloseableRegistry());
		fail();
	} catch (Exception e) {
		assertEquals(expectedException, e);
	}
}
 
Example #4
Source File: RocksFullSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
private SupplierWithException<CheckpointStreamWithResultProvider, Exception> createCheckpointStreamSupplier(
	long checkpointId,
	CheckpointStreamFactory primaryStreamFactory,
	CheckpointOptions checkpointOptions) {

	return localRecoveryConfig.isLocalRecoveryEnabled() && !checkpointOptions.getCheckpointType().isSavepoint() ?

		() -> CheckpointStreamWithResultProvider.createDuplicatingStream(
			checkpointId,
			CheckpointedStateScope.EXCLUSIVE,
			primaryStreamFactory,
			localRecoveryConfig.getLocalStateDirectoryProvider()) :

		() -> CheckpointStreamWithResultProvider.createSimpleStream(
			CheckpointedStateScope.EXCLUSIVE,
			primaryStreamFactory);
}
 
Example #5
Source File: RocksFullSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
private SupplierWithException<CheckpointStreamWithResultProvider, Exception> createCheckpointStreamSupplier(
	long checkpointId,
	CheckpointStreamFactory primaryStreamFactory,
	CheckpointOptions checkpointOptions) {

	return localRecoveryConfig.isLocalRecoveryEnabled() && !checkpointOptions.getCheckpointType().isSavepoint() ?

		() -> CheckpointStreamWithResultProvider.createDuplicatingStream(
			checkpointId,
			CheckpointedStateScope.EXCLUSIVE,
			primaryStreamFactory,
			localRecoveryConfig.getLocalStateDirectoryProvider()) :

		() -> CheckpointStreamWithResultProvider.createSimpleStream(
			CheckpointedStateScope.EXCLUSIVE,
			primaryStreamFactory);
}
 
Example #6
Source File: RocksDBStateUploaderTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test that the exception arose in the thread pool will rethrow to the main thread.
 */
@Test
public void testMultiThreadUploadThreadPoolExceptionRethrow() throws IOException {
	SpecifiedException expectedException = new SpecifiedException("throw exception while multi thread upload states.");

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream = createFailingCheckpointStateOutputStream(expectedException);
	CheckpointStreamFactory checkpointStreamFactory = (CheckpointedStateScope scope) -> outputStream;

	File file = temporaryFolder.newFile(String.valueOf(UUID.randomUUID()));
	generateRandomFileContent(file.getPath(), 20);

	Map<StateHandleID, Path> filePaths = new HashMap<>(1);
	filePaths.put(new StateHandleID("mockHandleID"), file.toPath());
	try (RocksDBStateUploader rocksDBStateUploader = new RocksDBStateUploader(5)) {
		rocksDBStateUploader.uploadFilesToCheckpointFs(filePaths, checkpointStreamFactory, new CloseableRegistry());
		fail();
	} catch (Exception e) {
		assertEquals(expectedException, e);
	}
}
 
Example #7
Source File: FsCheckpointStreamFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testExclusiveStateHasRelativePathHandles() throws IOException {
	final FsCheckpointStreamFactory factory = createFactory(FileSystem.getLocalFileSystem(), 0);

	final FsCheckpointStreamFactory.FsCheckpointStateOutputStream stream =
			factory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);
	stream.write(1657);
	final StreamStateHandle handle = stream.closeAndGetHandle();

	assertThat(handle, instanceOf(RelativeFileStateHandle.class));
	assertPathsEqual(exclusiveStateDir, ((RelativeFileStateHandle) handle).getFilePath().getParent());
}
 
Example #8
Source File: StateSnapshotContextSynchronousImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamClosingExceptionally() throws Exception {
	long checkpointId = 42L;
	long checkpointTimestamp = 1L;

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream1 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);
	CheckpointStreamFactory.CheckpointStateOutputStream outputStream2 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);

	CheckpointStreamFactory streamFactory = mock(CheckpointStreamFactory.class);
	when(streamFactory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE)).thenReturn(outputStream1, outputStream2);

	InsightCloseableRegistry closableRegistry = new InsightCloseableRegistry();

	KeyGroupRange keyGroupRange = new KeyGroupRange(0, 2);

	StateSnapshotContextSynchronousImpl context = new StateSnapshotContextSynchronousImpl(
		checkpointId,
		checkpointTimestamp,
		streamFactory,
		keyGroupRange,
		closableRegistry);

	// creating the output streams
	context.getRawKeyedOperatorStateOutput();
	context.getRawOperatorStateOutput();

	verify(streamFactory, times(2)).createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);

	assertEquals(2, closableRegistry.size());
	assertTrue(closableRegistry.contains(outputStream1));
	assertTrue(closableRegistry.contains(outputStream2));

	context.closeExceptionally();

	verify(outputStream1).close();
	verify(outputStream2).close();

	assertEquals(0, closableRegistry.size());
}
 
Example #9
Source File: OperatorStateWriter.java    From bravo with Apache License 2.0 5 votes vote down vote up
private StateObjectCollection<OperatorStateHandle> transformSubtaskOpState(Path outDir, Integer subtaskId,
		StateObjectCollection<OperatorStateHandle> baseState) {

	if (transformer == null) {
		return baseState;
	}

	StateObjectCollection<OperatorStateHandle> opHandle = baseState;
	try (OperatorStateBackend opBackend = OperatorStateReader
			.restoreOperatorStateBackend(opHandle)) {

		transformer.accept(subtaskId, opBackend);

		OperatorStateHandle newSnapshot = opBackend
				.snapshot(checkpointId, System.currentTimeMillis(), new CheckpointStreamFactory() {
					@Override
					public CheckpointStateOutputStream createCheckpointStateOutputStream(
							CheckpointedStateScope scope)
							throws IOException {
						return new FileBasedStateOutputStream(outDir.getFileSystem(),
								new Path(outDir, String.valueOf(UUID.randomUUID())));
					}
				}, null).get().getJobManagerOwnedSnapshot();
		return new StateObjectCollection<>(Lists.newArrayList(newSnapshot));
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #10
Source File: FsCheckpointStreamFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public FsCheckpointStateOutputStream createCheckpointStateOutputStream(CheckpointedStateScope scope) throws IOException {
	Path target = scope == CheckpointedStateScope.EXCLUSIVE ? checkpointDirectory : sharedStateDirectory;
	int bufferSize = Math.max(writeBufferSize, fileStateThreshold);

	final boolean absolutePath = entropyInjecting || scope == CheckpointedStateScope.SHARED;
	return new FsCheckpointStateOutputStream(target, filesystem, bufferSize, fileStateThreshold, !absolutePath);
}
 
Example #11
Source File: FsCheckpointStreamFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("ConstantConditions")
public void testWriteFlushesIfAboveThreshold() throws IOException {
	int fileSizeThreshold = 100;
	final FsCheckpointStreamFactory factory = createFactory(FileSystem.getLocalFileSystem(), fileSizeThreshold, fileSizeThreshold);
	final FsCheckpointStreamFactory.FsCheckpointStateOutputStream stream = factory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);
	stream.write(new byte[fileSizeThreshold]);
	File[] files = new File(exclusiveStateDir.toUri()).listFiles();
	assertEquals(1, files.length);
	File file = files[0];
	assertEquals(fileSizeThreshold, file.length());
	stream.write(new byte[fileSizeThreshold - 1]); // should buffer without flushing
	stream.write(127); // should buffer without flushing
	assertEquals(fileSizeThreshold, file.length());
}
 
Example #12
Source File: BlockerCheckpointStreamFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CheckpointStateOutputStream createCheckpointStateOutputStream(
	CheckpointedStateScope scope) throws IOException {

	BlockingCheckpointOutputStream blockingStream = new BlockingCheckpointOutputStream(
		new MemCheckpointStreamFactory.MemoryCheckpointOutputStream(maxSize),
		waiter,
		blocker,
		afterNumberInvocations);

	allCreatedStreams.add(blockingStream);

	return blockingStream;
}
 
Example #13
Source File: FsCheckpointStreamFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSharedStateHasAbsolutePathHandles() throws IOException {
	final FsCheckpointStreamFactory factory = createFactory(FileSystem.getLocalFileSystem(), 0);

	final FsCheckpointStreamFactory.FsCheckpointStateOutputStream stream =
		factory.createCheckpointStateOutputStream(CheckpointedStateScope.SHARED);
	stream.write(0);
	final StreamStateHandle handle = stream.closeAndGetHandle();

	assertThat(handle, instanceOf(FileStateHandle.class));
	assertThat(handle, not(instanceOf(RelativeFileStateHandle.class)));
	assertPathsEqual(sharedStateDir, ((FileStateHandle) handle).getFilePath().getParent());
}
 
Example #14
Source File: FsCheckpointStreamFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntropyMakesExclusiveStateAbsolutePaths() throws IOException{
	final FsCheckpointStreamFactory factory = createFactory(new FsStateBackendEntropyTest.TestEntropyAwareFs(), 0);

	final FsCheckpointStreamFactory.FsCheckpointStateOutputStream stream =
		factory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);
	stream.write(0);
	final StreamStateHandle handle = stream.closeAndGetHandle();

	assertThat(handle, instanceOf(FileStateHandle.class));
	assertThat(handle, not(instanceOf(RelativeFileStateHandle.class)));
	assertPathsEqual(exclusiveStateDir, ((FileStateHandle) handle).getFilePath().getParent());
}
 
Example #15
Source File: FsCheckpointStreamFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void flushAndVerify(int minFileSize, int bytesToFlush, boolean expectEmpty) throws IOException {
	FsCheckpointStreamFactory.FsCheckpointStateOutputStream stream =
			createFactory(new FsStateBackendEntropyTest.TestEntropyAwareFs(), minFileSize)
					.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);

	stream.write(new byte[bytesToFlush], 0, bytesToFlush);
	stream.flush();
	assertEquals(expectEmpty ? 0 : 1, new File(exclusiveStateDir.toUri()).listFiles().length);
}
 
Example #16
Source File: BlockerCheckpointStreamFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CheckpointStateOutputStream createCheckpointStateOutputStream(
	CheckpointedStateScope scope) throws IOException {

	BlockingCheckpointOutputStream blockingStream = new BlockingCheckpointOutputStream(
		new MemCheckpointStreamFactory.MemoryCheckpointOutputStream(maxSize),
		waiter,
		blocker,
		afterNumberInvocations);

	allCreatedStreams.add(blockingStream);

	return blockingStream;
}
 
Example #17
Source File: StateSnapshotContextSynchronousImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamClosingExceptionally() throws Exception {
	long checkpointId = 42L;
	long checkpointTimestamp = 1L;

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream1 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);
	CheckpointStreamFactory.CheckpointStateOutputStream outputStream2 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);

	CheckpointStreamFactory streamFactory = mock(CheckpointStreamFactory.class);
	when(streamFactory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE)).thenReturn(outputStream1, outputStream2);

	InsightCloseableRegistry closableRegistry = new InsightCloseableRegistry();

	KeyGroupRange keyGroupRange = new KeyGroupRange(0, 2);

	StateSnapshotContextSynchronousImpl context = new StateSnapshotContextSynchronousImpl(
		checkpointId,
		checkpointTimestamp,
		streamFactory,
		keyGroupRange,
		closableRegistry);

	// creating the output streams
	context.getRawKeyedOperatorStateOutput();
	context.getRawOperatorStateOutput();

	verify(streamFactory, times(2)).createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);

	assertEquals(2, closableRegistry.size());
	assertTrue(closableRegistry.contains(outputStream1));
	assertTrue(closableRegistry.contains(outputStream2));

	context.closeExceptionally();

	verify(outputStream1).close();
	verify(outputStream2).close();

	assertEquals(0, closableRegistry.size());
}
 
Example #18
Source File: FsCheckpointStreamFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public FsCheckpointStateOutputStream createCheckpointStateOutputStream(CheckpointedStateScope scope) throws IOException {
	Path target = scope == CheckpointedStateScope.EXCLUSIVE ? checkpointDirectory : sharedStateDirectory;
	int bufferSize = Math.max(writeBufferSize, fileStateThreshold);

	return new FsCheckpointStateOutputStream(target, filesystem, bufferSize, fileStateThreshold);
}
 
Example #19
Source File: FsCheckpointStreamFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public FsCheckpointStateOutputStream createCheckpointStateOutputStream(CheckpointedStateScope scope) throws IOException {
	Path target = scope == CheckpointedStateScope.EXCLUSIVE ? checkpointDirectory : sharedStateDirectory;
	int bufferSize = Math.max(DEFAULT_WRITE_BUFFER_SIZE, fileStateThreshold);

	return new FsCheckpointStateOutputStream(target, filesystem, bufferSize, fileStateThreshold);
}
 
Example #20
Source File: StateSnapshotContextSynchronousImplTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that closing the StateSnapshotContextSynchronousImpl will also close the associated
 * output streams.
 */
@Test
public void testStreamClosingWhenClosing() throws Exception {
	long checkpointId = 42L;
	long checkpointTimestamp = 1L;

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream1 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);
	CheckpointStreamFactory.CheckpointStateOutputStream outputStream2 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);

	CheckpointStreamFactory streamFactory = mock(CheckpointStreamFactory.class);
	when(streamFactory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE)).thenReturn(outputStream1, outputStream2);

	InsightCloseableRegistry closableRegistry = new InsightCloseableRegistry();

	KeyGroupRange keyGroupRange = new KeyGroupRange(0, 2);

	StateSnapshotContextSynchronousImpl context = new StateSnapshotContextSynchronousImpl(
		checkpointId,
		checkpointTimestamp,
		streamFactory,
		keyGroupRange,
		closableRegistry);

	// creating the output streams
	context.getRawKeyedOperatorStateOutput();
	context.getRawOperatorStateOutput();

	verify(streamFactory, times(2)).createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);

	assertEquals(2, closableRegistry.size());
	assertTrue(closableRegistry.contains(outputStream1));
	assertTrue(closableRegistry.contains(outputStream2));

	context.close();

	verify(outputStream1).close();
	verify(outputStream2).close();

	assertEquals(0, closableRegistry.size());
}
 
Example #21
Source File: BlockerCheckpointStreamFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public CheckpointStateOutputStream createCheckpointStateOutputStream(
	CheckpointedStateScope scope) throws IOException {

	BlockingCheckpointOutputStream blockingStream = new BlockingCheckpointOutputStream(
		new MemCheckpointStreamFactory.MemoryCheckpointOutputStream(maxSize),
		waiter,
		blocker,
		afterNumberInvocations);

	allCreatedStreams.add(blockingStream);

	return blockingStream;
}
 
Example #22
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Nonnull
private SnapshotResult<StreamStateHandle> materializeMetaData() throws Exception {

	CheckpointStreamWithResultProvider streamWithResultProvider =

		localRecoveryConfig.isLocalRecoveryEnabled() ?

			CheckpointStreamWithResultProvider.createDuplicatingStream(
				checkpointId,
				CheckpointedStateScope.EXCLUSIVE,
				checkpointStreamFactory,
				localRecoveryConfig.getLocalStateDirectoryProvider()) :

			CheckpointStreamWithResultProvider.createSimpleStream(
				CheckpointedStateScope.EXCLUSIVE,
				checkpointStreamFactory);

	snapshotCloseableRegistry.registerCloseable(streamWithResultProvider);

	try {
		//no need for compression scheme support because sst-files are already compressed
		KeyedBackendSerializationProxy<K> serializationProxy =
			new KeyedBackendSerializationProxy<>(
				keySerializer,
				stateMetaInfoSnapshots,
				false);

		DataOutputView out =
			new DataOutputViewStreamWrapper(streamWithResultProvider.getCheckpointOutputStream());

		serializationProxy.write(out);

		if (snapshotCloseableRegistry.unregisterCloseable(streamWithResultProvider)) {
			SnapshotResult<StreamStateHandle> result =
				streamWithResultProvider.closeAndFinalizeCheckpointStreamResult();
			streamWithResultProvider = null;
			return result;
		} else {
			throw new IOException("Stream already closed and cannot return a handle.");
		}
	} finally {
		if (streamWithResultProvider != null) {
			if (snapshotCloseableRegistry.unregisterCloseable(streamWithResultProvider)) {
				IOUtils.closeQuietly(streamWithResultProvider);
			}
		}
	}
}
 
Example #23
Source File: StateSnapshotContextSynchronousImplTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that closing the StateSnapshotContextSynchronousImpl will also close the associated
 * output streams.
 */
@Test
public void testStreamClosingWhenClosing() throws Exception {
	long checkpointId = 42L;
	long checkpointTimestamp = 1L;

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream1 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);
	CheckpointStreamFactory.CheckpointStateOutputStream outputStream2 = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);

	CheckpointStreamFactory streamFactory = mock(CheckpointStreamFactory.class);
	when(streamFactory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE)).thenReturn(outputStream1, outputStream2);

	InsightCloseableRegistry closableRegistry = new InsightCloseableRegistry();

	KeyGroupRange keyGroupRange = new KeyGroupRange(0, 2);

	StateSnapshotContextSynchronousImpl context = new StateSnapshotContextSynchronousImpl(
		checkpointId,
		checkpointTimestamp,
		streamFactory,
		keyGroupRange,
		closableRegistry);

	// creating the output streams
	context.getRawKeyedOperatorStateOutput();
	context.getRawOperatorStateOutput();

	verify(streamFactory, times(2)).createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);

	assertEquals(2, closableRegistry.size());
	assertTrue(closableRegistry.contains(outputStream1));
	assertTrue(closableRegistry.contains(outputStream2));

	context.getKeyedStateStreamFuture().run();
	context.getOperatorStateStreamFuture().run();

	verify(outputStream1).closeAndGetHandle();
	verify(outputStream2).closeAndGetHandle();

	assertEquals(0, closableRegistry.size());
}
 
Example #24
Source File: RocksDBAsyncSnapshotTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream get() throws IOException {
	return factory.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);
}
 
Example #25
Source File: BackendForTestStream.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream createCheckpointStateOutputStream(CheckpointedStateScope scope) throws IOException {
	return streamFactory.get();
}
 
Example #26
Source File: TestCheckpointStreamFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream createCheckpointStateOutputStream(CheckpointedStateScope scope) {
	return supplier.get();
}
 
Example #27
Source File: FsCheckpointStorageTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testDirectoriesForExclusiveAndSharedState() throws Exception {
	final FileSystem fs = LocalFileSystem.getSharedInstance();
	final Path checkpointDir = randomTempPath();
	final Path sharedStateDir = randomTempPath();

	FsCheckpointStorageLocation storageLocation = new FsCheckpointStorageLocation(
			fs,
			checkpointDir,
			sharedStateDir,
			randomTempPath(),
			CheckpointStorageLocationReference.getDefault(),
			FILE_SIZE_THRESHOLD,
			WRITE_BUFFER_SIZE);

	assertNotEquals(storageLocation.getCheckpointDirectory(), storageLocation.getSharedStateDirectory());

	assertEquals(0, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
	assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length);

	// create exclusive state

	FsCheckpointStateOutputStream exclusiveStream =
			storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);

	exclusiveStream.write(42);
	exclusiveStream.flushToFile();
	StreamStateHandle exclusiveHandle = exclusiveStream.closeAndGetHandle();

	assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
	assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length);

	// create shared state

	FsCheckpointStateOutputStream sharedStream =
			storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.SHARED);

	sharedStream.write(42);
	sharedStream.flushToFile();
	StreamStateHandle sharedHandle = sharedStream.closeAndGetHandle();

	assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
	assertEquals(1, fs.listStatus(storageLocation.getSharedStateDirectory()).length);

	// drop state

	exclusiveHandle.discardState();
	sharedHandle.discardState();
}
 
Example #28
Source File: MemCheckpointStreamFactory.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream createCheckpointStateOutputStream(
		CheckpointedStateScope scope) throws IOException
{
	return new MemoryCheckpointOutputStream(maxStateSize);
}
 
Example #29
Source File: FsCheckpointStorageTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testDirectoriesForExclusiveAndSharedState() throws Exception {
	final FileSystem fs = LocalFileSystem.getSharedInstance();
	final Path checkpointDir = randomTempPath();
	final Path sharedStateDir = randomTempPath();

	FsCheckpointStorageLocation storageLocation = new FsCheckpointStorageLocation(
			fs,
			checkpointDir,
			sharedStateDir,
			randomTempPath(),
			CheckpointStorageLocationReference.getDefault(),
			FILE_SIZE_THRESHOLD);

	assertNotEquals(storageLocation.getCheckpointDirectory(), storageLocation.getSharedStateDirectory());

	assertEquals(0, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
	assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length);

	// create exclusive state

	CheckpointStateOutputStream exclusiveStream =
			storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);

	exclusiveStream.write(42);
	exclusiveStream.flush();
	StreamStateHandle exclusiveHandle = exclusiveStream.closeAndGetHandle();

	assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
	assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length);

	// create shared state

	CheckpointStateOutputStream sharedStream =
			storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.SHARED);

	sharedStream.write(42);
	sharedStream.flush();
	StreamStateHandle sharedHandle = sharedStream.closeAndGetHandle();

	assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
	assertEquals(1, fs.listStatus(storageLocation.getSharedStateDirectory()).length);

	// drop state

	exclusiveHandle.discardState();
	sharedHandle.discardState();
}
 
Example #30
Source File: TestCheckpointStreamFactory.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream createCheckpointStateOutputStream(CheckpointedStateScope scope) {
	return supplier.get();
}