@SuppressWarnings("java:S112")
  private void updateLastCache(TsFileResource newTsFileResource, TsFileLastReader lastReader) {
    boolean isTableModel = isTableModelDatabase(databaseName);

    Map<IDeviceID, List<Pair<String, TimeValuePair>>> lastValues =
        newTsFileResource.getLastValues();
    if (lastValues != null) {
      for (Entry<IDeviceID, List<Pair<String, TimeValuePair>>> entry : lastValues.entrySet()) {
        IDeviceID deviceID = entry.getKey();
        String[] measurements = entry.getValue().stream().map(Pair::getLeft).toArray(String[]::new);
        TimeValuePair[] timeValuePairs =
            entry.getValue().stream().map(Pair::getRight).toArray(TimeValuePair[]::new);
        if (isTableModel) {
          TableDeviceSchemaCache.getInstance()
              .updateLastCacheIfExists(databaseName, deviceID, measurements, timeValuePairs);
        } else {
          // we do not update schema here, so aligned is not relevant
          TreeDeviceSchemaCacheManager.getInstance()
              .updateLastCacheIfExists(
                  databaseName, deviceID, measurements, timeValuePairs, false, null);
        }
      }
      newTsFileResource.setLastValues(null);
      return;
    }

    if (lastReader != null) {
      while (lastReader.hasNext()) {
        Pair<IDeviceID, List<Pair<String, TimeValuePair>>> nextDevice = lastReader.next();
        IDeviceID deviceID = nextDevice.left;
        String[] measurements = nextDevice.right.stream().map(Pair::getLeft).toArray(String[]::new);
        TimeValuePair[] timeValuePairs =
            nextDevice.right.stream().map(Pair::getRight).toArray(TimeValuePair[]::new);
        if (isTableModel) {
          TableDeviceSchemaCache.getInstance()
              .updateLastCacheIfExists(databaseName, deviceID, measurements, timeValuePairs);
        } else {
          // we do not update schema here, so aligned is not relevant
          TreeDeviceSchemaCacheManager.getInstance()
              .updateLastCacheIfExists(
                  databaseName, deviceID, measurements, timeValuePairs, false, null);
        }
      }
    } else {
      TreeDeviceSchemaCacheManager.getInstance().cleanUp();
    }
  }
Load a new tsfile to unsequence dir.

<p>Then, update the latestTimeForEachDevice and partitionLatestFlushedTimeForEachDevice.

@param newTsFileResource tsfile resource @UsedBy load external tsfile module
@param deleteOriginFile whether to delete origin tsfile
@param isGeneratedByPipe whether the load tsfile request is generated by pipe
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java