Search in sources :

Example 1 with TestingStreamStateHandle

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");
}
Also used : AcknowledgeCheckpoint(org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint) PlaceholderStreamStateHandle(org.apache.flink.runtime.state.PlaceholderStreamStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) HashMap(java.util.HashMap) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) StateHandleID(org.apache.flink.runtime.state.StateHandleID) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID)

Example 2 with TestingStreamStateHandle

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());
}
Also used : TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) CheckpointCoordinatorBuilder(org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder) Test(org.junit.Test)

Example 3 with TestingStreamStateHandle

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;
}
Also used : TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) SharedStateRegistryKey(org.apache.flink.runtime.state.SharedStateRegistryKey)

Example 4 with TestingStreamStateHandle

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));
}
Also used : TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 5 with TestingStreamStateHandle

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);
}
Also used : TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) TaskAcknowledgeResult(org.apache.flink.runtime.checkpoint.PendingCheckpoint.TaskAcknowledgeResult) OperatorInfo(org.apache.flink.runtime.operators.coordination.OperatorInfo) TestingOperatorInfo(org.apache.flink.runtime.operators.coordination.TestingOperatorInfo) TestingOperatorInfo(org.apache.flink.runtime.operators.coordination.TestingOperatorInfo) Test(org.junit.Test)

Aggregations

TestingStreamStateHandle (org.apache.flink.runtime.state.TestingStreamStateHandle)9 Test (org.junit.Test)7 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 TaskAcknowledgeResult (org.apache.flink.runtime.checkpoint.PendingCheckpoint.TaskAcknowledgeResult)2 ExecutionGraph (org.apache.flink.runtime.executiongraph.ExecutionGraph)2 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 OperatorInfo (org.apache.flink.runtime.operators.coordination.OperatorInfo)2 TestingOperatorInfo (org.apache.flink.runtime.operators.coordination.TestingOperatorInfo)2 SharedStateRegistryKey (org.apache.flink.runtime.state.SharedStateRegistryKey)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1