fanhualta commented on a change in pull request #2403:
URL: https://github.com/apache/iotdb/pull/2403#discussion_r552330418



##########
File path: 
server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
##########
@@ -1835,18 +1836,50 @@ public void loadNewTsFileForSync(TsFileResource 
newTsFileResource) throws LoadFi
           newFilePartitionId)) {
         updateLatestTimeMap(newTsFileResource);
       }
+      resetLastCacheWhenLoadingTsfile(newTsFileResource);
     } catch (DiskSpaceInsufficientException e) {
       logger.error(
           "Failed to append the tsfile {} to storage group processor {} 
because the disk space is insufficient.",
           tsfileToBeInserted.getAbsolutePath(), 
tsfileToBeInserted.getParentFile().getName());
       IoTDBDescriptor.getInstance().getConfig().setReadOnly(true);
       throw new LoadFileException(e);
+    } catch (IllegalPathException | WriteProcessException e) {
+      logger.error("Failed to reset last cache when loading file {}", 
newTsFileResource.getTsFilePath());
+      throw new LoadFileException(e);
     } finally {
       tsFileManagement.writeUnlock();
       writeUnlock();
     }
   }
 
+  private void resetLastCacheWhenLoadingTsfile(TsFileResource 
newTsFileResource)
+      throws IllegalPathException, WriteProcessException {
+    for (Entry<String, Integer> entry : 
newTsFileResource.getDeviceToIndexMap().entrySet()) {
+      PartialPath device = new PartialPath(entry.getKey());
+      tryToDeleteLastCacheByDevice(device);
+    }
+  }
+
+  private void tryToDeleteLastCacheByDevice(PartialPath deviceId) throws 
WriteProcessException {
+    if (!IoTDBDescriptor.getInstance().getConfig().isLastCacheEnabled()) {
+      return;
+    }
+    try {
+      MNode node = IoTDB.metaManager.getDeviceNode(deviceId);
+
+      for (MNode measurementNode : node.getChildren().values()) {
+        if (measurementNode != null) {
+          TimeValuePair lastPair = ((MeasurementMNode) 
measurementNode).getCachedLast();

Review comment:
       fixed




----------------------------------------------------------------
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:
[email protected]


Reply via email to