Search in sources :

Example 1 with SharedStateRegistryImpl

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

the class DefaultCompletedCheckpointStoreTest method testShutdownFailsAnyFutureCallsToAddCheckpoint.

@Test
public void testShutdownFailsAnyFutureCallsToAddCheckpoint() throws Exception {
    final CheckpointsCleaner checkpointsCleaner = new CheckpointsCleaner();
    for (JobStatus status : JobStatus.values()) {
        final CompletedCheckpointStore completedCheckpointStore = createCompletedCheckpointStore(builder.build());
        completedCheckpointStore.shutdown(status, checkpointsCleaner);
        assertThrows(IllegalStateException.class, () -> completedCheckpointStore.addCheckpointAndSubsumeOldestOne(CompletedCheckpointStoreTest.createCheckpoint(0L, new SharedStateRegistryImpl()), checkpointsCleaner, () -> {
        // No-op.
        }));
    }
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) Test(org.junit.Test)

Example 2 with SharedStateRegistryImpl

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

the class CompletedCheckpointStoreTest method testGetAllCheckpoints.

/**
 * Tests that all added checkpoints are returned.
 */
@Test
public void testGetAllCheckpoints() throws Exception {
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    CompletedCheckpointStore checkpoints = createRecoveredCompletedCheckpointStore(4);
    TestCompletedCheckpoint[] expected = new TestCompletedCheckpoint[] { createCheckpoint(0, sharedStateRegistry), createCheckpoint(1, sharedStateRegistry), createCheckpoint(2, sharedStateRegistry), createCheckpoint(3, sharedStateRegistry) };
    for (TestCompletedCheckpoint checkpoint : expected) {
        checkpoints.addCheckpointAndSubsumeOldestOne(checkpoint, new CheckpointsCleaner(), () -> {
        });
    }
    List<CompletedCheckpoint> actual = checkpoints.getAllCheckpoints();
    assertEquals(expected.length, actual.size());
    for (int i = 0; i < expected.length; i++) {
        assertEquals(expected[i], actual.get(i));
    }
}
Also used : SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 3 with SharedStateRegistryImpl

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

the class CompletedCheckpointStoreTest method testDiscardAllCheckpoints.

/**
 * Tests that all checkpoints are discarded (using the correct class loader).
 */
@Test
public void testDiscardAllCheckpoints() throws Exception {
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    CompletedCheckpointStore checkpoints = createRecoveredCompletedCheckpointStore(4);
    TestCompletedCheckpoint[] expected = new TestCompletedCheckpoint[] { createCheckpoint(0, sharedStateRegistry), createCheckpoint(1, sharedStateRegistry), createCheckpoint(2, sharedStateRegistry), createCheckpoint(3, sharedStateRegistry) };
    for (TestCompletedCheckpoint checkpoint : expected) {
        checkpoints.addCheckpointAndSubsumeOldestOne(checkpoint, new CheckpointsCleaner(), () -> {
        });
    }
    checkpoints.shutdown(JobStatus.FINISHED, new CheckpointsCleaner());
    // Empty state
    assertNull(checkpoints.getLatestCheckpoint());
    assertEquals(0, checkpoints.getAllCheckpoints().size());
    assertEquals(0, checkpoints.getNumberOfRetainedCheckpoints());
    // All have been discarded
    for (TestCompletedCheckpoint checkpoint : expected) {
        // The ZooKeeper implementation discards asynchronously
        checkpoint.awaitDiscard();
        assertTrue(checkpoint.isDiscarded());
    }
}
Also used : SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 4 with SharedStateRegistryImpl

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

the class ZooKeeperCompletedCheckpointStoreTest method testDiscardingCheckpointsAtShutDown.

/**
 * Tests that checkpoints are discarded when the completed checkpoint store is shut down with a
 * globally terminal state.
 */
@Test
public void testDiscardingCheckpointsAtShutDown() 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));
        checkpointStore.shutdown(JobStatus.FINISHED, new CheckpointsCleaner());
        // verify that the 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 5 with SharedStateRegistryImpl

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

the class ZooKeeperCompletedCheckpointStoreITCase method testRecover.

// ---------------------------------------------------------------------------------------------
/**
 * Tests that older checkpoints are not cleaned up right away when recovering. Only after
 * another checkpoint has been completed the old checkpoints exceeding the number of checkpoints
 * to retain will be removed.
 */
@Test
public void testRecover() throws Exception {
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    CompletedCheckpointStore checkpoints = createRecoveredCompletedCheckpointStore(3);
    TestCompletedCheckpoint[] expected = new TestCompletedCheckpoint[] { createCheckpoint(0, sharedStateRegistry), createCheckpoint(1, sharedStateRegistry), createCheckpoint(2, sharedStateRegistry) };
    // Add multiple checkpoints
    checkpoints.addCheckpointAndSubsumeOldestOne(expected[0], new CheckpointsCleaner(), () -> {
    });
    checkpoints.addCheckpointAndSubsumeOldestOne(expected[1], new CheckpointsCleaner(), () -> {
    });
    checkpoints.addCheckpointAndSubsumeOldestOne(expected[2], new CheckpointsCleaner(), () -> {
    });
    verifyCheckpointRegistered(expected[0].getOperatorStates().values(), sharedStateRegistry);
    verifyCheckpointRegistered(expected[1].getOperatorStates().values(), sharedStateRegistry);
    verifyCheckpointRegistered(expected[2].getOperatorStates().values(), sharedStateRegistry);
    // All three should be in ZK
    assertEquals(3, ZOOKEEPER.getClient().getChildren().forPath(CHECKPOINT_PATH).size());
    assertEquals(3, checkpoints.getNumberOfRetainedCheckpoints());
    // Recover
    sharedStateRegistry.close();
    sharedStateRegistry = new SharedStateRegistryImpl();
    assertEquals(3, ZOOKEEPER.getClient().getChildren().forPath(CHECKPOINT_PATH).size());
    assertEquals(3, checkpoints.getNumberOfRetainedCheckpoints());
    assertEquals(expected[2], checkpoints.getLatestCheckpoint());
    List<CompletedCheckpoint> expectedCheckpoints = new ArrayList<>(3);
    expectedCheckpoints.add(expected[1]);
    expectedCheckpoints.add(expected[2]);
    expectedCheckpoints.add(createCheckpoint(3, sharedStateRegistry));
    checkpoints.addCheckpointAndSubsumeOldestOne(expectedCheckpoints.get(2), new CheckpointsCleaner(), () -> {
    });
    List<CompletedCheckpoint> actualCheckpoints = checkpoints.getAllCheckpoints();
    assertEquals(expectedCheckpoints, actualCheckpoints);
    for (CompletedCheckpoint actualCheckpoint : actualCheckpoints) {
        verifyCheckpointRegistered(actualCheckpoint.getOperatorStates().values(), sharedStateRegistry);
    }
}
Also used : SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) ArrayList(java.util.ArrayList) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Aggregations

SharedStateRegistryImpl (org.apache.flink.runtime.state.SharedStateRegistryImpl)23 SharedStateRegistry (org.apache.flink.runtime.state.SharedStateRegistry)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)6 CompletableFuture (java.util.concurrent.CompletableFuture)4 JobID (org.apache.flink.api.common.JobID)4 TestCompletedCheckpointStorageLocation (org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation)4 HashMap (java.util.HashMap)3 JobStatus (org.apache.flink.api.common.JobStatus)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)3 IOException (java.io.IOException)2 Arrays.asList (java.util.Arrays.asList)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 TimeUnit (java.util.concurrent.TimeUnit)2 TimeoutException (java.util.concurrent.TimeoutException)2