jt2594838 commented on code in PR #12687:
URL: https://github.com/apache/iotdb/pull/12687#discussion_r1630918138


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/MultiTsFileDeviceIterator.java:
##########
@@ -398,59 +404,43 @@ private void applyModificationForAlignedChunkMetadataList(
       // all the value chunks is empty chunk
       return;
     }
+    IDeviceID device = currentDevice.getLeft();
+    Deletion ttlDeletion = null;
+    if (tsFileResource.getStartTime(device) < timeLowerBoundForCurrentDevice) {
+      ttlDeletion =
+          new Deletion(
+              
CompactionPathUtils.getPath(device).concatNode(IoTDBConstant.ONE_LEVEL_PATH_WILDCARD),
+              Long.MAX_VALUE,
+              Long.MIN_VALUE,
+              timeLowerBoundForCurrentDevice);
+    }
 
     List<Modification> modifications =
         modificationCache.computeIfAbsent(
             tsFileResource,
-            r -> {
-              List<Modification> list =
-                  new 
LinkedList<>(ModificationFile.getNormalMods(r).getModifications());
-              // add outdated device mods by ttl
-              try {
-                for (IDeviceID device : r.getDevices()) {
-                  // TODO: remove deviceId conversion
-                  long timeLowerBound =
-                      CommonDateTimeUtils.currentTime()
-                          - DataNodeTTLCache.getInstance()
-                              .getTTL(((PlainDeviceID) device).toStringID());
-                  if (r.getStartTime(device) < timeLowerBound) {
-                    list.add(
-                        new Deletion(
-                            CompactionPathUtils.getPath(device)
-                                
.concatNode(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD),
-                            Long.MAX_VALUE,
-                            Long.MIN_VALUE,
-                            timeLowerBound));
-                  }
-                }
-              } catch (IllegalPathException e) {
-                throw new RuntimeException(e);
-              }
-              return list;
-            });
+            r -> new 
LinkedList<>(ModificationFile.getNormalMods(r).getModifications()));
 
     // construct the input params List<List<Modification>> for 
QueryUtils.modifyAlignedChunkMetaData
     AlignedChunkMetadata alignedChunkMetadata = 
alignedChunkMetadataList.get(0);
     List<IChunkMetadata> valueChunkMetadataList = 
alignedChunkMetadata.getValueChunkMetadataList();
     List<List<Modification>> modificationForCurDevice = new ArrayList<>();
-    List<PartialPath> valueSeriesPaths = new 
ArrayList<>(valueChunkMetadataList.size());
-    for (int i = 0; i < valueChunkMetadataList.size(); ++i) {
-      modificationForCurDevice.add(new ArrayList<>());
-      IChunkMetadata valueChunkMetadata = valueChunkMetadataList.get(i);
-      valueSeriesPaths.add(
-          valueChunkMetadata == null
-              ? null
-              : CompactionPathUtils.getPath(
-                  currentDevice.left, valueChunkMetadata.getMeasurementUid()));
-    }
-
-    for (Modification modification : modifications) {
-      for (int i = 0; i < valueChunkMetadataList.size(); ++i) {
-        PartialPath path = valueSeriesPaths.get(i);
-        if (path != null && modification.getPath().matchFullPath(path)) {
-          modificationForCurDevice.get(i).add(modification);
+    for (IChunkMetadata valueChunkMetadata : valueChunkMetadataList) {
+      List<Modification> modificationList = new ArrayList<>();
+      modificationForCurDevice.add(modificationList);
+      if (valueChunkMetadata == null) {
+        continue;
+      }
+      PartialPath path =
+          CompactionPathUtils.getPath(
+              currentDevice.getLeft(), valueChunkMetadata.getMeasurementUid());
+      for (Modification modification : modifications) {
+        if (modification.getPath().matchFullPath(path)) {
+          modificationList.add(modification);
         }
       }
+      if (ttlDeletion != null) {
+        modificationList.add(ttlDeletion);
+      }
     }

Review Comment:
   emptyList may occupy less memory than empty ArrayList if the list is 
unmodifiable.
   ```suggestion
       for (IChunkMetadata valueChunkMetadata : valueChunkMetadataList) {
         if (valueChunkMetadata == null) {
            modificationForCurDevice.add(Collections.emptyList());
           continue;
         }
         List<Modification> modificationList = new ArrayList<>();
         PartialPath path =
             CompactionPathUtils.getPath(
                 currentDevice.getLeft(), 
valueChunkMetadata.getMeasurementUid());
         for (Modification modification : modifications) {
           if (modification.getPath().matchFullPath(path)) {
             modificationList.add(modification);
           }
         }
         if (ttlDeletion != null) {
           modificationList.add(ttlDeletion);
         }
         modificationForCurDevice.add(modificationList.isEmpty() ? 
Collections.emptyList() : modificationList);
       }
   ```



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to