Search in sources :

Example 11 with SharedStateRegistry

use of org.apache.flink.runtime.state.SharedStateRegistry in project flink by apache.

the class ZooKeeperCompletedCheckpointStoreITCase method testShutdownDiscardsCheckpoints.

/**
 * Tests that shutdown discards all checkpoints.
 */
@Test
public void testShutdownDiscardsCheckpoints() throws Exception {
    CuratorFramework client = ZOOKEEPER.getClient();
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    CompletedCheckpointStore store = createRecoveredCompletedCheckpointStore(1);
    TestCompletedCheckpoint checkpoint = createCheckpoint(0, sharedStateRegistry);
    store.addCheckpointAndSubsumeOldestOne(checkpoint, new CheckpointsCleaner(), () -> {
    });
    assertEquals(1, store.getNumberOfRetainedCheckpoints());
    assertNotNull(client.checkExists().forPath(CHECKPOINT_PATH + checkpointStoreUtil.checkpointIDToName(checkpoint.getCheckpointID())));
    store.shutdown(JobStatus.FINISHED, new CheckpointsCleaner());
    assertEquals(0, store.getNumberOfRetainedCheckpoints());
    assertNull(client.checkExists().forPath(CHECKPOINT_PATH + checkpointStoreUtil.checkpointIDToName(checkpoint.getCheckpointID())));
    sharedStateRegistry.close();
    assertEquals(0, createRecoveredCompletedCheckpointStore(1).getNumberOfRetainedCheckpoints());
}
Also used : CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 12 with SharedStateRegistry

use of org.apache.flink.runtime.state.SharedStateRegistry in project flink by apache.

the class ZooKeeperCompletedCheckpointStoreITCase method testConcurrentCheckpointOperations.

/**
 * FLINK-6612
 *
 * <p>Checks that a concurrent checkpoint completion won't discard a checkpoint which has been
 * recovered by a different completed checkpoint store.
 */
@Test
public void testConcurrentCheckpointOperations() throws Exception {
    final int numberOfCheckpoints = 1;
    final long waitingTimeout = 50L;
    final CompletedCheckpointStore zkCheckpointStore1 = createRecoveredCompletedCheckpointStore(numberOfCheckpoints);
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    TestCompletedCheckpoint completedCheckpoint = createCheckpoint(1, sharedStateRegistry);
    // complete the first checkpoint
    zkCheckpointStore1.addCheckpointAndSubsumeOldestOne(completedCheckpoint, new CheckpointsCleaner(), () -> {
    });
    // recover the checkpoint by a different checkpoint store
    sharedStateRegistry.close();
    sharedStateRegistry = new SharedStateRegistryImpl();
    final CompletedCheckpointStore zkCheckpointStore2 = createRecoveredCompletedCheckpointStore(numberOfCheckpoints);
    CompletedCheckpoint recoveredCheckpoint = zkCheckpointStore2.getLatestCheckpoint();
    assertTrue(recoveredCheckpoint instanceof TestCompletedCheckpoint);
    TestCompletedCheckpoint recoveredTestCheckpoint = (TestCompletedCheckpoint) recoveredCheckpoint;
    // Check that the recovered checkpoint is not yet discarded
    assertFalse(recoveredTestCheckpoint.isDiscarded());
    // complete another checkpoint --> this should remove the first checkpoint from the store
    // because the number of retained checkpoints == 1
    TestCompletedCheckpoint completedCheckpoint2 = createCheckpoint(2, sharedStateRegistry);
    zkCheckpointStore1.addCheckpointAndSubsumeOldestOne(completedCheckpoint2, new CheckpointsCleaner(), () -> {
    });
    List<CompletedCheckpoint> allCheckpoints = zkCheckpointStore1.getAllCheckpoints();
    // check that we have removed the first checkpoint from zkCompletedStore1
    assertEquals(Collections.singletonList(completedCheckpoint2), allCheckpoints);
    // lets wait a little bit to see that no discard operation will be executed
    assertFalse("The checkpoint should not have been discarded.", recoveredTestCheckpoint.awaitDiscard(waitingTimeout));
    // check that we have not discarded the first completed checkpoint
    assertFalse(recoveredTestCheckpoint.isDiscarded());
    TestCompletedCheckpoint completedCheckpoint3 = createCheckpoint(3, sharedStateRegistry);
    // this should release the last lock on completedCheckpoint and thus discard it
    zkCheckpointStore2.addCheckpointAndSubsumeOldestOne(completedCheckpoint3, new CheckpointsCleaner(), () -> {
    });
    // the checkpoint should be discarded eventually because there is no lock on it anymore
    recoveredTestCheckpoint.awaitDiscard();
}
Also used : SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) CheckpointRequestDeciderTest.regularCheckpoint(org.apache.flink.runtime.checkpoint.CheckpointRequestDeciderTest.regularCheckpoint) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 13 with SharedStateRegistry

use of org.apache.flink.runtime.state.SharedStateRegistry in project flink by apache.

the class CompletedCheckpointTest method testRegisterStatesAtRegistry.

@Test
public void testRegisterStatesAtRegistry() {
    OperatorState state = mock(OperatorState.class);
    Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
    operatorStates.put(new OperatorID(), state);
    CompletedCheckpoint checkpoint = new CompletedCheckpoint(new JobID(), 0, 0, 1, operatorStates, Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), new TestCompletedCheckpointStorageLocation());
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    checkpoint.registerSharedStatesAfterRestored(sharedStateRegistry);
    verify(state, times(1)).registerSharedStates(sharedStateRegistry, 0L);
}
Also used : HashMap(java.util.HashMap) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) JobID(org.apache.flink.api.common.JobID) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 14 with SharedStateRegistry

use of org.apache.flink.runtime.state.SharedStateRegistry in project flink by apache.

the class ZooKeeperCompletedCheckpointStoreTest method testDiscardingSubsumedCheckpoints.

/**
 * Tests that subsumed checkpoints are discarded.
 */
@Test
public void testDiscardingSubsumedCheckpoints() throws Exception {
    final SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    final Configuration configuration = new Configuration();
    configuration.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, zooKeeperResource.getConnectString());
    final CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper = ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE);
    final CompletedCheckpointStore checkpointStore = createZooKeeperCheckpointStore(curatorFrameworkWrapper.asCuratorFramework());
    try {
        final CompletedCheckpointStoreTest.TestCompletedCheckpoint checkpoint1 = CompletedCheckpointStoreTest.createCheckpoint(0, sharedStateRegistry);
        checkpointStore.addCheckpointAndSubsumeOldestOne(checkpoint1, new CheckpointsCleaner(), () -> {
        });
        assertThat(checkpointStore.getAllCheckpoints(), Matchers.contains(checkpoint1));
        final CompletedCheckpointStoreTest.TestCompletedCheckpoint checkpoint2 = CompletedCheckpointStoreTest.createCheckpoint(1, sharedStateRegistry);
        checkpointStore.addCheckpointAndSubsumeOldestOne(checkpoint2, new CheckpointsCleaner(), () -> {
        });
        final List<CompletedCheckpoint> allCheckpoints = checkpointStore.getAllCheckpoints();
        assertThat(allCheckpoints, Matchers.contains(checkpoint2));
        assertThat(allCheckpoints, Matchers.not(Matchers.contains(checkpoint1)));
        // verify that the subsumed checkpoint is discarded
        CompletedCheckpointStoreTest.verifyCheckpointDiscarded(checkpoint1);
    } finally {
        curatorFrameworkWrapper.close();
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 15 with SharedStateRegistry

use of org.apache.flink.runtime.state.SharedStateRegistry in project flink by apache.

the class StandaloneCompletedCheckpointStoreTest method testSuspendDiscardsCheckpoints.

/**
 * Tests that suspends discards all checkpoints (as they cannot be recovered later in standalone
 * recovery mode).
 */
@Test
public void testSuspendDiscardsCheckpoints() throws Exception {
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    CompletedCheckpointStore store = createRecoveredCompletedCheckpointStore(1);
    TestCompletedCheckpoint checkpoint = createCheckpoint(0, sharedStateRegistry);
    Collection<OperatorState> taskStates = checkpoint.getOperatorStates().values();
    store.addCheckpointAndSubsumeOldestOne(checkpoint, new CheckpointsCleaner(), () -> {
    });
    assertEquals(1, store.getNumberOfRetainedCheckpoints());
    verifyCheckpointRegistered(taskStates, sharedStateRegistry);
    store.shutdown(JobStatus.SUSPENDED, new CheckpointsCleaner());
    assertEquals(0, store.getNumberOfRetainedCheckpoints());
    assertTrue(checkpoint.isDiscarded());
    verifyCheckpointDiscarded(taskStates);
}
Also used : SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Aggregations

SharedStateRegistry (org.apache.flink.runtime.state.SharedStateRegistry)22 SharedStateRegistryImpl (org.apache.flink.runtime.state.SharedStateRegistryImpl)19 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)5 JobID (org.apache.flink.api.common.JobID)3 Configuration (org.apache.flink.configuration.Configuration)3 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)3 IncrementalRemoteKeyedStateHandle (org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle)3 StateHandleID (org.apache.flink.runtime.state.StateHandleID)3 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)3 TestCompletedCheckpointStorageLocation (org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)2 CheckpointCoordinatorBuilder (org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder)2 CheckpointRequestDeciderTest.regularCheckpoint (org.apache.flink.runtime.checkpoint.CheckpointRequestDeciderTest.regularCheckpoint)2 ExecutionGraph (org.apache.flink.runtime.executiongraph.ExecutionGraph)2