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

The following examples show how to use org.apache.flink.runtime.state.CheckpointStorageLocation. 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: PendingCheckpoint.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public PendingCheckpoint(
		JobID jobId,
		long checkpointId,
		long checkpointTimestamp,
		Map<ExecutionAttemptID, ExecutionVertex> verticesToConfirm,
		CheckpointProperties props,
		CheckpointStorageLocation targetLocation,
		Executor executor) {

	checkArgument(verticesToConfirm.size() > 0,
			"Checkpoint needs at least one vertex that commits the checkpoint");

	this.jobId = checkNotNull(jobId);
	this.checkpointId = checkpointId;
	this.checkpointTimestamp = checkpointTimestamp;
	this.notYetAcknowledgedTasks = checkNotNull(verticesToConfirm);
	this.props = checkNotNull(props);
	this.targetLocation = checkNotNull(targetLocation);
	this.executor = Preconditions.checkNotNull(executor);

	this.operatorStates = new HashMap<>();
	this.masterState = new ArrayList<>();
	this.acknowledgedTasks = new HashSet<>(verticesToConfirm.size());
	this.onCompletionPromise = new CompletableFuture<>();
}
 
Example #2
Source File: CheckpointCoordinator.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Snapshot task state.
 *
 * @param timestamp the timestamp of this checkpoint reques
 * @param checkpointID the checkpoint id
 * @param checkpointStorageLocation the checkpoint location
 * @param props the checkpoint properties
 * @param executions the executions which should be triggered
 * @param advanceToEndOfTime Flag indicating if the source should inject a {@code MAX_WATERMARK}
 *                               in the pipeline to fire any registered event-time timers.
 */
private void snapshotTaskState(
	long timestamp,
	long checkpointID,
	CheckpointStorageLocation checkpointStorageLocation,
	CheckpointProperties props,
	Execution[] executions,
	boolean advanceToEndOfTime) {

	final CheckpointOptions checkpointOptions = new CheckpointOptions(
		props.getCheckpointType(),
		checkpointStorageLocation.getLocationReference(),
		isExactlyOnceMode,
		props.getCheckpointType() == CheckpointType.CHECKPOINT && unalignedCheckpointsEnabled);

	// send the messages to the tasks that trigger their checkpoint
	for (Execution execution: executions) {
		if (props.isSynchronous()) {
			execution.triggerSynchronousSavepoint(checkpointID, timestamp, checkpointOptions, advanceToEndOfTime);
		} else {
			execution.triggerCheckpoint(checkpointID, timestamp, checkpointOptions);
		}
	}
}
 
Example #3
Source File: CheckpointCoordinator.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the checkpoint trigger asynchronously. It will be executed in io thread due to
 * it might be time-consuming.
 *
 * @param props checkpoint properties
 * @param externalSavepointLocation the external savepoint location, it might be null
 * @return the future of initialized result, checkpoint id and checkpoint location
 */
private CompletableFuture<CheckpointIdAndStorageLocation> initializeCheckpoint(
	CheckpointProperties props,
	@Nullable String externalSavepointLocation) {

	return CompletableFuture.supplyAsync(() -> {
		try {
			// this must happen outside the coordinator-wide lock, because it communicates
			// with external services (in HA mode) and may block for a while.
			long checkpointID = checkpointIdCounter.getAndIncrement();

			CheckpointStorageLocation checkpointStorageLocation = props.isSavepoint() ?
				checkpointStorage
					.initializeLocationForSavepoint(checkpointID, externalSavepointLocation) :
				checkpointStorage.initializeLocationForCheckpoint(checkpointID);

			return new CheckpointIdAndStorageLocation(checkpointID, checkpointStorageLocation);
		} catch (Throwable throwable) {
			throw new CompletionException(throwable);
		}
	}, executor);
}
 
Example #4
Source File: SylphFsCheckpointStorage.java    From sylph with Apache License 2.0 6 votes vote down vote up
@Override
public CheckpointStorageLocation initializeLocationForCheckpoint(long checkpointId)
        throws IOException
{
    checkArgument(checkpointId >= 0);

    // prepare all the paths needed for the checkpoints
    final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

    // create the checkpoint exclusive directory
    fileSystem.mkdirs(checkpointDir);

    return new FsCheckpointStorageLocation(
            fileSystem,
            checkpointDir,
            sharedStateDirectory,
            taskOwnedStateDirectory,
            CheckpointStorageLocationReference.getDefault(),
            fileSizeThreshold,
            writeBufferSize);
}
 
Example #5
Source File: FsCheckpointStorage.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public CheckpointStorageLocation initializeLocationForCheckpoint(long checkpointId) throws IOException {
	checkArgument(checkpointId >= 0, "Illegal negative checkpoint id: %d.", checkpointId);
	checkArgument(baseLocationsInitialized, "The base checkpoint location has not been initialized.");

	// prepare all the paths needed for the checkpoints
	final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

	// create the checkpoint exclusive directory
	fileSystem.mkdirs(checkpointDir);

	return new FsCheckpointStorageLocation(
			fileSystem,
			checkpointDir,
			sharedStateDirectory,
			taskOwnedStateDirectory,
			CheckpointStorageLocationReference.getDefault(),
			fileSizeThreshold,
			writeBufferSize);
}
 
Example #6
Source File: MemoryCheckpointStorageTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonPersistentCheckpointLocation() throws Exception {
	MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			new JobID(), null, null, DEFAULT_MAX_STATE_SIZE);

	CheckpointStorageLocation location = storage.initializeLocationForCheckpoint(9);

	CheckpointMetadataOutputStream stream = location.createMetadataOutputStream();
	stream.write(99);

	CompletedCheckpointStorageLocation completed = stream.closeAndFinalizeCheckpoint();
	StreamStateHandle handle = completed.getMetadataHandle();
	assertTrue(handle instanceof ByteStreamStateHandle);

	// the reference is not valid in that case
	try {
		storage.resolveCheckpoint(completed.getExternalPointer());
		fail("should fail with an exception");
	} catch (Exception e) {
		// expected
	}
}
 
Example #7
Source File: AbstractFileCheckpointStorageTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void writeToAlreadyExistingCheckpointFails() throws Exception {
	final byte[] data = {8, 8, 4, 5, 2, 6, 3};
	final long checkpointId = 177;

	final CheckpointStorage storage = createCheckpointStorage(randomTempPath());
	final CheckpointStorageLocation loc = storage.initializeLocationForCheckpoint(checkpointId);

	// write to the metadata file for the checkpoint

	try (CheckpointMetadataOutputStream out = loc.createMetadataOutputStream()) {
		out.write(data);
		out.closeAndFinalizeCheckpoint();
	}

	// create another writer to the metadata file for the checkpoint
	try {
		loc.createMetadataOutputStream();
		fail("this should fail with an exception");
	}
	catch (IOException ignored) {}
}
 
Example #8
Source File: DispatcherTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private URI createTestingSavepoint() throws IOException, URISyntaxException {
	final StateBackend stateBackend = Checkpoints.loadStateBackend(configuration, Thread.currentThread().getContextClassLoader(), log);
	final CheckpointStorageCoordinatorView checkpointStorage = stateBackend.createCheckpointStorage(jobGraph.getJobID());
	final File savepointFile = temporaryFolder.newFolder();
	final long checkpointId = 1L;

	final CheckpointStorageLocation checkpointStorageLocation = checkpointStorage.initializeLocationForSavepoint(checkpointId, savepointFile.getAbsolutePath());

	final CheckpointMetadataOutputStream metadataOutputStream = checkpointStorageLocation.createMetadataOutputStream();
	Checkpoints.storeCheckpointMetadata(new SavepointV2(checkpointId, Collections.emptyList(), Collections.emptyList()), metadataOutputStream);

	final CompletedCheckpointStorageLocation completedCheckpointStorageLocation = metadataOutputStream.closeAndFinalizeCheckpoint();

	return new URI(completedCheckpointStorageLocation.getExternalPointer());

}
 
Example #9
Source File: MemoryBackendCheckpointStorage.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public CheckpointStorageLocation initializeLocationForCheckpoint(long checkpointId) throws IOException {
	checkArgument(checkpointId >= 0);

	if (checkpointsDirectory != null) {
		// configured for durable metadata
		// prepare all the paths needed for the checkpoints
		checkState(fileSystem != null);

		final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

		// create the checkpoint exclusive directory
		fileSystem.mkdirs(checkpointDir);

		return new PersistentMetadataCheckpointStorageLocation(fileSystem, checkpointDir, maxStateSize);
	}
	else {
		// no durable metadata - typical in IDE or test setup case
		return new NonPersistentMetadataCheckpointStorageLocation(maxStateSize);
	}
}
 
Example #10
Source File: MemoryBackendCheckpointStorage.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public CheckpointStorageLocation initializeLocationForCheckpoint(long checkpointId) throws IOException {
	checkArgument(checkpointId >= 0);

	if (checkpointsDirectory != null) {
		// configured for durable metadata
		// prepare all the paths needed for the checkpoints
		checkState(fileSystem != null);

		final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

		// create the checkpoint exclusive directory
		fileSystem.mkdirs(checkpointDir);

		return new PersistentMetadataCheckpointStorageLocation(fileSystem, checkpointDir, maxStateSize);
	}
	else {
		// no durable metadata - typical in IDE or test setup case
		return new NonPersistentMetadataCheckpointStorageLocation(maxStateSize);
	}
}
 
Example #11
Source File: FsCheckpointStorage.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public CheckpointStorageLocation initializeLocationForCheckpoint(long checkpointId) throws IOException {
	checkArgument(checkpointId >= 0);

	// prepare all the paths needed for the checkpoints
	final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

	// create the checkpoint exclusive directory
	fileSystem.mkdirs(checkpointDir);

	return new FsCheckpointStorageLocation(
			fileSystem,
			checkpointDir,
			sharedStateDirectory,
			taskOwnedStateDirectory,
			CheckpointStorageLocationReference.getDefault(),
			fileSizeThreshold,
			writeBufferSize);
}
 
Example #12
Source File: DispatcherTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private URI createTestingSavepoint() throws IOException, URISyntaxException {
	final StateBackend stateBackend = Checkpoints.loadStateBackend(configuration, Thread.currentThread().getContextClassLoader(), log);
	final CheckpointStorageCoordinatorView checkpointStorage = stateBackend.createCheckpointStorage(jobGraph.getJobID());
	final File savepointFile = temporaryFolder.newFolder();
	final long checkpointId = 1L;

	final CheckpointStorageLocation checkpointStorageLocation = checkpointStorage.initializeLocationForSavepoint(checkpointId, savepointFile.getAbsolutePath());

	final CheckpointMetadataOutputStream metadataOutputStream = checkpointStorageLocation.createMetadataOutputStream();
	Checkpoints.storeCheckpointMetadata(new CheckpointMetadata(checkpointId, Collections.emptyList(), Collections.emptyList()), metadataOutputStream);

	final CompletedCheckpointStorageLocation completedCheckpointStorageLocation = metadataOutputStream.closeAndFinalizeCheckpoint();

	return new URI(completedCheckpointStorageLocation.getExternalPointer());

}
 
Example #13
Source File: PendingCheckpoint.java    From flink with Apache License 2.0 6 votes vote down vote up
public PendingCheckpoint(
		JobID jobId,
		long checkpointId,
		long checkpointTimestamp,
		Map<ExecutionAttemptID, ExecutionVertex> verticesToConfirm,
		CheckpointProperties props,
		CheckpointStorageLocation targetLocation,
		Executor executor) {

	checkArgument(verticesToConfirm.size() > 0,
			"Checkpoint needs at least one vertex that commits the checkpoint");

	this.jobId = checkNotNull(jobId);
	this.checkpointId = checkpointId;
	this.checkpointTimestamp = checkpointTimestamp;
	this.notYetAcknowledgedTasks = checkNotNull(verticesToConfirm);
	this.props = checkNotNull(props);
	this.targetLocation = checkNotNull(targetLocation);
	this.executor = Preconditions.checkNotNull(executor);

	this.operatorStates = new HashMap<>();
	this.masterState = new ArrayList<>();
	this.acknowledgedTasks = new HashSet<>(verticesToConfirm.size());
	this.onCompletionPromise = new CompletableFuture<>();
}
 
Example #14
Source File: AbstractFileCheckpointStorageTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void writeToAlreadyExistingCheckpointFails() throws Exception {
	final byte[] data = {8, 8, 4, 5, 2, 6, 3};
	final long checkpointId = 177;

	final CheckpointStorage storage = createCheckpointStorage(randomTempPath());
	storage.initializeBaseLocations();
	final CheckpointStorageLocation loc = storage.initializeLocationForCheckpoint(checkpointId);

	// write to the metadata file for the checkpoint

	try (CheckpointMetadataOutputStream out = loc.createMetadataOutputStream()) {
		out.write(data);
		out.closeAndFinalizeCheckpoint();
	}

	// create another writer to the metadata file for the checkpoint
	try {
		loc.createMetadataOutputStream();
		fail("this should fail with an exception");
	}
	catch (IOException ignored) {}
}
 
Example #15
Source File: MemoryCheckpointStorageTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonPersistentCheckpointLocation() throws Exception {
	MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			new JobID(), null, null, DEFAULT_MAX_STATE_SIZE);

	CheckpointStorageLocation location = storage.initializeLocationForCheckpoint(9);

	CheckpointMetadataOutputStream stream = location.createMetadataOutputStream();
	stream.write(99);

	CompletedCheckpointStorageLocation completed = stream.closeAndFinalizeCheckpoint();
	StreamStateHandle handle = completed.getMetadataHandle();
	assertTrue(handle instanceof ByteStreamStateHandle);

	// the reference is not valid in that case
	try {
		storage.resolveCheckpoint(completed.getExternalPointer());
		fail("should fail with an exception");
	} catch (Exception e) {
		// expected
	}
}
 
Example #16
Source File: FsCheckpointStorage.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public CheckpointStorageLocation initializeLocationForCheckpoint(long checkpointId) throws IOException {
	checkArgument(checkpointId >= 0);

	// prepare all the paths needed for the checkpoints
	final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

	// create the checkpoint exclusive directory
	fileSystem.mkdirs(checkpointDir);

	return new FsCheckpointStorageLocation(
			fileSystem,
			checkpointDir,
			sharedStateDirectory,
			taskOwnedStateDirectory,
			CheckpointStorageLocationReference.getDefault(),
			fileSizeThreshold);
}
 
Example #17
Source File: AbstractFileCheckpointStorageTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void writeToAlreadyExistingCheckpointFails() throws Exception {
	final byte[] data = {8, 8, 4, 5, 2, 6, 3};
	final long checkpointId = 177;

	final CheckpointStorage storage = createCheckpointStorage(randomTempPath());
	final CheckpointStorageLocation loc = storage.initializeLocationForCheckpoint(checkpointId);

	// write to the metadata file for the checkpoint

	try (CheckpointMetadataOutputStream out = loc.createMetadataOutputStream()) {
		out.write(data);
		out.closeAndFinalizeCheckpoint();
	}

	// create another writer to the metadata file for the checkpoint
	try {
		loc.createMetadataOutputStream();
		fail("this should fail with an exception");
	}
	catch (IOException ignored) {}
}
 
Example #18
Source File: MemoryBackendCheckpointStorage.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public CheckpointStorageLocation initializeLocationForCheckpoint(long checkpointId) throws IOException {
	checkArgument(checkpointId >= 0);

	if (checkpointsDirectory != null) {
		// configured for durable metadata
		// prepare all the paths needed for the checkpoints
		checkState(fileSystem != null);

		final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

		// create the checkpoint exclusive directory
		fileSystem.mkdirs(checkpointDir);

		return new PersistentMetadataCheckpointStorageLocation(fileSystem, checkpointDir, maxStateSize);
	}
	else {
		// no durable metadata - typical in IDE or test setup case
		return new NonPersistentMetadataCheckpointStorageLocation(maxStateSize);
	}
}
 
Example #19
Source File: DispatcherTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
private URI createTestingSavepoint() throws IOException, URISyntaxException {
	final StateBackend stateBackend = Checkpoints.loadStateBackend(configuration, Thread.currentThread().getContextClassLoader(), log);
	final CheckpointStorage checkpointStorage = stateBackend.createCheckpointStorage(jobGraph.getJobID());
	final File savepointFile = temporaryFolder.newFolder();
	final long checkpointId = 1L;

	final CheckpointStorageLocation checkpointStorageLocation = checkpointStorage.initializeLocationForSavepoint(checkpointId, savepointFile.getAbsolutePath());

	final CheckpointMetadataOutputStream metadataOutputStream = checkpointStorageLocation.createMetadataOutputStream();
	Checkpoints.storeCheckpointMetadata(new SavepointV2(checkpointId, Collections.emptyList(), Collections.emptyList()), metadataOutputStream);

	final CompletedCheckpointStorageLocation completedCheckpointStorageLocation = metadataOutputStream.closeAndFinalizeCheckpoint();

	return new URI(completedCheckpointStorageLocation.getExternalPointer());

}
 
Example #20
Source File: MemoryCheckpointStorageTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonPersistentCheckpointLocation() throws Exception {
	MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			new JobID(), null, null, DEFAULT_MAX_STATE_SIZE);

	CheckpointStorageLocation location = storage.initializeLocationForCheckpoint(9);

	CheckpointMetadataOutputStream stream = location.createMetadataOutputStream();
	stream.write(99);

	CompletedCheckpointStorageLocation completed = stream.closeAndFinalizeCheckpoint();
	StreamStateHandle handle = completed.getMetadataHandle();
	assertTrue(handle instanceof ByteStreamStateHandle);

	// the reference is not valid in that case
	try {
		storage.resolveCheckpoint(completed.getExternalPointer());
		fail("should fail with an exception");
	} catch (Exception e) {
		// expected
	}
}
 
Example #21
Source File: AbstractFileCheckpointStorageTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testSavepoint(
		@Nullable Path savepointDir,
		@Nullable Path customDir,
		Path expectedParent) throws Exception {

	final CheckpointStorage storage = savepointDir == null ?
			createCheckpointStorage(randomTempPath()) :
			createCheckpointStorageWithSavepointDir(randomTempPath(), savepointDir);

	final String customLocation = customDir == null ? null : customDir.toString();

	final CheckpointStorageLocation savepointLocation =
			storage.initializeLocationForSavepoint(52452L, customLocation);

	final byte[] data = {77, 66, 55, 99, 88};

	final CompletedCheckpointStorageLocation completed;
	try (CheckpointMetadataOutputStream out = savepointLocation.createMetadataOutputStream()) {
		out.write(data);
		completed = out.closeAndFinalizeCheckpoint();
	}

	// we need to do this step to make sure we have a slash (or not) in the same way as the
	// expected path has it
	final Path normalizedWithSlash = Path.fromLocalFile(new File(new Path(completed.getExternalPointer()).getParent().getPath()));

	assertEquals(expectedParent, normalizedWithSlash);
	validateContents(completed.getMetadataHandle(), data);

	// validate that the correct directory was used
	FileStateHandle fileStateHandle = (FileStateHandle) completed.getMetadataHandle();

	// we need to recreate that path in the same way as the "expected path" (via File and URI) to make
	// sure the either both use '/' suffixes, or neither uses them (a bit of an annoying ambiguity)
	Path usedSavepointDir = new Path(new File(fileStateHandle.getFilePath().getParent().getParent().getPath()).toURI());

	assertEquals(expectedParent, usedSavepointDir);
}
 
Example #22
Source File: CheckpointCoordinator.java    From flink with Apache License 2.0 5 votes vote down vote up
CheckpointIdAndStorageLocation(
	long checkpointId,
	CheckpointStorageLocation checkpointStorageLocation) {

	this.checkpointId = checkpointId;
	this.checkpointStorageLocation = checkNotNull(checkpointStorageLocation);
}
 
Example #23
Source File: PendingCheckpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
public PendingCheckpoint(
		JobID jobId,
		long checkpointId,
		long checkpointTimestamp,
		Map<ExecutionAttemptID, ExecutionVertex> verticesToConfirm,
		Collection<OperatorID> operatorCoordinatorsToConfirm,
		Collection<String> masterStateIdentifiers,
		CheckpointProperties props,
		CheckpointStorageLocation targetLocation,
		Executor executor,
		CompletableFuture<CompletedCheckpoint> onCompletionPromise) {

	checkArgument(verticesToConfirm.size() > 0,
			"Checkpoint needs at least one vertex that commits the checkpoint");

	this.jobId = checkNotNull(jobId);
	this.checkpointId = checkpointId;
	this.checkpointTimestamp = checkpointTimestamp;
	this.notYetAcknowledgedTasks = checkNotNull(verticesToConfirm);
	this.props = checkNotNull(props);
	this.targetLocation = checkNotNull(targetLocation);
	this.executor = Preconditions.checkNotNull(executor);

	this.operatorStates = new HashMap<>();
	this.masterStates = new ArrayList<>(masterStateIdentifiers.size());
	this.notYetAcknowledgedMasterStates = masterStateIdentifiers.isEmpty()
			? Collections.emptySet() : new HashSet<>(masterStateIdentifiers);
	this.notYetAcknowledgedOperatorCoordinators = operatorCoordinatorsToConfirm.isEmpty()
			? Collections.emptySet() : new HashSet<>(operatorCoordinatorsToConfirm);
	this.acknowledgedTasks = new HashSet<>(verticesToConfirm.size());
	this.onCompletionPromise = checkNotNull(onCompletionPromise);
}
 
Example #24
Source File: SavepointOutputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
private static CheckpointStorageLocation createSavepointLocation(Path location) throws IOException {
	final CheckpointStorageLocationReference reference = AbstractFsCheckpointStorage.encodePathAsReference(location);
	return new FsCheckpointStorageLocation(
		location.getFileSystem(),
		location,
		location,
		location,
		reference,
		(int) CheckpointingOptions.FS_SMALL_FILE_THRESHOLD.defaultValue().getBytes(),
		CheckpointingOptions.FS_WRITE_BUFFER_SIZE.defaultValue());
}
 
Example #25
Source File: SylphFsCheckpointStorage.java    From sylph with Apache License 2.0 5 votes vote down vote up
@Override
protected CheckpointStorageLocation createSavepointLocation(FileSystem fs, Path location)
        throws IOException
{
    final CheckpointStorageLocationReference reference = encodePathAsReference(location);
    return new FsCheckpointStorageLocation(fs, location, location, location, reference, fileSizeThreshold, writeBufferSize);
}
 
Example #26
Source File: AbstractFileCheckpointStorageTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testSavepoint(
		@Nullable Path savepointDir,
		@Nullable Path customDir,
		Path expectedParent) throws Exception {

	final CheckpointStorage storage = savepointDir == null ?
			createCheckpointStorage(randomTempPath()) :
			createCheckpointStorageWithSavepointDir(randomTempPath(), savepointDir);

	final String customLocation = customDir == null ? null : customDir.toString();

	final CheckpointStorageLocation savepointLocation =
			storage.initializeLocationForSavepoint(52452L, customLocation);

	final byte[] data = {77, 66, 55, 99, 88};

	final CompletedCheckpointStorageLocation completed;
	try (CheckpointMetadataOutputStream out = savepointLocation.createMetadataOutputStream()) {
		out.write(data);
		completed = out.closeAndFinalizeCheckpoint();
	}

	// we need to do this step to make sure we have a slash (or not) in the same way as the
	// expected path has it
	final Path normalizedWithSlash = Path.fromLocalFile(new File(new Path(completed.getExternalPointer()).getParent().getPath()));

	assertEquals(expectedParent, normalizedWithSlash);
	validateContents(completed.getMetadataHandle(), data);

	// validate that the correct directory was used
	FileStateHandle fileStateHandle = (FileStateHandle) completed.getMetadataHandle();

	// we need to recreate that path in the same way as the "expected path" (via File and URI) to make
	// sure the either both use '/' suffixes, or neither uses them (a bit of an annoying ambiguity)
	Path usedSavepointDir = new Path(new File(fileStateHandle.getFilePath().getParent().getParent().getPath()).toURI());

	assertEquals(expectedParent, usedSavepointDir);
}
 
Example #27
Source File: AbstractFileCheckpointStorageTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void testSavepoint(
		@Nullable Path savepointDir,
		@Nullable Path customDir,
		Path expectedParent) throws Exception {

	final CheckpointStorage storage = savepointDir == null ?
			createCheckpointStorage(randomTempPath()) :
			createCheckpointStorageWithSavepointDir(randomTempPath(), savepointDir);

	final String customLocation = customDir == null ? null : customDir.toString();

	final CheckpointStorageLocation savepointLocation =
			storage.initializeLocationForSavepoint(52452L, customLocation);

	final byte[] data = {77, 66, 55, 99, 88};

	final CompletedCheckpointStorageLocation completed;
	try (CheckpointMetadataOutputStream out = savepointLocation.createMetadataOutputStream()) {
		out.write(data);
		completed = out.closeAndFinalizeCheckpoint();
	}

	// we need to do this step to make sure we have a slash (or not) in the same way as the
	// expected path has it
	final Path normalizedWithSlash = Path.fromLocalFile(new File(new Path(completed.getExternalPointer()).getParent().getPath()));

	assertEquals(expectedParent, normalizedWithSlash);
	validateContents(completed.getMetadataHandle(), data);

	// validate that the correct directory was used
	FileStateHandle fileStateHandle = (FileStateHandle) completed.getMetadataHandle();

	// we need to recreate that path in the same way as the "expected path" (via File and URI) to make
	// sure the either both use '/' suffixes, or neither uses them (a bit of an annoying ambiguity)
	Path usedSavepointDir = new Path(new File(fileStateHandle.getFilePath().getParent().getParent().getPath()).toURI());

	assertEquals(expectedParent, usedSavepointDir);
}
 
Example #28
Source File: StateBackendTestContext.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private CheckpointStorageLocation createCheckpointStorageLocation() {
	try {
		return stateBackend
			.createCheckpointStorage(new JobID())
			.initializeLocationForCheckpoint(2L);
	} catch (IOException e) {
		throw new RuntimeException("unexpected");
	}
}
 
Example #29
Source File: SavepointOutputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
private static CheckpointStorageLocation createSavepointLocation(Path location) throws IOException {
	final CheckpointStorageLocationReference reference = AbstractFsCheckpointStorage.encodePathAsReference(location);
	return new FsCheckpointStorageLocation(
		location.getFileSystem(),
		location,
		location,
		location,
		reference,
		CheckpointingOptions.FS_SMALL_FILE_THRESHOLD.defaultValue(),
		CheckpointingOptions.FS_WRITE_BUFFER_SIZE.defaultValue());
}
 
Example #30
Source File: AbstractFileCheckpointStorageTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Validates that multiple checkpoints from different jobs with the same checkpoint ID do not
 * interfere with each other.
 */
@Test
public void testPersistMultipleMetadataOnlyCheckpoints() throws Exception {
	final FileSystem fs = FileSystem.getLocalFileSystem();
	final Path checkpointDir = new Path(tmp.newFolder().toURI());

	final long checkpointId = 177;

	final CheckpointStorage storage1 = createCheckpointStorage(checkpointDir);
	storage1.initializeBaseLocations();
	final CheckpointStorage storage2 = createCheckpointStorage(checkpointDir);
	storage2.initializeBaseLocations();

	final CheckpointStorageLocation loc1 = storage1.initializeLocationForCheckpoint(checkpointId);
	final CheckpointStorageLocation loc2 = storage2.initializeLocationForCheckpoint(checkpointId);

	final byte[] data1 = {77, 66, 55, 99, 88};
	final byte[] data2 = {1, 3, 2, 5, 4};

	final CompletedCheckpointStorageLocation completedLocation1;
	try (CheckpointMetadataOutputStream out = loc1.createMetadataOutputStream()) {
		out.write(data1);
		completedLocation1 = out.closeAndFinalizeCheckpoint();
	}
	final String result1 = completedLocation1.getExternalPointer();

	final CompletedCheckpointStorageLocation completedLocation2;
	try (CheckpointMetadataOutputStream out = loc2.createMetadataOutputStream()) {
		out.write(data2);
		completedLocation2 = out.closeAndFinalizeCheckpoint();
	}
	final String result2 = completedLocation2.getExternalPointer();

	// check that this went to a file, but in a nested directory structure

	// one directory per storage
	FileStatus[] files = fs.listStatus(checkpointDir);
	assertEquals(2, files.length);

	// in each per-storage directory, one for the checkpoint
	FileStatus[] job1Files = fs.listStatus(files[0].getPath());
	FileStatus[] job2Files = fs.listStatus(files[1].getPath());
	assertTrue(job1Files.length >= 1);
	assertTrue(job2Files.length >= 1);

	assertTrue(fs.exists(new Path(result1, AbstractFsCheckpointStorage.METADATA_FILE_NAME)));
	assertTrue(fs.exists(new Path(result2, AbstractFsCheckpointStorage.METADATA_FILE_NAME)));

	// check that both storages can resolve each others contents
	validateContents(storage1.resolveCheckpoint(result1).getMetadataHandle(), data1);
	validateContents(storage1.resolveCheckpoint(result2).getMetadataHandle(), data2);
	validateContents(storage2.resolveCheckpoint(result1).getMetadataHandle(), data1);
	validateContents(storage2.resolveCheckpoint(result2).getMetadataHandle(), data2);
}