Search in sources :

Example 1 with ChangelogStateBackendHandleImpl

use of org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl in project flink by apache.

the class MetadataV3SerializerTest method testSerializeChangelogStateBackendHandle.

private void testSerializeChangelogStateBackendHandle(boolean fullSnapshot) throws IOException {
    ChangelogStateBackendHandle handle = createChangelogStateBackendHandle(fullSnapshot);
    try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
        MetadataV2V3SerializerBase.serializeKeyedStateHandle(handle, new DataOutputStream(out));
        try (ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())) {
            KeyedStateHandle deserialized = MetadataV2V3SerializerBase.deserializeKeyedStateHandle(new DataInputStream(in), null);
            assertTrue(deserialized instanceof ChangelogStateBackendHandleImpl);
            assertEquals(((ChangelogStateBackendHandleImpl) deserialized).getMaterializedStateHandles(), handle.getMaterializedStateHandles());
        }
    }
}
Also used : ChangelogStateBackendHandle(org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) DataInputStream(java.io.DataInputStream) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) ChangelogStateBackendHandleImpl(org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl) ByteArrayOutputStreamWithPos(org.apache.flink.core.memory.ByteArrayOutputStreamWithPos)

Example 2 with ChangelogStateBackendHandleImpl

use of org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl in project flink by apache.

the class ChangelogKeyedStateBackend method buildSnapshotResult.

private SnapshotResult<KeyedStateHandle> buildSnapshotResult(ChangelogStateHandle delta, ChangelogSnapshotState changelogStateBackendStateCopy) {
    // collections don't change once started and handles are immutable
    List<ChangelogStateHandle> prevDeltaCopy = new ArrayList<>(changelogStateBackendStateCopy.getRestoredNonMaterialized());
    long persistedSizeOfThisCheckpoint = 0L;
    if (delta != null && delta.getStateSize() > 0) {
        prevDeltaCopy.add(delta);
        persistedSizeOfThisCheckpoint += delta.getCheckpointedSize();
    }
    if (prevDeltaCopy.isEmpty() && changelogStateBackendStateCopy.getMaterializedSnapshot().isEmpty()) {
        return SnapshotResult.empty();
    } else {
        return SnapshotResult.of(new ChangelogStateBackendHandleImpl(changelogStateBackendStateCopy.getMaterializedSnapshot(), prevDeltaCopy, getKeyGroupRange(), changelogStateBackendStateCopy.materializationID, persistedSizeOfThisCheckpoint));
    }
}
Also used : ChangelogStateHandle(org.apache.flink.runtime.state.changelog.ChangelogStateHandle) ArrayList(java.util.ArrayList) ChangelogStateBackendHandleImpl(org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl)

Example 3 with ChangelogStateBackendHandleImpl

use of org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl in project flink by apache.

the class SharedStateRegistryTest method testRegisterChangelogStateBackendHandles.

@Test
public void testRegisterChangelogStateBackendHandles() throws InterruptedException {
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    long materializationId1 = 1L;
    // the base materialized state on TM side
    ChangelogTestUtils.IncrementalStateHandleWrapper materializedStateBase1 = createDummyIncrementalStateHandle(materializationId1);
    // we deserialize the state handle due to FLINK-25479 to mock on JM side
    IncrementalStateHandleWrapper materializedState1 = materializedStateBase1.deserialize();
    ChangelogStateHandleWrapper nonMaterializedState1 = createDummyChangelogStateHandle(1, 2);
    long materializationId = 1L;
    long checkpointId1 = 41;
    ChangelogStateBackendHandleImpl changelogStateBackendHandle1 = new ChangelogStateBackendHandleImpl(Collections.singletonList(materializedState1), Collections.singletonList(nonMaterializedState1), materializedStateBase1.getKeyGroupRange(), materializationId, nonMaterializedState1.getStateSize());
    changelogStateBackendHandle1.registerSharedStates(sharedStateRegistry, checkpointId1);
    sharedStateRegistry.checkpointCompleted(checkpointId1);
    sharedStateRegistry.unregisterUnusedState(checkpointId1);
    IncrementalStateHandleWrapper materializedState2 = materializedStateBase1.deserialize();
    ChangelogStateHandleWrapper nonMaterializedState2 = createDummyChangelogStateHandle(2, 3);
    long checkpointId2 = 42;
    ChangelogStateBackendHandleImpl changelogStateBackendHandle2 = new ChangelogStateBackendHandleImpl(Collections.singletonList(materializedState2), Collections.singletonList(nonMaterializedState2), materializedStateBase1.getKeyGroupRange(), materializationId, nonMaterializedState2.getStateSize());
    changelogStateBackendHandle2.registerSharedStates(sharedStateRegistry, checkpointId2);
    sharedStateRegistry.checkpointCompleted(checkpointId2);
    sharedStateRegistry.unregisterUnusedState(checkpointId2);
    // the 1st materialized state would not be discarded since the 2nd changelog state backend
    // handle still use it.
    assertFalse(materializedState1.isDiscarded());
    // FLINK-26101, check whether the multi registered state not discarded.
    assertFalse(materializedState2.isDiscarded());
    assertTrue(nonMaterializedState1.isDiscarded());
    long materializationId2 = 2L;
    IncrementalStateHandleWrapper materializedStateBase2 = createDummyIncrementalStateHandle(materializationId2);
    IncrementalStateHandleWrapper materializedState3 = materializedStateBase2.deserialize();
    long checkpointId3 = 43L;
    ChangelogStateBackendHandleImpl changelogStateBackendHandle3 = new ChangelogStateBackendHandleImpl(Collections.singletonList(materializedState3), Collections.singletonList(nonMaterializedState2), materializedState3.getKeyGroupRange(), materializationId2, 0L);
    changelogStateBackendHandle3.registerSharedStates(sharedStateRegistry, checkpointId3);
    sharedStateRegistry.checkpointCompleted(checkpointId3);
    sharedStateRegistry.unregisterUnusedState(checkpointId3);
    // the 1st materialized state would be discarded since we have a newer materialized
    // state registered.
    assertTrue(materializedState1.isDiscarded());
    // the 2nd non-materialized state would not be discarded as 3rd changelog state backend
    // handle still use it.
    assertFalse(nonMaterializedState2.isDiscarded());
}
Also used : ChangelogStateHandleWrapper(org.apache.flink.runtime.state.ChangelogTestUtils.ChangelogStateHandleWrapper) IncrementalStateHandleWrapper(org.apache.flink.runtime.state.ChangelogTestUtils.IncrementalStateHandleWrapper) ChangelogStateBackendHandleImpl(org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl) IncrementalStateHandleWrapper(org.apache.flink.runtime.state.ChangelogTestUtils.IncrementalStateHandleWrapper) Test(org.junit.Test)

Example 4 with ChangelogStateBackendHandleImpl

use of org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl in project flink by apache.

the class ChangelogStateBackendHandleTest method testPublicConstructor.

@Test
public void testPublicConstructor() {
    long materializationID = 1L;
    long size = 2L;
    validateHandle(materializationID, size, new ChangelogStateBackendHandleImpl(emptyList(), emptyList(), KeyGroupRange.of(1, 2), materializationID, size));
}
Also used : ChangelogStateBackendHandleImpl(org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl) Test(org.junit.Test)

Aggregations

ChangelogStateBackendHandleImpl (org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle.ChangelogStateBackendHandleImpl)4 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1 ByteArrayOutputStreamWithPos (org.apache.flink.core.memory.ByteArrayOutputStreamWithPos)1 ChangelogStateHandleWrapper (org.apache.flink.runtime.state.ChangelogTestUtils.ChangelogStateHandleWrapper)1 IncrementalStateHandleWrapper (org.apache.flink.runtime.state.ChangelogTestUtils.IncrementalStateHandleWrapper)1 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)1 ChangelogStateBackendHandle (org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle)1 ChangelogStateHandle (org.apache.flink.runtime.state.changelog.ChangelogStateHandle)1