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/01/04 07:12:27 UTC

[GitHub] [iotdb] wshao08 commented on a change in pull request #2403: Fix a bug of sync last query not right

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



##########
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:
       Hi, calling resetCache() will set cachedLastValuePair to null. So here you can get rid of lastPair and just call resetCache().




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