Search in sources :

Example 1 with CheckpointListener

use of org.apache.flink.api.common.state.CheckpointListener in project flink by apache.

the class EmbeddedRocksDBStateBackendTest method testSharedIncrementalStateDeRegistration.

@Test
public void testSharedIncrementalStateDeRegistration() throws Exception {
    if (enableIncrementalCheckpointing) {
        CheckpointableKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
        try {
            ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class, null);
            kvId.initializeSerializerUnlessSet(new ExecutionConfig());
            ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
            Queue<IncrementalRemoteKeyedStateHandle> previousStateHandles = new LinkedList<>();
            SharedStateRegistry sharedStateRegistry = spy(new SharedStateRegistryImpl());
            for (int checkpointId = 0; checkpointId < 3; ++checkpointId) {
                reset(sharedStateRegistry);
                backend.setCurrentKey(checkpointId);
                state.update("Hello-" + checkpointId);
                RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot = backend.snapshot(checkpointId, checkpointId, createStreamFactory(), CheckpointOptions.forCheckpointWithDefaultLocation());
                snapshot.run();
                SnapshotResult<KeyedStateHandle> snapshotResult = snapshot.get();
                IncrementalRemoteKeyedStateHandle stateHandle = (IncrementalRemoteKeyedStateHandle) snapshotResult.getJobManagerOwnedSnapshot();
                Map<StateHandleID, StreamStateHandle> sharedState = new HashMap<>(stateHandle.getSharedState());
                stateHandle.registerSharedStates(sharedStateRegistry, checkpointId);
                for (Map.Entry<StateHandleID, StreamStateHandle> e : sharedState.entrySet()) {
                    verify(sharedStateRegistry).registerReference(stateHandle.createSharedStateRegistryKeyFromFileName(e.getKey()), e.getValue(), checkpointId);
                }
                previousStateHandles.add(stateHandle);
                ((CheckpointListener) backend).notifyCheckpointComplete(checkpointId);
                if (previousStateHandles.size() > 1) {
                    previousStateHandles.remove().discardState();
                }
            }
            while (!previousStateHandles.isEmpty()) {
                reset(sharedStateRegistry);
                previousStateHandles.remove().discardState();
            }
        } finally {
            IOUtils.closeQuietly(backend);
            backend.dispose();
        }
    }
}
Also used : SnapshotResult(org.apache.flink.runtime.state.SnapshotResult) HashMap(java.util.HashMap) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) LinkedList(java.util.LinkedList) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) StateHandleID(org.apache.flink.runtime.state.StateHandleID) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 CheckpointListener (org.apache.flink.api.common.state.CheckpointListener)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 IncrementalRemoteKeyedStateHandle (org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle)1 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)1 SharedStateRegistry (org.apache.flink.runtime.state.SharedStateRegistry)1 SharedStateRegistryImpl (org.apache.flink.runtime.state.SharedStateRegistryImpl)1 SnapshotResult (org.apache.flink.runtime.state.SnapshotResult)1 StateHandleID (org.apache.flink.runtime.state.StateHandleID)1 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)1 Test (org.junit.Test)1