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/30 07:36:03 UTC

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

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