Search in sources :

Example 11 with SharedStateRegistryImpl

use of org.apache.flink.runtime.state.SharedStateRegistryImpl 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 12 with SharedStateRegistryImpl

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

the class DefaultCompletedCheckpointStoreTest method createStateHandles.

private List<Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String>> createStateHandles(int num) {
    final List<Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String>> stateHandles = new ArrayList<>();
    for (int i = 1; i <= num; i++) {
        final CompletedCheckpointStoreTest.TestCompletedCheckpoint completedCheckpoint = CompletedCheckpointStoreTest.createCheckpoint(i, new SharedStateRegistryImpl());
        final RetrievableStateHandle<CompletedCheckpoint> checkpointStateHandle = checkpointStorageHelper.store(completedCheckpoint);
        stateHandles.add(new Tuple2<>(checkpointStateHandle, String.valueOf(i)));
    }
    return stateHandles;
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) ArrayList(java.util.ArrayList) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl)

Example 13 with SharedStateRegistryImpl

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

the class DefaultCompletedCheckpointStoreTest method testAddCheckpointFailedShouldNotRemoveOldOnes.

@Test
public void testAddCheckpointFailedShouldNotRemoveOldOnes() throws Exception {
    final int num = 1;
    final String errMsg = "Add to state handle failed.";
    final TestingStateHandleStore<CompletedCheckpoint> stateHandleStore = builder.setGetAllSupplier(() -> createStateHandles(num)).setAddFunction((ignore, ckp) -> {
        throw new FlinkException(errMsg);
    }).build();
    final CompletedCheckpointStore completedCheckpointStore = createCompletedCheckpointStore(stateHandleStore);
    assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
    assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(1L));
    final long ckpId = 100L;
    final CompletedCheckpoint ckp = CompletedCheckpointStoreTest.createCheckpoint(ckpId, new SharedStateRegistryImpl());
    try {
        completedCheckpointStore.addCheckpointAndSubsumeOldestOne(ckp, new CheckpointsCleaner(), () -> {
        });
        fail("We should get an exception when add checkpoint to failed..");
    } catch (FlinkException ex) {
        assertThat(ex, FlinkMatchers.containsMessage(errMsg));
    }
    // Check the old checkpoint still exists.
    assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
    assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(1L));
}
Also used : FlinkException(org.apache.flink.util.FlinkException) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Assert.assertThrows(org.junit.Assert.assertThrows) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) NEVER_RETAIN_AFTER_TERMINATION(org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) TestingRetrievableStateStorageHelper(org.apache.flink.runtime.persistence.TestingRetrievableStateStorageHelper) SharedStateRegistryKey(org.apache.flink.runtime.state.SharedStateRegistryKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) Assert.fail(org.junit.Assert.fail) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) Collections.emptyList(java.util.Collections.emptyList) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) JobID(org.apache.flink.api.common.JobID) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TestingStateHandleStore(org.apache.flink.runtime.persistence.TestingStateHandleStore) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 14 with SharedStateRegistryImpl

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

the class DefaultCompletedCheckpointStoreTest method testAddCheckpointSuccessfullyShouldRemoveOldOnes.

@Test
public void testAddCheckpointSuccessfullyShouldRemoveOldOnes() throws Exception {
    final int num = 1;
    final CompletableFuture<CompletedCheckpoint> addFuture = new CompletableFuture<>();
    final TestingStateHandleStore<CompletedCheckpoint> stateHandleStore = builder.setGetAllSupplier(() -> createStateHandles(num)).setAddFunction((ignore, ckp) -> {
        addFuture.complete(ckp);
        return null;
    }).build();
    final CompletedCheckpointStore completedCheckpointStore = createCompletedCheckpointStore(stateHandleStore);
    assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
    assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(1L));
    final long ckpId = 100L;
    final CompletedCheckpoint ckp = CompletedCheckpointStoreTest.createCheckpoint(ckpId, new SharedStateRegistryImpl());
    completedCheckpointStore.addCheckpointAndSubsumeOldestOne(ckp, new CheckpointsCleaner(), () -> {
    });
    // We should persist the completed checkpoint to state handle store.
    final CompletedCheckpoint addedCkp = addFuture.get(timeout, TimeUnit.MILLISECONDS);
    assertThat(addedCkp.getCheckpointID(), is(ckpId));
    // Check the old checkpoint is removed and new one is added.
    assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
    assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(ckpId));
}
Also used : FlinkException(org.apache.flink.util.FlinkException) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Assert.assertThrows(org.junit.Assert.assertThrows) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) NEVER_RETAIN_AFTER_TERMINATION(org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) TestingRetrievableStateStorageHelper(org.apache.flink.runtime.persistence.TestingRetrievableStateStorageHelper) SharedStateRegistryKey(org.apache.flink.runtime.state.SharedStateRegistryKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) Assert.fail(org.junit.Assert.fail) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) Collections.emptyList(java.util.Collections.emptyList) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) JobID(org.apache.flink.api.common.JobID) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TestingStateHandleStore(org.apache.flink.runtime.persistence.TestingStateHandleStore) CompletableFuture(java.util.concurrent.CompletableFuture) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) Test(org.junit.Test)

Example 15 with SharedStateRegistryImpl

use of org.apache.flink.runtime.state.SharedStateRegistryImpl 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)

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