Search in sources :

Example 6 with StateHandleID

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

the class RocksDBStateDownloaderTest method testMultiThreadRestoreThreadPoolExceptionRethrow.

/**
 * Test that the exception arose in the thread pool will rethrow to the main thread.
 */
@Test
public void testMultiThreadRestoreThreadPoolExceptionRethrow() {
    SpecifiedException expectedException = new SpecifiedException("throw exception while multi thread restore.");
    StreamStateHandle stateHandle = new ThrowingStateHandle(expectedException);
    Map<StateHandleID, StreamStateHandle> stateHandles = new HashMap<>(1);
    stateHandles.put(new StateHandleID("state1"), stateHandle);
    IncrementalRemoteKeyedStateHandle incrementalKeyedStateHandle = new IncrementalRemoteKeyedStateHandle(UUID.randomUUID(), KeyGroupRange.EMPTY_KEY_GROUP_RANGE, 1, stateHandles, stateHandles, stateHandle);
    try (RocksDBStateDownloader rocksDBStateDownloader = new RocksDBStateDownloader(5)) {
        rocksDBStateDownloader.transferAllStateDataToDirectory(incrementalKeyedStateHandle, temporaryFolder.newFolder().toPath(), new CloseableRegistry());
        fail();
    } catch (Exception e) {
        assertEquals(expectedException, e);
    }
}
Also used : StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) HashMap(java.util.HashMap) StateHandleID(org.apache.flink.runtime.state.StateHandleID) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with StateHandleID

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

the class RocksDBStateUploaderTest method testMultiThreadUploadThreadPoolExceptionRethrow.

/**
 * Test that the exception arose in the thread pool will rethrow to the main thread.
 */
@Test
public void testMultiThreadUploadThreadPoolExceptionRethrow() throws IOException {
    SpecifiedException expectedException = new SpecifiedException("throw exception while multi thread upload states.");
    CheckpointStateOutputStream outputStream = createFailingCheckpointStateOutputStream(expectedException);
    CheckpointStreamFactory checkpointStreamFactory = new CheckpointStreamFactory() {

        @Override
        public CheckpointStateOutputStream createCheckpointStateOutputStream(CheckpointedStateScope scope) throws IOException {
            return outputStream;
        }

        @Override
        public boolean canFastDuplicate(StreamStateHandle stateHandle, CheckpointedStateScope scope) throws IOException {
            return false;
        }

        @Override
        public List<StreamStateHandle> duplicate(List<StreamStateHandle> stateHandles, CheckpointedStateScope scope) throws IOException {
            return null;
        }
    };
    File file = temporaryFolder.newFile(String.valueOf(UUID.randomUUID()));
    generateRandomFileContent(file.getPath(), 20);
    Map<StateHandleID, Path> filePaths = new HashMap<>(1);
    filePaths.put(new StateHandleID("mockHandleID"), file.toPath());
    try (RocksDBStateUploader rocksDBStateUploader = new RocksDBStateUploader(5)) {
        rocksDBStateUploader.uploadFilesToCheckpointFs(filePaths, checkpointStreamFactory, CheckpointedStateScope.SHARED, new CloseableRegistry());
        fail();
    } catch (Exception e) {
        assertEquals(expectedException, e);
    }
}
Also used : Path(java.nio.file.Path) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) HashMap(java.util.HashMap) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) IOException(java.io.IOException) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) StateHandleID(org.apache.flink.runtime.state.StateHandleID) CheckpointStateOutputStream(org.apache.flink.runtime.state.CheckpointStateOutputStream) List(java.util.List) CheckpointedStateScope(org.apache.flink.runtime.state.CheckpointedStateScope) File(java.io.File) Test(org.junit.Test)

Example 8 with StateHandleID

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

the class SchedulerUtilsTest method buildIncrementalHandle.

private IncrementalRemoteKeyedStateHandle buildIncrementalHandle(StateHandleID key, StreamStateHandle shared, UUID backendIdentifier) {
    StreamStateHandle meta = new ByteStreamStateHandle("meta", new byte[] { 1, 2, 3 });
    Map<StateHandleID, StreamStateHandle> sharedStateMap = new HashMap<>();
    sharedStateMap.put(key, shared);
    return new IncrementalRemoteKeyedStateHandle(backendIdentifier, KeyGroupRange.EMPTY_KEY_GROUP_RANGE, 1, sharedStateMap, emptyMap(), meta);
}
Also used : StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) PlaceholderStreamStateHandle(org.apache.flink.runtime.state.PlaceholderStreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) HashMap(java.util.HashMap) StateHandleID(org.apache.flink.runtime.state.StateHandleID) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle)

Example 9 with StateHandleID

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

the class SchedulerUtilsTest method testSharedStateRegistration.

/**
 * Check that a {@link SharedStateRegistryFactory} used by {@link SchedulerUtils} registers
 * shared checkpoint state on restore.
 */
@Test
public void testSharedStateRegistration() throws Exception {
    UUID backendId = UUID.randomUUID();
    StateHandleID key = new StateHandleID("k0");
    StreamStateHandle handle = new ByteStreamStateHandle("h0", new byte[] { 1, 2, 3 });
    CheckpointRecoveryFactory recoveryFactory = buildRecoveryFactory(buildCheckpoint(buildIncrementalHandle(key, handle, backendId)));
    CompletedCheckpointStore checkpointStore = SchedulerUtils.createCompletedCheckpointStore(new Configuration(), recoveryFactory, Executors.directExecutor(), log, new JobID());
    SharedStateRegistry sharedStateRegistry = checkpointStore.getSharedStateRegistry();
    IncrementalRemoteKeyedStateHandle newHandle = buildIncrementalHandle(key, new PlaceholderStreamStateHandle(1L), backendId);
    newHandle.registerSharedStates(sharedStateRegistry, 1L);
    assertSame(handle, newHandle.getSharedState().get(key));
}
Also used : PlaceholderStreamStateHandle(org.apache.flink.runtime.state.PlaceholderStreamStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) PlaceholderStreamStateHandle(org.apache.flink.runtime.state.PlaceholderStreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) Configuration(org.apache.flink.configuration.Configuration) StateHandleID(org.apache.flink.runtime.state.StateHandleID) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) UUID(java.util.UUID) CheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory) StandaloneCheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.StandaloneCheckpointRecoveryFactory) JobID(org.apache.flink.api.common.JobID) CompletedCheckpointStore(org.apache.flink.runtime.checkpoint.CompletedCheckpointStore) EmbeddedCompletedCheckpointStore(org.apache.flink.runtime.checkpoint.EmbeddedCompletedCheckpointStore) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 10 with StateHandleID

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

the class MetadataV2V3SerializerBase method deserializeIncrementalStateHandle.

private static IncrementalRemoteKeyedStateHandle deserializeIncrementalStateHandle(DataInputStream dis, @Nullable DeserializationContext context, int stateHandleType) throws IOException {
    boolean isV2Format = INCREMENTAL_KEY_GROUPS_HANDLE_V2 == stateHandleType;
    long checkpointId = dis.readLong();
    String backendId = dis.readUTF();
    int startKeyGroup = dis.readInt();
    int numKeyGroups = dis.readInt();
    long checkpointedSize = isV2Format ? dis.readLong() : UNKNOWN_CHECKPOINTED_SIZE;
    KeyGroupRange keyGroupRange = KeyGroupRange.of(startKeyGroup, startKeyGroup + numKeyGroups - 1);
    StreamStateHandle metaDataStateHandle = deserializeStreamStateHandle(dis, context);
    Map<StateHandleID, StreamStateHandle> sharedStates = deserializeStreamStateHandleMap(dis, context);
    Map<StateHandleID, StreamStateHandle> privateStates = deserializeStreamStateHandleMap(dis, context);
    UUID uuid;
    try {
        uuid = UUID.fromString(backendId);
    } catch (Exception ex) {
        // compatibility with old format pre FLINK-6964:
        uuid = UUID.nameUUIDFromBytes(backendId.getBytes(StandardCharsets.UTF_8));
    }
    StateHandleID stateHandleId = isV2Format ? new StateHandleID(dis.readUTF()) : StateHandleID.randomStateHandleId();
    return IncrementalRemoteKeyedStateHandle.restore(uuid, keyGroupRange, checkpointId, sharedStates, privateStates, metaDataStateHandle, checkpointedSize, stateHandleId);
}
Also used : OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) StateHandleID(org.apache.flink.runtime.state.StateHandleID) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) UUID(java.util.UUID) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) IOException(java.io.IOException) BiFunctionWithException(org.apache.flink.util.function.BiFunctionWithException)

Aggregations

StateHandleID (org.apache.flink.runtime.state.StateHandleID)19 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)18 HashMap (java.util.HashMap)14 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)14 IncrementalRemoteKeyedStateHandle (org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle)10 OperatorStreamStateHandle (org.apache.flink.runtime.state.OperatorStreamStateHandle)8 Test (org.junit.Test)8 Map (java.util.Map)7 PlaceholderStreamStateHandle (org.apache.flink.runtime.state.PlaceholderStreamStateHandle)7 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)5 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)5 File (java.io.File)4 UUID (java.util.UUID)4 AcknowledgeCheckpoint (org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint)4 TestingStreamStateHandle (org.apache.flink.runtime.state.TestingStreamStateHandle)4 DeclineCheckpoint (org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint)3 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)3