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());
}
}
}
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));
}
}
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());
}
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));
}
Aggregations