public static TimeseriesMetadata loadTimeSeriesMetadata(
      TsFileResource resource,
      NonAlignedFullPath seriesPath,
      FragmentInstanceContext context,
      Filter globalTimeFilter,
      Set<String> allSensors,
      boolean isSeq)
      throws IOException {
    long t1 = System.nanoTime();
    boolean loadFromMem = false;
    try {
      // common path
      TimeseriesMetadata timeSeriesMetadata;
      // If the tsfile is closed, we need to load from tsfile
      if (resource.isClosed()) {
        // when resource.getTimeIndexType() == 1, TsFileResource.timeIndexType is deviceTimeIndex
        // we should not ignore the non-exist of device in TsFileMetadata
        timeSeriesMetadata =
            TimeSeriesMetadataCache.getInstance()
                .get(
                    resource.getTsFilePath(),
                    new TimeSeriesMetadataCache.TimeSeriesMetadataCacheKey(
                        resource.getTsFileID(),
                        seriesPath.getDeviceId(),
                        seriesPath.getMeasurement()),
                    allSensors,
                    context.ignoreNotExistsDevice()
                        || resource.getTimeIndexType() == ITimeIndex.FILE_TIME_INDEX_TYPE,
                    context.isDebug(),
                    context);
        if (timeSeriesMetadata != null) {
          long t2 = System.nanoTime();
          List<ModEntry> pathModifications =
              context.getPathModifications(
                  resource, seriesPath.getDeviceId(), seriesPath.getMeasurement());
          timeSeriesMetadata.setModified(!pathModifications.isEmpty());
          timeSeriesMetadata.setChunkMetadataLoader(
              new DiskChunkMetadataLoader(resource, context, globalTimeFilter, pathModifications));
          int modificationCount = pathModifications.size();
          if (modificationCount != 0) {
            long costTime = System.nanoTime() - t2;
            context
                .getQueryStatistics()
                .getNonAlignedTimeSeriesMetadataModificationCount()
                .getAndAdd(modificationCount);
            context
                .getQueryStatistics()
                .getNonAlignedTimeSeriesMetadataModificationTime()
                .getAndAdd(costTime);
          }
        }
      } else { // if the tsfile is unclosed, we just get it directly from TsFileResource
        loadFromMem = true;

        timeSeriesMetadata = (TimeseriesMetadata) resource.getTimeSeriesMetadata(seriesPath);
        if (timeSeriesMetadata != null) {
          timeSeriesMetadata.setChunkMetadataLoader(
              new MemChunkMetadataLoader(resource, seriesPath, context, globalTimeFilter));
        }
      }

      if (timeSeriesMetadata != null) {
        if (timeSeriesMetadata.getStatistics().getStartTime()
            > timeSeriesMetadata.getStatistics().getEndTime()) {
          return null;
        }
        if (globalTimeFilter != null && globalTimeFilter.canSkip(timeSeriesMetadata)) {
          return null;
        }
      }
      return timeSeriesMetadata;
    } finally {
      long costTime = System.nanoTime() - t1;
      if (loadFromMem) {
        if (isSeq) {
          context.getQueryStatistics().getLoadTimeSeriesMetadataMemSeqCount().getAndAdd(1);
          context.getQueryStatistics().getLoadTimeSeriesMetadataMemSeqTime().getAndAdd(costTime);
        } else {
          context.getQueryStatistics().getLoadTimeSeriesMetadataMemUnSeqCount().getAndAdd(1);
          context.getQueryStatistics().getLoadTimeSeriesMetadataMemUnSeqTime().getAndAdd(costTime);
        }
      } else {
        if (isSeq) {
          context.getQueryStatistics().getLoadTimeSeriesMetadataDiskSeqCount().getAndAdd(1);
          context.getQueryStatistics().getLoadTimeSeriesMetadataDiskSeqTime().getAndAdd(costTime);
        } else {
          context.getQueryStatistics().getLoadTimeSeriesMetadataDiskUnSeqCount().getAndAdd(1);
          context.getQueryStatistics().getLoadTimeSeriesMetadataDiskUnSeqTime().getAndAdd(costTime);
        }
      }
    }
  }
Load TimeSeriesMetadata for non-aligned time series.

@param resource TsFile
@param seriesPath Timeseries path
@param allSensors measurements queried at the same time of this device
@param globalTimeFilter global time filter, only used to check time range
@throws IOException may be thrown while reading it from disk.
@param isSeq if it is a sequence file
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java