1996fanrui commented on code in PR #21855:
URL: https://github.com/apache/flink/pull/21855#discussion_r1097075422


##########
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:
   Thanks for your quick feedback, I will fix this bug by set `threadNum=1`.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to