use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.
the class CheckpointCoordinatorTest method ackCheckpoint.
private void ackCheckpoint(long checkpointId, CheckpointCoordinator coordinator, JobVertexID ackVertexID, ExecutionGraph graph, TestingStreamStateHandle metaState, TestingStreamStateHandle privateState, TestingStreamStateHandle sharedState) throws CheckpointException {
Map<StateHandleID, StreamStateHandle> sharedStateMap = new HashMap<>(singletonMap(new StateHandleID("shared-state-key"), sharedState));
Map<StateHandleID, StreamStateHandle> privateStateMap = new HashMap<>(singletonMap(new StateHandleID("private-state-key"), privateState));
ExecutionJobVertex jobVertex = graph.getJobVertex(ackVertexID);
OperatorID operatorID = jobVertex.getOperatorIDs().get(0).getGeneratedOperatorID();
coordinator.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(graph.getJobID(), jobVertex.getTaskVertices()[0].getCurrentExecutionAttempt().getAttemptId(), checkpointId, new CheckpointMetrics(), new TaskStateSnapshot(singletonMap(operatorID, OperatorSubtaskState.builder().setManagedKeyedState(new IncrementalRemoteKeyedStateHandle(UUID.randomUUID(), KeyGroupRange.of(0, 9), checkpointId, sharedStateMap, privateStateMap, metaState)).build()))), "test");
}
use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.
the class CheckpointCoordinatorTest method testSharedStateNotDiscaredOnAbort.
@Test
public void testSharedStateNotDiscaredOnAbort() throws Exception {
JobVertexID v1 = new JobVertexID(), v2 = new JobVertexID();
ExecutionGraph graph = new CheckpointCoordinatorTestingUtils.CheckpointExecutionGraphBuilder().addJobVertex(v1).addJobVertex(v2).build();
CheckpointCoordinator coordinator = new CheckpointCoordinatorBuilder().setExecutionGraph(graph).setTimer(manuallyTriggeredScheduledExecutor).build();
coordinator.startCheckpointScheduler();
CompletableFuture<CompletedCheckpoint> cpFuture = coordinator.triggerCheckpoint(true);
manuallyTriggeredScheduledExecutor.triggerAll();
cpFuture.getNow(null);
TestingStreamStateHandle metaState = handle();
TestingStreamStateHandle privateState = handle();
TestingStreamStateHandle sharedState = handle();
ackCheckpoint(1L, coordinator, v1, graph, metaState, privateState, sharedState);
declineCheckpoint(1L, coordinator, v2, graph);
assertTrue(privateState.isDisposed());
assertTrue(metaState.isDisposed());
assertFalse(sharedState.isDisposed());
cpFuture = coordinator.triggerCheckpoint(true);
manuallyTriggeredScheduledExecutor.triggerAll();
cpFuture.getNow(null);
ackCheckpoint(2L, coordinator, v1, graph, handle(), handle(), handle());
ackCheckpoint(2L, coordinator, v2, graph, handle(), handle(), handle());
cpFuture.get();
assertTrue(sharedState.isDisposed());
}
use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.
the class DefaultCompletedCheckpointStoreTest method registerState.
private TestingStreamStateHandle registerState(CompletedCheckpointStore completedCheckpointStore, long checkpointID) {
TestingStreamStateHandle handle = new TestingStreamStateHandle();
completedCheckpointStore.getSharedStateRegistry().registerReference(new SharedStateRegistryKey(String.valueOf(new Object().hashCode())), handle, checkpointID);
return handle;
}
use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.
the class DefaultCompletedCheckpointStoreTest method testShutdownShouldDiscardStateHandleWhenJobIsGloballyTerminalState.
@Test
public void testShutdownShouldDiscardStateHandleWhenJobIsGloballyTerminalState() throws Exception {
int numBeforeRetained = 3;
int numAfterRetained = 4;
long retainedCheckpointID = numBeforeRetained + 1;
final int numCheckpoints = numBeforeRetained + 1 + numAfterRetained;
final AtomicInteger removeCalledNum = new AtomicInteger(0);
final CompletableFuture<Void> clearEntriesAllFuture = new CompletableFuture<>();
final TestingStateHandleStore<CompletedCheckpoint> stateHandleStore = builder.setGetAllSupplier(() -> createStateHandles(numBeforeRetained, numAfterRetained)).setRemoveFunction(ignore -> {
removeCalledNum.incrementAndGet();
return true;
}).setClearEntriesRunnable(() -> clearEntriesAllFuture.complete(null)).build();
final CompletedCheckpointStore completedCheckpointStore = createCompletedCheckpointStore(stateHandleStore);
assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(numCheckpoints));
// emulate shared state registration for two checkpoints which won't be completed
TestingStreamStateHandle nonRetainedState = registerState(completedCheckpointStore, retainedCheckpointID - 1);
TestingStreamStateHandle retainedState = registerState(completedCheckpointStore, retainedCheckpointID);
TestingStreamStateHandle beyondRetained = registerState(completedCheckpointStore, retainedCheckpointID + 1);
completedCheckpointStore.shutdown(JobStatus.CANCELED, new CheckpointsCleaner());
assertThat(removeCalledNum.get(), is(numCheckpoints));
assertThat(clearEntriesAllFuture.isDone(), is(true));
assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(0));
assertThat(nonRetainedState.isDisposed(), is(true));
assertThat(retainedState.isDisposed(), is(false));
assertThat(beyondRetained.isDisposed(), is(false));
}
use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.
the class PendingCheckpointTest method testDuplicateAcknowledgeCoordinator.
@Test
public void testDuplicateAcknowledgeCoordinator() throws Exception {
final OperatorInfo coordinator = new TestingOperatorInfo();
final PendingCheckpoint checkpoint = createPendingCheckpointWithCoordinators(coordinator);
checkpoint.acknowledgeCoordinatorState(coordinator, new TestingStreamStateHandle());
final TaskAcknowledgeResult secondAck = checkpoint.acknowledgeCoordinatorState(coordinator, null);
assertEquals(TaskAcknowledgeResult.DUPLICATE, secondAck);
}
Aggregations