org.apache.flink.core.fs.FileSystemSafetyNet Java Examples

The following examples show how to use org.apache.flink.core.fs.FileSystemSafetyNet. 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: BucketingSinkFsInitTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Before
public void activateSafetyNet() {
	FileSystemSafetyNet.initializeSafetyNetForThread();
}
 
Example #2
Source File: BucketingSinkFsInitTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@After
public void deactivateSafetyNet() {
	FileSystemSafetyNet.closeSafetyNetAndGuardedResourcesForThread();
}
 
Example #3
Source File: Task.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Calls the invokable to trigger a checkpoint.
 *
 * @param checkpointID The ID identifying the checkpoint.
 * @param checkpointTimestamp The timestamp associated with the checkpoint.
 * @param checkpointOptions Options for performing this checkpoint.
 */
public void triggerCheckpointBarrier(
		final long checkpointID,
		long checkpointTimestamp,
		final CheckpointOptions checkpointOptions) {

	final AbstractInvokable invokable = this.invokable;
	final CheckpointMetaData checkpointMetaData = new CheckpointMetaData(checkpointID, checkpointTimestamp);

	if (executionState == ExecutionState.RUNNING && invokable != null) {

		// build a local closure
		final String taskName = taskNameWithSubtask;
		final SafetyNetCloseableRegistry safetyNetCloseableRegistry =
			FileSystemSafetyNet.getSafetyNetCloseableRegistryForThread();

		Runnable runnable = new Runnable() {
			@Override
			public void run() {
				// set safety net from the task's context for checkpointing thread
				LOG.debug("Creating FileSystem stream leak safety net for {}", Thread.currentThread().getName());
				FileSystemSafetyNet.setSafetyNetCloseableRegistryForThread(safetyNetCloseableRegistry);

				try {
					boolean success = invokable.triggerCheckpoint(checkpointMetaData, checkpointOptions);
					if (!success) {
						checkpointResponder.declineCheckpoint(
								getJobID(), getExecutionId(), checkpointID,
								new CheckpointDeclineTaskNotReadyException(taskName));
					}
				}
				catch (Throwable t) {
					if (getExecutionState() == ExecutionState.RUNNING) {
						failExternally(new Exception(
							"Error while triggering checkpoint " + checkpointID + " for " +
								taskNameWithSubtask, t));
					} else {
						LOG.debug("Encountered error while triggering checkpoint {} for " +
							"{} ({}) while being not in state running.", checkpointID,
							taskNameWithSubtask, executionId, t);
					}
				} finally {
					FileSystemSafetyNet.setSafetyNetCloseableRegistryForThread(null);
				}
			}
		};
		executeAsyncCallRunnable(runnable, String.format("Checkpoint Trigger for %s (%s).", taskNameWithSubtask, executionId));
	}
	else {
		LOG.debug("Declining checkpoint request for non-running task {} ({}).", taskNameWithSubtask, executionId);

		// send back a message that we did not do the checkpoint
		checkpointResponder.declineCheckpoint(jobId, executionId, checkpointID,
				new CheckpointDeclineTaskNotReadyException(taskNameWithSubtask));
	}
}
 
Example #4
Source File: BucketingSinkFsInitTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void activateSafetyNet() {
	FileSystemSafetyNet.initializeSafetyNetForThread();
}
 
Example #5
Source File: BucketingSinkFsInitTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@After
public void deactivateSafetyNet() {
	FileSystemSafetyNet.closeSafetyNetAndGuardedResourcesForThread();
}
 
Example #6
Source File: Task.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Calls the invokable to trigger a checkpoint.
 *
 * @param checkpointID The ID identifying the checkpoint.
 * @param checkpointTimestamp The timestamp associated with the checkpoint.
 * @param checkpointOptions Options for performing this checkpoint.
 * @param advanceToEndOfEventTime Flag indicating if the source should inject a {@code MAX_WATERMARK} in the pipeline
 *                           to fire any registered event-time timers.
 */
public void triggerCheckpointBarrier(
		final long checkpointID,
		final long checkpointTimestamp,
		final CheckpointOptions checkpointOptions,
		final boolean advanceToEndOfEventTime) {

	final AbstractInvokable invokable = this.invokable;
	final CheckpointMetaData checkpointMetaData = new CheckpointMetaData(checkpointID, checkpointTimestamp);

	if (executionState == ExecutionState.RUNNING && invokable != null) {

		// build a local closure
		final String taskName = taskNameWithSubtask;
		final SafetyNetCloseableRegistry safetyNetCloseableRegistry =
			FileSystemSafetyNet.getSafetyNetCloseableRegistryForThread();

		Runnable runnable = new Runnable() {
			@Override
			public void run() {
				// set safety net from the task's context for checkpointing thread
				LOG.debug("Creating FileSystem stream leak safety net for {}", Thread.currentThread().getName());
				FileSystemSafetyNet.setSafetyNetCloseableRegistryForThread(safetyNetCloseableRegistry);

				try {
					boolean success = invokable.triggerCheckpoint(checkpointMetaData, checkpointOptions, advanceToEndOfEventTime);
					if (!success) {
						checkpointResponder.declineCheckpoint(
								getJobID(), getExecutionId(), checkpointID,
								new CheckpointException("Task Name" + taskName, CheckpointFailureReason.CHECKPOINT_DECLINED_TASK_NOT_READY));
					}
				}
				catch (Throwable t) {
					if (getExecutionState() == ExecutionState.RUNNING) {
						failExternally(new Exception(
							"Error while triggering checkpoint " + checkpointID + " for " +
								taskNameWithSubtask, t));
					} else {
						LOG.debug("Encountered error while triggering checkpoint {} for " +
							"{} ({}) while being not in state running.", checkpointID,
							taskNameWithSubtask, executionId, t);
					}
				} finally {
					FileSystemSafetyNet.setSafetyNetCloseableRegistryForThread(null);
				}
			}
		};
		executeAsyncCallRunnable(
				runnable,
				String.format("Checkpoint Trigger for %s (%s).", taskNameWithSubtask, executionId));
	}
	else {
		LOG.debug("Declining checkpoint request for non-running task {} ({}).", taskNameWithSubtask, executionId);

		// send back a message that we did not do the checkpoint
		checkpointResponder.declineCheckpoint(jobId, executionId, checkpointID,
				new CheckpointException("Task name with subtask : " + taskNameWithSubtask, CheckpointFailureReason.CHECKPOINT_DECLINED_TASK_NOT_READY));
	}
}
 
Example #7
Source File: BucketingSinkFsInitTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void activateSafetyNet() {
	FileSystemSafetyNet.initializeSafetyNetForThread();
}
 
Example #8
Source File: BucketingSinkFsInitTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@After
public void deactivateSafetyNet() {
	FileSystemSafetyNet.closeSafetyNetAndGuardedResourcesForThread();
}