fredia commented on code in PR #21855:
URL: https://github.com/apache/flink/pull/21855#discussion_r1097051184


##########
flink-state-backends/flink-statebackend-rocksdb/src/test/java/org/apache/flink/contrib/streaming/state/RocksDBStateUploaderTest.java:
##########
@@ -96,13 +100,92 @@ public List<StreamStateHandle> duplicate(
                     filePaths,
                     checkpointStreamFactory,
                     CheckpointedStateScope.SHARED,
+                    new CloseableRegistry(),
                     new CloseableRegistry());
             fail();
         } catch (Exception e) {
             assertEquals(expectedException, e);
         }
     }
 
+    @Test
+    public void testUploadedSstCanBeCleanedUp() throws Exception {
+        SpecifiedException expectedException =
+                new SpecifiedException("throw exception while multi thread 
upload states.");
+
+        File checkpointPrivateFolder = temporaryFolder.newFolder("private");
+        org.apache.flink.core.fs.Path checkpointPrivateDirectory =
+                
org.apache.flink.core.fs.Path.fromLocalFile(checkpointPrivateFolder);
+
+        File checkpointSharedFolder = temporaryFolder.newFolder("shared");
+        org.apache.flink.core.fs.Path checkpointSharedDirectory =
+                
org.apache.flink.core.fs.Path.fromLocalFile(checkpointSharedFolder);
+
+        FileSystem fileSystem = checkpointPrivateDirectory.getFileSystem();
+
+        int sstFileCount = 6;
+        int fileStateSizeThreshold = 1024;
+        int writeBufferSize = 4096;
+        CheckpointStreamFactory checkpointStreamFactory =
+                new FsCheckpointStreamFactory(
+                        fileSystem,
+                        checkpointPrivateDirectory,
+                        checkpointSharedDirectory,
+                        fileStateSizeThreshold,
+                        writeBufferSize);
+
+        String localFolder = "local";
+        temporaryFolder.newFolder(localFolder);
+
+        Map<StateHandleID, Path> filePaths =
+                generateRandomSstFiles(localFolder, sstFileCount, 
fileStateSizeThreshold);
+        CloseableRegistry tmpResourcesRegistry = new CloseableRegistry();
+        try (RocksDBStateUploader rocksDBStateUploader = new 
RocksDBStateUploader(sstFileCount)) {
+            rocksDBStateUploader.uploadFilesToCheckpointFs(
+                    filePaths,
+                    checkpointStreamFactory,
+                    CheckpointedStateScope.SHARED,
+                    new CloseableRegistry(),
+                    tmpResourcesRegistry);
+
+            try {
+                rocksDBStateUploader.uploadFilesToCheckpointFs(
+                        filePaths,
+                        new LastFailingCheckpointStateOutputStreamFactory(
+                                checkpointStreamFactory, sstFileCount, 
expectedException),
+                        CheckpointedStateScope.SHARED,
+                        new CloseableRegistry(),
+                        tmpResourcesRegistry);
+                fail();
+            } catch (Exception e) {
+                assertEquals(expectedException, e);
+            }
+            assertEquals(0, 
checkNotNull(checkpointPrivateFolder.list()).length);
+            assertTrue(checkNotNull(checkpointSharedFolder.list()).length > 0);
+
+            tmpResourcesRegistry.close();
+            // Check whether the temporary file before the exception can be 
cleaned up
+            assertEquals(0, 
checkNotNull(checkpointPrivateFolder.list()).length);
+            assertEquals(0, 
checkNotNull(checkpointSharedFolder.list()).length);

Review Comment:
   Good catch👍,  setting the number of threads of RocksDBStateUploader to 1 is 
a good way, because RocksDBStateDataTransfer would use`DirectExecutorService` 
to directly execute the runnables and the callables in the calling thread when 
threadNum=1.
   
   ~~And I agree with reusing FLINK-30461 to fix the bug too.~~ 
https://issues.apache.org/jira/browse/FLINK-30916 has been created for this 
test, maybe this bug can be fixed under FLINK-30916.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to