tillrohrmann commented on a change in pull request #7320: [FLINK-11171] Avoid
concurrent usage of StateSnapshotTransformer
URL: https://github.com/apache/flink/pull/7320#discussion_r247968937
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/state/StateBackendTestBase.java
##########
@@ -3902,6 +3906,84 @@ public void testParallelAsyncSnapshots() throws
Exception {
}
}
+ @Test
+ public void testNonConcurrentSnapshotTransformerAccess() throws
Exception {
+ Random rnd = new Random();
+ BlockerCheckpointStreamFactory streamFactory = new
BlockerCheckpointStreamFactory(1024 * 1024);
+ AbstractKeyedStateBackend<Integer> backend = null;
+ try {
+ backend = createKeyedBackend(IntSerializer.INSTANCE);
+ InternalValueState<Integer, VoidNamespace, String>
valueState = backend.createInternalState(
+ VoidNamespaceSerializer.INSTANCE,
+ new ValueStateDescriptor<>("test",
StringSerializer.INSTANCE),
+
createSingleThreadAccessCheckingStateSnapshotTransformFactory());
+
+ valueState.setCurrentNamespace(VoidNamespace.INSTANCE);
+
+ for (int i = 0; i < 100; i++) {
+ backend.setCurrentKey(i);
+
valueState.update(StringUtils.getRandomString(rnd,5, 10));
+ }
+
+ CheckpointOptions checkpointOptions =
CheckpointOptions.forCheckpointWithDefaultLocation();
+
+ RunnableFuture<SnapshotResult<KeyedStateHandle>>
snapshot1 =
+ backend.snapshot(1L, 0L, streamFactory,
checkpointOptions);
+
+ RunnableFuture<SnapshotResult<KeyedStateHandle>>
snapshot2 =
+ backend.snapshot(2L, 0L, streamFactory,
checkpointOptions);
+
+ Thread runner1 = new Thread(snapshot1, "snapshot1");
+ runner1.start();
+ Thread runner2 = new Thread(snapshot2, "snapshot2");
+ runner2.start();
+
+ runner1.join();
+ runner2.join();
+
+ snapshot1.get();
+ snapshot2.get();
+ } finally {
+ if (backend != null) {
+ IOUtils.closeQuietly(backend);
+ backend.dispose();
+ }
+ }
+ }
+
+ private static <T> StateSnapshotTransformFactory<T>
+ createSingleThreadAccessCheckingStateSnapshotTransformFactory() {
+ return new StateSnapshotTransformFactory<T>() {
+ @Override
+ public Optional<StateSnapshotTransformer<T>>
createForDeserializedState() {
+ return createStateSnapshotTransformer();
+ }
+
+ @Override
+ public Optional<StateSnapshotTransformer<byte[]>>
createForSerializedState() {
+ return createStateSnapshotTransformer();
+ }
+
+ private <T1> Optional<StateSnapshotTransformer<T1>>
createStateSnapshotTransformer() {
+ return Optional.of(new
StateSnapshotTransformer<T1>() {
+ private Thread currentThread = null;
+
+ @Nullable
+ @Override
+ public T1 filterOrTransform(@Nullable
T1 value) {
+ if (currentThread == null) {
+ currentThread =
Thread.currentThread();
+ } else {
+
assertEquals("Concurrent access from another thread",
+ currentThread,
Thread.currentThread());
+ }
Review comment:
The current implementation assumes that there is only a single element to
transform, right? Otherwise it should fail with the second element.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services