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_r247966443
 
 

 ##########
 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() {
 
 Review comment:
   This is only my personal taste, but I like it more if the return type and 
the function name is on the same line.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to