This is an automated email from the ASF dual-hosted git repository.

pwason pushed a commit to branch release-0.14.0
in repository https://gitbox.apache.org/repos/asf/hudi.git

commit 0ea1f1b68cbc16138637460f1557de2b9cf6c360
Author: Bingeng Huang <[email protected]>
AuthorDate: Mon Aug 21 19:40:11 2023 +0800

    [HUDI-6156] Prevent leaving tmp file in timeline, delete tmp file when 
rename throw exception (#9483)
    
    Co-authored-by: hbg <[email protected]>
---
 .../org/apache/hudi/common/fs/HoodieWrapperFileSystem.java | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git 
a/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java
 
b/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java
index ecba8eff8b5..0789ef4e27f 100644
--- 
a/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java
+++ 
b/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java
@@ -1051,16 +1051,22 @@ public class HoodieWrapperFileSystem extends FileSystem 
{
         throw new HoodieIOException(errorMsg, e);
       }
 
+      boolean renameSuccess = false;
       try {
         if (null != tmpPath) {
-          boolean renameSuccess = fileSystem.rename(tmpPath, fullPath);
-          if (!renameSuccess) {
+          renameSuccess = fileSystem.rename(tmpPath, fullPath);
+        }
+      } catch (IOException e) {
+        throw new HoodieIOException("Failed to rename " + tmpPath + " to the 
target " + fullPath, e);
+      } finally {
+        if (!renameSuccess && null != tmpPath) {
+          try {
             fileSystem.delete(tmpPath, false);
             LOG.warn("Fail to rename " + tmpPath + " to " + fullPath + ", 
target file exists: " + fileSystem.exists(fullPath));
+          } catch (IOException e) {
+            throw new HoodieIOException("Failed to delete tmp file " + 
tmpPath, e);
           }
         }
-      } catch (IOException e) {
-        throw new HoodieIOException("Failed to rename " + tmpPath + " to the 
target " + fullPath, e);
       }
     }
   }

Reply via email to