use of org.apache.flink.runtime.jobgraph.JobVertexID in project flink by apache.
the class BackPressureStatsTrackerTest method testTriggerStackTraceSample.
/** Tests simple statistics with fake stack traces. */
@Test
@SuppressWarnings("unchecked")
public void testTriggerStackTraceSample() throws Exception {
CompletableFuture<StackTraceSample> sampleFuture = new FlinkCompletableFuture<>();
StackTraceSampleCoordinator sampleCoordinator = mock(StackTraceSampleCoordinator.class);
when(sampleCoordinator.triggerStackTraceSample(any(ExecutionVertex[].class), anyInt(), any(Time.class), anyInt())).thenReturn(sampleFuture);
ExecutionGraph graph = mock(ExecutionGraph.class);
when(graph.getState()).thenReturn(JobStatus.RUNNING);
// Same Thread execution context
when(graph.getFutureExecutor()).thenReturn(new Executor() {
@Override
public void execute(Runnable runnable) {
runnable.run();
}
});
ExecutionVertex[] taskVertices = new ExecutionVertex[4];
ExecutionJobVertex jobVertex = mock(ExecutionJobVertex.class);
when(jobVertex.getJobId()).thenReturn(new JobID());
when(jobVertex.getJobVertexId()).thenReturn(new JobVertexID());
when(jobVertex.getGraph()).thenReturn(graph);
when(jobVertex.getTaskVertices()).thenReturn(taskVertices);
taskVertices[0] = mockExecutionVertex(jobVertex, 0);
taskVertices[1] = mockExecutionVertex(jobVertex, 1);
taskVertices[2] = mockExecutionVertex(jobVertex, 2);
taskVertices[3] = mockExecutionVertex(jobVertex, 3);
int numSamples = 100;
Time delayBetweenSamples = Time.milliseconds(100L);
BackPressureStatsTracker tracker = new BackPressureStatsTracker(sampleCoordinator, 9999, numSamples, delayBetweenSamples);
// Trigger
assertTrue("Failed to trigger", tracker.triggerStackTraceSample(jobVertex));
verify(sampleCoordinator).triggerStackTraceSample(eq(taskVertices), eq(numSamples), eq(delayBetweenSamples), eq(BackPressureStatsTracker.MAX_STACK_TRACE_DEPTH));
// Trigger again for pending request, should not fire
assertFalse("Unexpected trigger", tracker.triggerStackTraceSample(jobVertex));
assertTrue(tracker.getOperatorBackPressureStats(jobVertex).isEmpty());
verify(sampleCoordinator).triggerStackTraceSample(eq(taskVertices), eq(numSamples), eq(delayBetweenSamples), eq(BackPressureStatsTracker.MAX_STACK_TRACE_DEPTH));
assertTrue(tracker.getOperatorBackPressureStats(jobVertex).isEmpty());
// Complete the future
Map<ExecutionAttemptID, List<StackTraceElement[]>> traces = new HashMap<>();
for (ExecutionVertex vertex : taskVertices) {
List<StackTraceElement[]> taskTraces = new ArrayList<>();
for (int i = 0; i < taskVertices.length; i++) {
// Traces until sub task index are back pressured
taskTraces.add(createStackTrace(i <= vertex.getParallelSubtaskIndex()));
}
traces.put(vertex.getCurrentExecutionAttempt().getAttemptId(), taskTraces);
}
int sampleId = 1231;
int endTime = 841;
StackTraceSample sample = new StackTraceSample(sampleId, 0, endTime, traces);
// Succeed the promise
sampleFuture.complete(sample);
assertTrue(tracker.getOperatorBackPressureStats(jobVertex).isDefined());
OperatorBackPressureStats stats = tracker.getOperatorBackPressureStats(jobVertex).get();
// Verify the stats
assertEquals(sampleId, stats.getSampleId());
assertEquals(endTime, stats.getEndTimestamp());
assertEquals(taskVertices.length, stats.getNumberOfSubTasks());
for (int i = 0; i < taskVertices.length; i++) {
double ratio = stats.getBackPressureRatio(i);
// Traces until sub task index are back pressured
assertEquals((i + 1) / ((double) 4), ratio, 0.0);
}
}
use of org.apache.flink.runtime.jobgraph.JobVertexID in project flink by apache.
the class CheckpointStatsSubtaskDetailsHandlerTest method testCheckpointNotFound.
/**
* Test lookup of not existing checkpoint in history.
*/
@Test
public void testCheckpointNotFound() throws Exception {
CheckpointStatsHistory history = mock(CheckpointStatsHistory.class);
// not found
when(history.getCheckpointById(anyLong())).thenReturn(null);
CheckpointStatsSnapshot snapshot = mock(CheckpointStatsSnapshot.class);
when(snapshot.getHistory()).thenReturn(history);
AccessExecutionGraph graph = mock(AccessExecutionGraph.class);
when(graph.getCheckpointStatsSnapshot()).thenReturn(snapshot);
CheckpointStatsDetailsSubtasksHandler handler = new CheckpointStatsDetailsSubtasksHandler(mock(ExecutionGraphHolder.class), new CheckpointStatsCache(0));
Map<String, String> params = new HashMap<>();
params.put("checkpointid", "123");
params.put("vertexid", new JobVertexID().toString());
String json = handler.handleRequest(graph, params);
assertEquals("{}", json);
verify(history, times(1)).getCheckpointById(anyLong());
}
use of org.apache.flink.runtime.jobgraph.JobVertexID in project flink by apache.
the class CheckpointStatsSubtaskDetailsHandlerTest method triggerRequest.
// ------------------------------------------------------------------------
private static JsonNode triggerRequest(AbstractCheckpointStats checkpoint) throws Exception {
CheckpointStatsHistory history = mock(CheckpointStatsHistory.class);
when(history.getCheckpointById(anyLong())).thenReturn(checkpoint);
CheckpointStatsSnapshot snapshot = mock(CheckpointStatsSnapshot.class);
when(snapshot.getHistory()).thenReturn(history);
AccessExecutionGraph graph = mock(AccessExecutionGraph.class);
when(graph.getCheckpointStatsSnapshot()).thenReturn(snapshot);
CheckpointStatsDetailsSubtasksHandler handler = new CheckpointStatsDetailsSubtasksHandler(mock(ExecutionGraphHolder.class), new CheckpointStatsCache(0));
Map<String, String> params = new HashMap<>();
params.put("checkpointid", "123");
params.put("vertexid", new JobVertexID().toString());
String json = handler.handleRequest(graph, params);
ObjectMapper mapper = new ObjectMapper();
return mapper.readTree(json);
}
use of org.apache.flink.runtime.jobgraph.JobVertexID in project flink by apache.
the class ArchivedJobGenerationUtils method generateArchivedJob.
private static void generateArchivedJob() throws Exception {
// Attempt
StringifiedAccumulatorResult acc1 = new StringifiedAccumulatorResult("name1", "type1", "value1");
StringifiedAccumulatorResult acc2 = new StringifiedAccumulatorResult("name2", "type2", "value2");
TaskManagerLocation location = new TaskManagerLocation(new ResourceID("hello"), InetAddress.getLocalHost(), 1234);
originalAttempt = new ArchivedExecutionBuilder().setStateTimestamps(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }).setParallelSubtaskIndex(1).setAttemptNumber(0).setAssignedResourceLocation(location).setUserAccumulators(new StringifiedAccumulatorResult[] { acc1, acc2 }).setState(ExecutionState.FINISHED).setFailureCause("attemptException").build();
// Subtask
originalSubtask = new ArchivedExecutionVertexBuilder().setSubtaskIndex(originalAttempt.getParallelSubtaskIndex()).setTaskNameWithSubtask("hello(1/1)").setCurrentExecution(originalAttempt).build();
// Task
originalTask = new ArchivedExecutionJobVertexBuilder().setTaskVertices(new ArchivedExecutionVertex[] { originalSubtask }).build();
// Job
Map<JobVertexID, ArchivedExecutionJobVertex> tasks = new HashMap<>();
tasks.put(originalTask.getJobVertexId(), originalTask);
originalJob = new ArchivedExecutionGraphBuilder().setJobID(new JobID()).setTasks(tasks).setFailureCause("jobException").setState(JobStatus.FINISHED).setStateTimestamps(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).setArchivedUserAccumulators(new StringifiedAccumulatorResult[] { acc1, acc2 }).build();
}
use of org.apache.flink.runtime.jobgraph.JobVertexID in project flink by apache.
the class SavepointV0Serializer method convertTaskState.
private org.apache.flink.runtime.checkpoint.TaskState convertTaskState(TaskState taskState, ClassLoader userClassLoader, long checkpointID) throws Exception {
JobVertexID jobVertexID = taskState.getJobVertexID();
int parallelism = taskState.getParallelism();
int chainLength = determineOperatorChainLength(taskState, userClassLoader);
org.apache.flink.runtime.checkpoint.TaskState newTaskState = new org.apache.flink.runtime.checkpoint.TaskState(jobVertexID, parallelism, parallelism, chainLength);
if (chainLength > 0) {
Map<Integer, SubtaskState> subtaskStates = taskState.getSubtaskStatesById();
for (Map.Entry<Integer, SubtaskState> subtaskState : subtaskStates.entrySet()) {
int parallelInstanceIdx = subtaskState.getKey();
newTaskState.putState(parallelInstanceIdx, convertSubtaskState(subtaskState.getValue(), parallelInstanceIdx, userClassLoader, checkpointID));
}
}
return newTaskState;
}
Aggregations