Java Code Examples for org.apache.flink.streaming.api.operators.StreamingRuntimeContext#getAllocationIDAsString()
The following examples show how to use
org.apache.flink.streaming.api.operators.StreamingRuntimeContext#getAllocationIDAsString() .
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: StickyAllocationAndLocalRecoveryTestJob.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception { ValueStateDescriptor<String> stateDescriptor = new ValueStateDescriptor<>("state", String.class); valueState = functionInitializationContext.getKeyedStateStore().getState(stateDescriptor); ListStateDescriptor<MapperSchedulingAndFailureInfo> mapperInfoStateDescriptor = new ListStateDescriptor<>("mapperState", MapperSchedulingAndFailureInfo.class); schedulingAndFailureState = functionInitializationContext.getOperatorStateStore().getUnionListState(mapperInfoStateDescriptor); StreamingRuntimeContext runtimeContext = (StreamingRuntimeContext) getRuntimeContext(); String allocationID = runtimeContext.getAllocationIDAsString(); final int thisJvmPid = getJvmPid(); final Set<Integer> killedJvmPids = new HashSet<>(); // here we check if the sticky scheduling worked as expected if (functionInitializationContext.isRestored()) { Iterable<MapperSchedulingAndFailureInfo> iterable = schedulingAndFailureState.get(); String taskNameWithSubtasks = runtimeContext.getTaskNameWithSubtasks(); MapperSchedulingAndFailureInfo infoForThisTask = null; List<MapperSchedulingAndFailureInfo> completeInfo = new ArrayList<>(); if (iterable != null) { for (MapperSchedulingAndFailureInfo testInfo : iterable) { completeInfo.add(testInfo); if (taskNameWithSubtasks.equals(testInfo.taskNameWithSubtask)) { infoForThisTask = testInfo; } if (testInfo.killedJvm) { killedJvmPids.add(testInfo.jvmPid); } } } Preconditions.checkNotNull(infoForThisTask, "Expected to find info here."); if (!isScheduledToCorrectAllocation(infoForThisTask, allocationID, killedJvmPids)) { allocationFailureMessage = String.format( "Sticky allocation test failed: Subtask %s in attempt %d was rescheduled from allocation %s " + "on JVM with PID %d to unexpected allocation %s on JVM with PID %d.\n" + "Complete information from before the crash: %s.", runtimeContext.getTaskNameWithSubtasks(), runtimeContext.getAttemptNumber(), infoForThisTask.allocationId, infoForThisTask.jvmPid, allocationID, thisJvmPid, completeInfo); } } // We determine which of the subtasks will produce the artificial failure boolean failingTask = shouldTaskFailForThisAttempt(); // We take note of all the meta info that we require to check sticky scheduling in the next re-attempt this.currentSchedulingAndFailureInfo = new MapperSchedulingAndFailureInfo( failingTask, failingTask && killTaskOnFailure, thisJvmPid, runtimeContext.getTaskNameWithSubtasks(), allocationID); schedulingAndFailureState.clear(); schedulingAndFailureState.add(currentSchedulingAndFailureInfo); }
Example 2
Source File: StickyAllocationAndLocalRecoveryTestJob.java From flink with Apache License 2.0 | 4 votes |
@Override public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception { ValueStateDescriptor<String> stateDescriptor = new ValueStateDescriptor<>("state", String.class); valueState = functionInitializationContext.getKeyedStateStore().getState(stateDescriptor); ListStateDescriptor<MapperSchedulingAndFailureInfo> mapperInfoStateDescriptor = new ListStateDescriptor<>("mapperState", MapperSchedulingAndFailureInfo.class); schedulingAndFailureState = functionInitializationContext.getOperatorStateStore().getUnionListState(mapperInfoStateDescriptor); StreamingRuntimeContext runtimeContext = (StreamingRuntimeContext) getRuntimeContext(); String allocationID = runtimeContext.getAllocationIDAsString(); final int thisJvmPid = getJvmPid(); final Set<Integer> killedJvmPids = new HashSet<>(); // here we check if the sticky scheduling worked as expected if (functionInitializationContext.isRestored()) { Iterable<MapperSchedulingAndFailureInfo> iterable = schedulingAndFailureState.get(); String taskNameWithSubtasks = runtimeContext.getTaskNameWithSubtasks(); MapperSchedulingAndFailureInfo infoForThisTask = null; List<MapperSchedulingAndFailureInfo> completeInfo = new ArrayList<>(); if (iterable != null) { for (MapperSchedulingAndFailureInfo testInfo : iterable) { completeInfo.add(testInfo); if (taskNameWithSubtasks.equals(testInfo.taskNameWithSubtask)) { infoForThisTask = testInfo; } if (testInfo.killedJvm) { killedJvmPids.add(testInfo.jvmPid); } } } Preconditions.checkNotNull(infoForThisTask, "Expected to find info here."); if (!isScheduledToCorrectAllocation(infoForThisTask, allocationID, killedJvmPids)) { allocationFailureMessage = String.format( "Sticky allocation test failed: Subtask %s in attempt %d was rescheduled from allocation %s " + "on JVM with PID %d to unexpected allocation %s on JVM with PID %d.\n" + "Complete information from before the crash: %s.", runtimeContext.getTaskNameWithSubtasks(), runtimeContext.getAttemptNumber(), infoForThisTask.allocationId, infoForThisTask.jvmPid, allocationID, thisJvmPid, completeInfo); } } // We determine which of the subtasks will produce the artificial failure boolean failingTask = shouldTaskFailForThisAttempt(); // We take note of all the meta info that we require to check sticky scheduling in the next re-attempt this.currentSchedulingAndFailureInfo = new MapperSchedulingAndFailureInfo( failingTask, failingTask && killTaskOnFailure, thisJvmPid, runtimeContext.getTaskNameWithSubtasks(), allocationID); schedulingAndFailureState.clear(); schedulingAndFailureState.add(currentSchedulingAndFailureInfo); }
Example 3
Source File: StickyAllocationAndLocalRecoveryTestJob.java From flink with Apache License 2.0 | 4 votes |
@Override public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception { ValueStateDescriptor<String> stateDescriptor = new ValueStateDescriptor<>("state", String.class); valueState = functionInitializationContext.getKeyedStateStore().getState(stateDescriptor); ListStateDescriptor<MapperSchedulingAndFailureInfo> mapperInfoStateDescriptor = new ListStateDescriptor<>("mapperState", MapperSchedulingAndFailureInfo.class); schedulingAndFailureState = functionInitializationContext.getOperatorStateStore().getUnionListState(mapperInfoStateDescriptor); StreamingRuntimeContext runtimeContext = (StreamingRuntimeContext) getRuntimeContext(); String allocationID = runtimeContext.getAllocationIDAsString(); final int thisJvmPid = getJvmPid(); final Set<Integer> killedJvmPids = new HashSet<>(); // here we check if the sticky scheduling worked as expected if (functionInitializationContext.isRestored()) { Iterable<MapperSchedulingAndFailureInfo> iterable = schedulingAndFailureState.get(); String taskNameWithSubtasks = runtimeContext.getTaskNameWithSubtasks(); MapperSchedulingAndFailureInfo infoForThisTask = null; List<MapperSchedulingAndFailureInfo> completeInfo = new ArrayList<>(); if (iterable != null) { for (MapperSchedulingAndFailureInfo testInfo : iterable) { completeInfo.add(testInfo); if (taskNameWithSubtasks.equals(testInfo.taskNameWithSubtask)) { infoForThisTask = testInfo; } if (testInfo.killedJvm) { killedJvmPids.add(testInfo.jvmPid); } } } Preconditions.checkNotNull(infoForThisTask, "Expected to find info here."); if (!isScheduledToCorrectAllocation(infoForThisTask, allocationID, killedJvmPids)) { allocationFailureMessage = String.format( "Sticky allocation test failed: Subtask %s in attempt %d was rescheduled from allocation %s " + "on JVM with PID %d to unexpected allocation %s on JVM with PID %d.\n" + "Complete information from before the crash: %s.", runtimeContext.getTaskNameWithSubtasks(), runtimeContext.getAttemptNumber(), infoForThisTask.allocationId, infoForThisTask.jvmPid, allocationID, thisJvmPid, completeInfo); } } // We determine which of the subtasks will produce the artificial failure boolean failingTask = shouldTaskFailForThisAttempt(); // We take note of all the meta info that we require to check sticky scheduling in the next re-attempt this.currentSchedulingAndFailureInfo = new MapperSchedulingAndFailureInfo( failingTask, failingTask && killTaskOnFailure, thisJvmPid, runtimeContext.getTaskNameWithSubtasks(), allocationID); schedulingAndFailureState.clear(); schedulingAndFailureState.add(currentSchedulingAndFailureInfo); }