You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/03/26 09:12:14 UTC

[GitHub] [iotdb] zhanglingzhe0820 opened a new pull request #2920: Fix unseq compaction file selector conflicts with time partition bug

zhanglingzhe0820 opened a new pull request #2920:
URL: https://github.com/apache/iotdb/pull/2920


   ## Behavior
   A ci bug behave like below:
   ![image](https://user-images.githubusercontent.com/24886743/112608587-761e6580-8e55-11eb-8860-e1ebd2d9dc3f.png)
   
   ## Reason
   
   The compaction process get all seq files to merge with unseq files in one time partition t1. And the unseq compaction may select seq files which is not in time partition t1. This operation may destroy the time partition structure.
   
   ## Solution
   1. Just submit seq files in time partition t1 for unseq compaction.
   2. Make unseq compaction not select file across time partition.


-- 
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.

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



[GitHub] [iotdb] SilverNarcissus commented on a change in pull request #2920: Fix unseq compaction file selector conflicts with time partition bug

Posted by GitBox <gi...@apache.org>.
SilverNarcissus commented on a change in pull request #2920:
URL: https://github.com/apache/iotdb/pull/2920#discussion_r603851927



##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -28,41 +28,53 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 public class NoCompactionTsFileManagement extends TsFileManagement {
 
   private static final Logger logger = LoggerFactory.getLogger(NoCompactionTsFileManagement.class);
   // includes sealed and unsealed sequence TsFiles
-  private TreeSet<TsFileResource> sequenceFileTreeSet =
-      new TreeSet<>(
-          (o1, o2) -> {
-            try {
-              int rangeCompare =
-                  Long.compare(
-                      Long.parseLong(o1.getTsFile().getParentFile().getName()),
-                      Long.parseLong(o2.getTsFile().getParentFile().getName()));
-              return rangeCompare == 0
-                  ? compareFileName(o1.getTsFile(), o2.getTsFile())
-                  : rangeCompare;
-            } catch (NumberFormatException e) {
-              return compareFileName(o1.getTsFile(), o2.getTsFile());
-            }
-          });
+  private final Map<Long, TreeSet<TsFileResource>> sequenceFileTreeSetMap =

Review comment:
       You use ConcurrentSkipListMap to improve the concurrency. But the value of this map is treeset, which is not thread safe. In your later code, you use synchronize in "add" method but never use synchronize in "contains method". That will cause a concurrency problem. As far as I'm concerned, I recommend to use synchronize on this complex structure. Use TreeMap and tree set and use synchronize at every read and write.




-- 
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.

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



[GitHub] [iotdb] zhanglingzhe0820 closed pull request #2920: Fix unseq compaction file selector conflicts with time partition bug

Posted by GitBox <gi...@apache.org>.
zhanglingzhe0820 closed pull request #2920:
URL: https://github.com/apache/iotdb/pull/2920


   


-- 
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.

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



[GitHub] [iotdb] jixuan1989 commented on a change in pull request #2920: Fix unseq compaction file selector conflicts with time partition bug

Posted by GitBox <gi...@apache.org>.
jixuan1989 commented on a change in pull request #2920:
URL: https://github.com/apache/iotdb/pull/2920#discussion_r602959610



##########
File path: server/src/main/java/org/apache/iotdb/db/engine/merge/selector/MaxFileMergeFileSelector.java
##########
@@ -229,10 +229,13 @@ private void selectOverlappedSeqFiles(TsFileResource unseqFile) {
         }
         // the open file's endTime is Long.MIN_VALUE, this will make the file be filtered below
         long seqEndTime = seqFile.isClosed() ? seqFile.getEndTime(deviceId) : Long.MAX_VALUE;
+        long seqStartTime = seqFile.getStartTime(deviceId);
         if (unseqEndTime <= seqEndTime) {
           // the unseqFile overlaps current seqFile
-          tmpSelectedSeqFiles.add(i);
-          tmpSelectedNum++;
+          if (seqStartTime <= seqEndTime) {

Review comment:
       seqStartTime<= seqEndTime?




-- 
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.

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



[GitHub] [iotdb] jt2594838 commented on a change in pull request #2920: Fix unseq compaction file selector conflicts with time partition bug

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on a change in pull request #2920:
URL: https://github.com/apache/iotdb/pull/2920#discussion_r603896633



##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -72,9 +69,14 @@ public NoCompactionTsFileManagement(String storageGroupName, String storageGroup
   @Override
   public List<TsFileResource> getTsFileListByTimePartition(boolean sequence, long timePartition) {
     if (sequence) {
-      return new ArrayList<>(sequenceFileTreeSetMap.get(timePartition));
+      synchronized (sequenceFileTreeSetMap) {
+        return new ArrayList<>(sequenceFileTreeSetMap.getOrDefault(timePartition, new TreeSet<>()));
+      }
     } else {
-      return new ArrayList<>(unSequenceFileListMap.get(timePartition));
+      synchronized (unSequenceFileListMap) {
+        return new ArrayList<>(
+            unSequenceFileListMap.getOrDefault(timePartition, new ArrayList<>()));
+      }

Review comment:
       Use `Collections.emptySet` and `Collection.emptyList` instead.




-- 
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.

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



[GitHub] [iotdb] jt2594838 commented on a change in pull request #2920: Fix unseq compaction file selector conflicts with time partition bug

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on a change in pull request #2920:
URL: https://github.com/apache/iotdb/pull/2920#discussion_r603852385



##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -28,41 +28,53 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 public class NoCompactionTsFileManagement extends TsFileManagement {
 
   private static final Logger logger = LoggerFactory.getLogger(NoCompactionTsFileManagement.class);
   // includes sealed and unsealed sequence TsFiles
-  private TreeSet<TsFileResource> sequenceFileTreeSet =
-      new TreeSet<>(
-          (o1, o2) -> {
-            try {
-              int rangeCompare =
-                  Long.compare(
-                      Long.parseLong(o1.getTsFile().getParentFile().getName()),
-                      Long.parseLong(o2.getTsFile().getParentFile().getName()));
-              return rangeCompare == 0
-                  ? compareFileName(o1.getTsFile(), o2.getTsFile())
-                  : rangeCompare;
-            } catch (NumberFormatException e) {
-              return compareFileName(o1.getTsFile(), o2.getTsFile());
-            }
-          });
+  private final Map<Long, TreeSet<TsFileResource>> sequenceFileTreeSetMap =
+      new ConcurrentSkipListMap<>();
 
   // includes sealed and unsealed unSequence TsFiles
-  private List<TsFileResource> unSequenceFileList = new ArrayList<>();
+  private final Map<Long, List<TsFileResource>> unSequenceFileListMap =
+      new ConcurrentSkipListMap<>();
 
   public NoCompactionTsFileManagement(String storageGroupName, String storageGroupDir) {
     super(storageGroupName, storageGroupDir);
   }
 
+  @Deprecated
   @Override
   public List<TsFileResource> getTsFileList(boolean sequence) {
+    List<TsFileResource> result = new ArrayList<>();
     if (sequence) {
-      return new ArrayList<>(sequenceFileTreeSet);
+      synchronized (sequenceFileTreeSetMap) {
+        for (long timePartition : sequenceFileTreeSetMap.keySet()) {
+          result.addAll(getTsFileListByTimePartition(true, timePartition));
+        }

Review comment:
       How about just iterating the `valueSet`?

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -74,27 +86,48 @@ public NoCompactionTsFileManagement(String storageGroupName, String storageGroup
   @Override
   public void remove(TsFileResource tsFileResource, boolean sequence) {
     if (sequence) {
-      sequenceFileTreeSet.remove(tsFileResource);
+      synchronized (sequenceFileTreeSetMap) {
+        TreeSet<TsFileResource> sequenceFileTreeSet =
+            sequenceFileTreeSetMap.get(tsFileResource.getTimePartition());
+        sequenceFileTreeSet.remove(tsFileResource);
+      }
     } else {
-      unSequenceFileList.remove(tsFileResource);
+      synchronized (unSequenceFileListMap) {
+        List<TsFileResource> unSequenceFileList =
+            unSequenceFileListMap.get(tsFileResource.getTimePartition());
+        unSequenceFileList.remove(tsFileResource);
+      }
     }
   }
 
   @Override
   public void removeAll(List<TsFileResource> tsFileResourceList, boolean sequence) {
     if (sequence) {
-      sequenceFileTreeSet.removeAll(tsFileResourceList);
+      for (Set<TsFileResource> sequenceFileTreeSet : sequenceFileTreeSetMap.values()) {
+        sequenceFileTreeSet.removeAll(tsFileResourceList);
+      }
     } else {
-      unSequenceFileList.removeAll(tsFileResourceList);
+      for (List<TsFileResource> unSequenceFileList : unSequenceFileListMap.values()) {
+        unSequenceFileList.removeAll(tsFileResourceList);
+      }

Review comment:
       This contains potentially redundant operations, here is my advice:
   1. sort `tsFileResourceList` according to their partitions
   2. for each partition `p` existing in `tsFileResourceList`, find its first position `min` and last position `max` in `tsFileResourceList`
   3. call `sequenceFileTreeSetMap.get(p).removeAll(tsFileResourceList.subList(min, max + 1))`

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -105,44 +138,61 @@ public void addRecover(TsFileResource tsFileResource, boolean sequence) {
 
   @Override
   public void addAll(List<TsFileResource> tsFileResourceList, boolean sequence) {
-    if (sequence) {
-      sequenceFileTreeSet.addAll(tsFileResourceList);
-    } else {
-      unSequenceFileList.addAll(tsFileResourceList);
+    for (TsFileResource tsFileResource : tsFileResourceList) {
+      add(tsFileResource, sequence);
     }
   }
 
   @Override
   public boolean contains(TsFileResource tsFileResource, boolean sequence) {
     if (sequence) {
-      return sequenceFileTreeSet.contains(tsFileResource);
+      return sequenceFileTreeSetMap
+          .computeIfAbsent(tsFileResource.getTimePartition(), this::newSequenceTsFileResources)
+          .contains(tsFileResource);

Review comment:
       It may be better to use `getOrDefault(partition, Collections.emptyList())` here since it is not necessary to create entries for reads.

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -159,4 +209,25 @@ public void forkCurrentFileList(long timePartition) {
   protected void merge(long timePartition) {
     logger.info("{} no merge logic", storageGroupName);
   }
+
+  private TreeSet<TsFileResource> newSequenceTsFileResources(Long k) {
+    return new TreeSet<>(
+        (o1, o2) -> {
+          try {
+            int rangeCompare =
+                Long.compare(
+                    Long.parseLong(o1.getTsFile().getParentFile().getName()),
+                    Long.parseLong(o2.getTsFile().getParentFile().getName()));
+            return rangeCompare == 0
+                ? compareFileName(o1.getTsFile(), o2.getTsFile())
+                : rangeCompare;
+          } catch (NumberFormatException e) {
+            return compareFileName(o1.getTsFile(), o2.getTsFile());
+          }
+        });
+  }
+
+  private List<TsFileResource> newUnSequenceTsFileResources(Long k) {
+    return new CopyOnWriteArrayList<>();

Review comment:
       Now that you have used `synchronized`, is it necessary to use `CopyOnWriteArrayList` too?

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -74,27 +86,48 @@ public NoCompactionTsFileManagement(String storageGroupName, String storageGroup
   @Override
   public void remove(TsFileResource tsFileResource, boolean sequence) {
     if (sequence) {
-      sequenceFileTreeSet.remove(tsFileResource);
+      synchronized (sequenceFileTreeSetMap) {
+        TreeSet<TsFileResource> sequenceFileTreeSet =
+            sequenceFileTreeSetMap.get(tsFileResource.getTimePartition());
+        sequenceFileTreeSet.remove(tsFileResource);
+      }
     } else {
-      unSequenceFileList.remove(tsFileResource);
+      synchronized (unSequenceFileListMap) {
+        List<TsFileResource> unSequenceFileList =
+            unSequenceFileListMap.get(tsFileResource.getTimePartition());
+        unSequenceFileList.remove(tsFileResource);
+      }
     }
   }
 
   @Override
   public void removeAll(List<TsFileResource> tsFileResourceList, boolean sequence) {
     if (sequence) {
-      sequenceFileTreeSet.removeAll(tsFileResourceList);
+      for (Set<TsFileResource> sequenceFileTreeSet : sequenceFileTreeSetMap.values()) {
+        sequenceFileTreeSet.removeAll(tsFileResourceList);
+      }
     } else {
-      unSequenceFileList.removeAll(tsFileResourceList);
+      for (List<TsFileResource> unSequenceFileList : unSequenceFileListMap.values()) {
+        unSequenceFileList.removeAll(tsFileResourceList);
+      }

Review comment:
       By the way, is not concurrent safety a concern?

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/no/NoCompactionTsFileManagement.java
##########
@@ -28,41 +28,53 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 public class NoCompactionTsFileManagement extends TsFileManagement {
 
   private static final Logger logger = LoggerFactory.getLogger(NoCompactionTsFileManagement.class);
   // includes sealed and unsealed sequence TsFiles
-  private TreeSet<TsFileResource> sequenceFileTreeSet =
-      new TreeSet<>(
-          (o1, o2) -> {
-            try {
-              int rangeCompare =
-                  Long.compare(
-                      Long.parseLong(o1.getTsFile().getParentFile().getName()),
-                      Long.parseLong(o2.getTsFile().getParentFile().getName()));
-              return rangeCompare == 0
-                  ? compareFileName(o1.getTsFile(), o2.getTsFile())
-                  : rangeCompare;
-            } catch (NumberFormatException e) {
-              return compareFileName(o1.getTsFile(), o2.getTsFile());
-            }
-          });
+  private final Map<Long, TreeSet<TsFileResource>> sequenceFileTreeSetMap =
+      new ConcurrentSkipListMap<>();
 
   // includes sealed and unsealed unSequence TsFiles
-  private List<TsFileResource> unSequenceFileList = new ArrayList<>();
+  private final Map<Long, List<TsFileResource>> unSequenceFileListMap =
+      new ConcurrentSkipListMap<>();
 
   public NoCompactionTsFileManagement(String storageGroupName, String storageGroupDir) {
     super(storageGroupName, storageGroupDir);
   }
 
+  @Deprecated
   @Override
   public List<TsFileResource> getTsFileList(boolean sequence) {
+    List<TsFileResource> result = new ArrayList<>();
     if (sequence) {
-      return new ArrayList<>(sequenceFileTreeSet);
+      synchronized (sequenceFileTreeSetMap) {
+        for (long timePartition : sequenceFileTreeSetMap.keySet()) {
+          result.addAll(getTsFileListByTimePartition(true, timePartition));
+        }
+      }
     } else {
-      return new ArrayList<>(unSequenceFileList);
+      synchronized (unSequenceFileListMap) {
+        for (long timePartition : unSequenceFileListMap.keySet()) {
+          result.addAll(getTsFileListByTimePartition(false, timePartition));
+        }
+      }
+    }
+    return result;
+  }
+
+  @Override
+  public List<TsFileResource> getTsFileListByTimePartition(boolean sequence, long timePartition) {
+    if (sequence) {
+      return new ArrayList<>(sequenceFileTreeSetMap.get(timePartition));
+    } else {
+      return new ArrayList<>(unSequenceFileListMap.get(timePartition));

Review comment:
       Is it possible that this `get` returns a null? If so, better to use `getOrDefault`.




-- 
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.

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



[GitHub] [iotdb] jixuan1989 merged pull request #2920: Fix unseq compaction file selector conflicts with time partition bug

Posted by GitBox <gi...@apache.org>.
jixuan1989 merged pull request #2920:
URL: https://github.com/apache/iotdb/pull/2920


   


-- 
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.

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