You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2025/07/22 09:25:34 UTC

(iotdb) branch pipe-enhance-create-link created (now 4f96ca5b625)

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

rong pushed a change to branch pipe-enhance-create-link
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 4f96ca5b625 Pipe: Handle existing hardlink in createHardLink method

This branch includes the following new commits:

     new 4f96ca5b625 Pipe: Handle existing hardlink in createHardLink method

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(iotdb) 01/01: Pipe: Handle existing hardlink in createHardLink method

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch pipe-enhance-create-link
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 4f96ca5b62595f5d10f80f90b12b238ce27cc398
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Tue Jul 22 17:25:26 2025 +0800

    Pipe: Handle existing hardlink in createHardLink method
    
    Adds logic to check if a hardlink already exists when creating a hardlink. If the existing file matches the source (by MD5), a warning is logged and creation is skipped. If not, the existing file is deleted and creation is retried, with error handling and logging for failures.
---
 .../org/apache/iotdb/commons/utils/FileUtils.java  | 30 +++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
index ea023b1487e..f1c0410dd56 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
@@ -35,6 +35,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.DirectoryNotEmptyException;
+import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.NoSuchFileException;
@@ -347,7 +348,34 @@ public class FileUtils {
 
     final Path sourcePath = FileSystems.getDefault().getPath(sourceFile.getAbsolutePath());
     final Path linkPath = FileSystems.getDefault().getPath(hardlink.getAbsolutePath());
-    Files.createLink(linkPath, sourcePath);
+    try {
+      Files.createLink(linkPath, sourcePath);
+    } catch (final FileAlreadyExistsException fileAlreadyExistsException) {
+      if (haveSameMD5(sourceFile, hardlink)) {
+        LOGGER.warn(
+            "Hardlink {} already exists, will not create it again. Source file: {}",
+            hardlink.getAbsolutePath(),
+            sourceFile.getAbsolutePath());
+      } else {
+        LOGGER.warn(
+            "Hardlink {} already exists but does not match source file {}, will try create it again.",
+            hardlink.getAbsolutePath(),
+            sourceFile.getAbsolutePath());
+        deleteFileIfExist(hardlink);
+        try {
+          Files.createLink(linkPath, sourcePath);
+        } catch (final Exception e) {
+          deleteFileIfExist(linkPath.toFile());
+          LOGGER.error(
+              "Failed to create hardlink {} for file {}: {}",
+              hardlink.getAbsolutePath(),
+              sourceFile.getAbsolutePath(),
+              e.getMessage(),
+              e);
+          throw e;
+        }
+      }
+    }
     return hardlink;
   }