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

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 5354dee8f8e Fixed the concurrent modification bug of pathPatternTree
5354dee8f8e is described below

commit 5354dee8f8ef37451f92d95c973a9d1cb31313f1
Author: Caideyipi <[email protected]>
AuthorDate: Mon Apr 14 14:42:14 2025 +0800

    Fixed the concurrent modification bug of pathPatternTree
---
 .../apache/iotdb/commons/path/PathPatternTree.java   | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PathPatternTree.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PathPatternTree.java
index ffe744e71e0..569112dbf9f 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PathPatternTree.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PathPatternTree.java
@@ -39,6 +39,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 public class PathPatternTree {
 
@@ -122,7 +123,8 @@ public class PathPatternTree {
     for (PartialPath path : pathPatternList) {
       appendBranchWithoutPrune(root, path.getNodes(), 0);
     }
-    pathPatternList.clear();
+    // Do not clear to avoid concurrent modification
+    pathPatternList = new LinkedList<>();
   }
 
   private void appendBranchWithoutPrune(
@@ -285,18 +287,14 @@ public class PathPatternTree {
     ancestors.pop();
   }
 
-  public List<PartialPath> getOverlappedPathPatterns(PartialPath pattern) {
-    if (pathPatternList.isEmpty()) {
-      pathPatternList = getAllPathPatterns();
+  public List<PartialPath> getOverlappedPathPatterns(final PartialPath 
pattern) {
+    List<PartialPath> patternList = pathPatternList;
+    if (Objects.isNull(patternList) || patternList.isEmpty()) {
+      patternList = getAllPathPatterns();
+      pathPatternList = patternList;
     }
 
-    List<PartialPath> results = new ArrayList<>();
-    for (PartialPath path : pathPatternList) {
-      if (pattern.overlapWith(path)) {
-        results.add(path);
-      }
-    }
-    return results;
+    return 
patternList.stream().filter(pattern::overlapWith).collect(Collectors.toList());
   }
 
   private String convertNodesToString(List<String> nodes) {

Reply via email to