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

rong pushed a commit to branch rc/1.3.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rc/1.3.3 by this push:
     new ba3f08e2fea Active Load: Check dir r/w permissions before loading from 
listening dirs (#13488) (#13500)
ba3f08e2fea is described below

commit ba3f08e2fea87b75e62d5056d5459d38bf1f516a
Author: YC27 <[email protected]>
AuthorDate: Fri Sep 13 10:12:20 2024 +0800

    Active Load: Check dir r/w permissions before loading from listening dirs 
(#13488) (#13500)
    
    Co-authored-by: Steve Yurong Su <[email protected]>
---
 .../load/active/ActiveLoadDirScanner.java          | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadDirScanner.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadDirScanner.java
index ca8760b3e3d..a9d30b8a7f7 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadDirScanner.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadDirScanner.java
@@ -51,6 +51,8 @@ public class ActiveLoadDirScanner extends 
ActiveLoadScheduledExecutorService {
   private final AtomicReference<String[]> listeningDirsConfig = new 
AtomicReference<>();
   private final Set<String> listeningDirs = new CopyOnWriteArraySet<>();
 
+  private final Set<String> noPermissionDirs = new CopyOnWriteArraySet<>();
+
   private final ActiveLoadTsFileLoader activeLoadTsFileLoader;
 
   public ActiveLoadDirScanner(final ActiveLoadTsFileLoader 
activeLoadTsFileLoader) {
@@ -73,6 +75,10 @@ public class ActiveLoadDirScanner extends 
ActiveLoadScheduledExecutorService {
     hotReloadActiveLoadDirs();
 
     for (final String listeningDir : listeningDirs) {
+      if (!checkPermission(listeningDir)) {
+        continue;
+      }
+
       final int currentAllowedPendingSize = 
activeLoadTsFileLoader.getCurrentAllowedPendingSize();
       if (currentAllowedPendingSize <= 0) {
         return;
@@ -93,6 +99,43 @@ public class ActiveLoadDirScanner extends 
ActiveLoadScheduledExecutorService {
     }
   }
 
+  private boolean checkPermission(final String listeningDir) {
+    try {
+      final Path listeningDirPath = new File(listeningDir).toPath();
+
+      if (!Files.isReadable(listeningDirPath)) {
+        if (!noPermissionDirs.contains(listeningDir)) {
+          LOGGER.error(
+              "Current dir path is not readable: {}."
+                  + "Skip scanning this dir. Please check the permission.",
+              listeningDirPath);
+          noPermissionDirs.add(listeningDir);
+        }
+        return false;
+      }
+
+      if (!Files.isWritable(listeningDirPath)) {
+        if (!noPermissionDirs.contains(listeningDir)) {
+          LOGGER.error(
+              "Current dir path is not writable: {}."
+                  + "Skip scanning this dir. Please check the permission.",
+              listeningDirPath);
+          noPermissionDirs.add(listeningDir);
+        }
+        return false;
+      }
+
+      noPermissionDirs.remove(listeningDir);
+      return true;
+    } catch (final Exception e) {
+      LOGGER.error(
+          "Error occurred during checking r/w permission of dir: {}. Skip 
scanning this dir.",
+          listeningDir,
+          e);
+      return false;
+    }
+  }
+
   private boolean isTsFileCompleted(final String file) {
     try (final TsFileSequenceReader reader = new TsFileSequenceReader(file, 
false)) {
       return TSFileConfig.MAGIC_STRING.equals(reader.readTailMagic());

Reply via email to