Java Code Examples for org.apache.flink.api.common.functions.RuntimeContext#getAttemptNumber()

The following examples show how to use org.apache.flink.api.common.functions.RuntimeContext#getAttemptNumber() . 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: FailingSource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void run(SourceContext<Tuple2<Long, IntType>> ctx) throws Exception {

	final RuntimeContext runtimeContext = getRuntimeContext();
	// detect if this task is "the chosen one" and should fail (via subtaskidx), if it did not fail before (via attempt)
	final boolean failThisTask =
		runtimeContext.getAttemptNumber() == 0 && runtimeContext.getIndexOfThisSubtask() == 0;

	// we loop longer than we have elements, to permit delayed checkpoints
	// to still cause a failure
	while (running && emitCallCount < expectedEmitCalls) {

		// the function failed before, or we are in the elements before the failure
		synchronized (ctx.getCheckpointLock()) {
			eventEmittingGenerator.emitEvent(ctx, emitCallCount++);
		}

		if (emitCallCount < failureAfterNumElements) {
			Thread.sleep(1);
		} else if (failThisTask && emitCallCount == failureAfterNumElements) {
			// wait for a pending checkpoint that fulfills our requirements if needed
			while (checkpointStatus.get() != STATEFUL_CHECKPOINT_COMPLETED) {
				Thread.sleep(1);
			}
			throw new Exception("Artificial Failure");
		}
	}

	if (usingProcessingTime) {
		while (running) {
			Thread.sleep(10);
		}
	}
}
 
Example 2
Source File: StickyAllocationAndLocalRecoveryTestJob.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private boolean shouldTaskFailForThisAttempt() {
	RuntimeContext runtimeContext = getRuntimeContext();
	int numSubtasks = runtimeContext.getNumberOfParallelSubtasks();
	int subtaskIdx = runtimeContext.getIndexOfThisSubtask();
	int attempt = runtimeContext.getAttemptNumber();
	return (attempt % numSubtasks) == subtaskIdx;
}
 
Example 3
Source File: FailingSource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run(SourceContext<Tuple2<Long, IntType>> ctx) throws Exception {

	final RuntimeContext runtimeContext = getRuntimeContext();
	// detect if this task is "the chosen one" and should fail (via subtaskidx), if it did not fail before (via attempt)
	final boolean failThisTask =
		runtimeContext.getAttemptNumber() == 0 && runtimeContext.getIndexOfThisSubtask() == 0;

	// we loop longer than we have elements, to permit delayed checkpoints
	// to still cause a failure
	while (running && emitCallCount < expectedEmitCalls) {

		// the function failed before, or we are in the elements before the failure
		synchronized (ctx.getCheckpointLock()) {
			eventEmittingGenerator.emitEvent(ctx, emitCallCount++);
		}

		if (emitCallCount < failureAfterNumElements) {
			Thread.sleep(1);
		} else if (failThisTask && emitCallCount == failureAfterNumElements) {
			// wait for a pending checkpoint that fulfills our requirements if needed
			while (checkpointStatus.get() != STATEFUL_CHECKPOINT_COMPLETED) {
				Thread.sleep(1);
			}
			throw new Exception("Artificial Failure");
		}
	}

	if (usingProcessingTime) {
		while (running) {
			Thread.sleep(10);
		}
	}
}
 
Example 4
Source File: StickyAllocationAndLocalRecoveryTestJob.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean shouldTaskFailForThisAttempt() {
	RuntimeContext runtimeContext = getRuntimeContext();
	int numSubtasks = runtimeContext.getNumberOfParallelSubtasks();
	int subtaskIdx = runtimeContext.getIndexOfThisSubtask();
	int attempt = runtimeContext.getAttemptNumber();
	return (attempt % numSubtasks) == subtaskIdx;
}
 
Example 5
Source File: FailingSource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run(SourceContext<Tuple2<Long, IntType>> ctx) throws Exception {

	final RuntimeContext runtimeContext = getRuntimeContext();
	// detect if this task is "the chosen one" and should fail (via subtaskidx), if it did not fail before (via attempt)
	final boolean failThisTask =
		runtimeContext.getAttemptNumber() == 0 && runtimeContext.getIndexOfThisSubtask() == 0;

	// we loop longer than we have elements, to permit delayed checkpoints
	// to still cause a failure
	while (running && emitCallCount < expectedEmitCalls) {

		// the function failed before, or we are in the elements before the failure
		synchronized (ctx.getCheckpointLock()) {
			eventEmittingGenerator.emitEvent(ctx, emitCallCount++);
		}

		if (emitCallCount < failureAfterNumElements) {
			Thread.sleep(1);
		} else if (failThisTask && emitCallCount == failureAfterNumElements) {
			// wait for a pending checkpoint that fulfills our requirements if needed
			while (checkpointStatus.get() != STATEFUL_CHECKPOINT_COMPLETED) {
				Thread.sleep(1);
			}
			throw new Exception("Artificial Failure");
		}
	}

	if (usingProcessingTime) {
		while (running) {
			Thread.sleep(10);
		}
	}
}
 
Example 6
Source File: StickyAllocationAndLocalRecoveryTestJob.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean shouldTaskFailForThisAttempt() {
	RuntimeContext runtimeContext = getRuntimeContext();
	int numSubtasks = runtimeContext.getNumberOfParallelSubtasks();
	int subtaskIdx = runtimeContext.getIndexOfThisSubtask();
	int attempt = runtimeContext.getAttemptNumber();
	return (attempt % numSubtasks) == subtaskIdx;
}